-
-
Notifications
You must be signed in to change notification settings - Fork 583
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NEW] hw_twitter_printing - prints tweets with specific hashtags (#415)
- Loading branch information
Dinar
authored and
Ivan Yelizariev
committed
Sep 29, 2017
1 parent
338804a
commit 34f9518
Showing
7 changed files
with
194 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
========================== | ||
Print tweets with PosBox | ||
========================== | ||
|
||
The module allows to print tweets with specific hashtags by using PosBox. | ||
|
||
TODO: Works with Network Printer only | ||
|
||
Credits | ||
======= | ||
|
||
Contributors | ||
------------ | ||
* `Dinar Gabbasov <https://it-projects.info/team/GabbasovDinar>`__ | ||
|
||
Sponsors | ||
-------- | ||
* `IT-Projects LLC <https://it-projects.info>`__ | ||
|
||
Maintainers | ||
----------- | ||
* `IT-Projects LLC <https://it-projects.info>`__ | ||
|
||
Further information | ||
=================== | ||
|
||
Demo: http://runbot.it-projects.info/demo/pos-addons/10 | ||
|
||
HTML Description: https://apps.odoo.com/apps/modules/10/printings_twitter_tweets/ | ||
|
||
Usage instructions: `<doc/index.rst>`_ | ||
|
||
Changelog: `<doc/changelog.rst>`_ | ||
|
||
Tested on Odoo 10.0 3550a68d968aeacf1b6efd1c96f5c57e5de60bbe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# -*- coding: utf-8 -*- | ||
import logging | ||
import threading | ||
from odoo.tools import config | ||
|
||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
try: | ||
from twython import TwythonStreamer | ||
from escpos.printer import Network | ||
except ImportError as err: | ||
_logger.debug(err) | ||
|
||
|
||
class MyStreamerThread(threading.Thread): | ||
|
||
def __init__(self): | ||
threading.Thread.__init__(self, name='MyStreamerThread') | ||
self.daemon = True | ||
|
||
def run(self): | ||
_logger.info("MyStreamerThread started.") | ||
|
||
app_key = config['app_key'] | ||
app_secret = config['app_secret'] | ||
oauth_token = config['oauth_token'] | ||
oauth_token_secret = config['oauth_token_secret'] | ||
|
||
stream = MyStreamer(app_key, app_secret, oauth_token, oauth_token_secret) | ||
stream.printer = False | ||
stream.statuses.filter(track='#OdooExperience,#OdooExperience2017') | ||
|
||
|
||
class MyStreamer(TwythonStreamer): | ||
def on_success(self, data): | ||
if 'text' in data and 'retweeted_status' not in data: | ||
try: | ||
self.connect_to_printer() | ||
self.print_tweet(data) | ||
except: | ||
pass | ||
# TODO: Print logs | ||
|
||
def print_tweet(self, data): | ||
name = data['user']['name'] + '\n' | ||
self.printer.set() | ||
self.printer.text(name) | ||
|
||
login = '@' + data['user']['screen_name'] + '\n' | ||
self.printer.set() | ||
self.printer.text(login) | ||
|
||
self.printer.set() | ||
self.printer.text('\n') | ||
text = data['text'].encode('utf-8') + '\n' | ||
self.printer.text(text) | ||
self.printer.text('\n') | ||
if 'quoted_status' in data: | ||
self.printer.text("_______________________________________________\n\n") | ||
self.printer.set(font='b') | ||
quoted_name = data['quoted_status']['user']['name'] + ' ' | ||
|
||
self.printer.text(quoted_name) | ||
quoted_login = '@' + data['quoted_status']['user']['screen_name'] + '\n' | ||
self.printer.text(quoted_login) | ||
self.printer.text('\n') | ||
quoted_text = data['quoted_status']['text'] + '\n' | ||
self.printer.set(align='right', font='b') | ||
self.printer.text(quoted_text) | ||
self.printer.text('\n') | ||
self.printer.set() | ||
self.printer.text("_______________________________________________\n\n") | ||
|
||
date = data['created_at'] + '\n' | ||
self.printer.set(font='b') | ||
self.printer.text(date) | ||
self.printer.cut() | ||
|
||
def connect_to_printer(self): | ||
NETWORK_PRINTER_IP = config['printer_ip'] | ||
if self.printer: | ||
self.printer.close() | ||
try: | ||
self.printer = Network(NETWORK_PRINTER_IP) | ||
except: | ||
_logger.error("Can not get printer with IP: %s" % NETWORK_PRINTER_IP) | ||
self.printer = False | ||
|
||
def on_error(self, status_code, data): | ||
_logger.error("Can not printing tweets: %s" % status_code) | ||
|
||
|
||
my_streamer = MyStreamerThread() | ||
my_streamer.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# -*- coding: utf-8 -*- | ||
{ | ||
"name": """Print tweets with PosBox""", | ||
"summary": """Print tweets with specific hashtags""", | ||
"category": "Point of Sale", | ||
# "live_test_URL": "", | ||
"images": [], | ||
"version": "1.0.0", | ||
"application": False, | ||
|
||
"author": "IT-Projects LLC, Dinar Gabbasov", | ||
"support": "apps@it-projects.info", | ||
"website": "https://it-projects.info/team/GabbasovDinar", | ||
"license": "LGPL-3", | ||
# "price": 0.00, | ||
# "currency": "EUR", | ||
|
||
"depends": [ | ||
], | ||
"external_dependencies": {"python": ["twython", "escpos"], "bin": []}, | ||
"data": [ | ||
], | ||
"qweb": [ | ||
], | ||
"demo": [ | ||
], | ||
|
||
"post_load": None, | ||
"pre_init_hook": None, | ||
"post_init_hook": None, | ||
|
||
"auto_install": False, | ||
"installable": True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
`1.0.0` | ||
------- | ||
|
||
- Init version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
========================== | ||
Print tweets with PosBox | ||
========================== | ||
|
||
Installation | ||
============ | ||
|
||
* Go to Twitter apps: https://apps.twitter.com/ | ||
* Click ``[Create New App]`` | ||
* Specify the Application Details | ||
* Click ``[Create your Twitter application]`` | ||
* Go to ``Keys and Access Tokens`` tab | ||
* Click ``modify app permissions`` and specify ``Read only`` | ||
* Click ``[Update Settings]`` | ||
* Go to ``Keys and Access Tokens`` tab | ||
* Save ``Consumer Key (API Key)`` and ``Consumer Secret (API Secret)`` in the PosBox config using the parameters app_key, app_secret | ||
* Click ``[Create my access token]`` | ||
* Save ``Access Token`` and ``Access Token Secret`` in the PosBox config using the parameters oauth_token, oauth_token_secret | ||
* Specify a ``Printer IP`` in the PosBox config using the parameter printer_ip | ||
|
||
In PosBox | ||
--------- | ||
|
||
* add ``hw_twitter_printing`` module to *server wide modules*. Detailed instruction is here: https://odoo-development.readthedocs.io/en/latest/admin/posbox/administrate-posbox.html#how-to-update-odoo-command-line-options |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.