Skip to content

Commit

Permalink
[NEW] hw_twitter_printing - prints tweets with specific hashtags (#415)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinar authored and Ivan Yelizariev committed Sep 29, 2017
1 parent 338804a commit 34f9518
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ addons:
env:
global:
- VERSION="10.0" TESTS="0" LINT_CHECK="0" TRANSIFEX="0" UNIT_TEST="0"
- EXCLUDE="hw_printer_network"
- EXCLUDE="hw_printer_network,hw_twitter_printing"
- PYLINT_ODOO_JSLINTRC="/home/travis/maintainer-quality-tools/travis/cfg/.jslintrc"
- TRANSIFEX_USER='i18n-bot@it-projects.info'
- secure: "LALUDmASaCYKLpDE97zycd1tnui7ozddyjrfCLAowKUyMxx5xjrCSeFzebZfYVpf+PeBunYOrRpspgRi81NpWeFUjb92TrGSdFmkcPQKQJa1zFRhblRexR48dxv1+/Ubi/ZNIvt6uxztPvynCDk78j7jwiSj3bKD6t5P7oI22jwo4DkhlY9gmb9Ook3pxKm1enohyUpSgfAUyoINvOdaLXMmCg0lxwVmzNw4jgWWIQDgmycrCjQioRFeiPOsvvNC0RklVaKbtnzsA9PmfMUL40F2Lu67EnBXk3IVfqnQJQjVYVO5IUbAtpw76+CTheFXBrDIJ2gk5y/tpOk215N8DekFaX0BRLOlTkF+PLUO9RHLWHfrVTwYqBggKcTj2Oz+nsGuj5sTRSTVLU03vKGMb2KKmH4QldgLgcRG26qTKVhRw6LCaCsLgdZptF93c8QoyI7bgQspOBVb9asQIJ/wbS+SluPBLAw4WTWrqI0BY+y4YjaSSZO9QNLUgthhg1AuSJw2Kb5265AI1ha7HQUEsYYDP4l8K68RK22TnuPvgBcbCpiEmU28D1o08Va2Q6W2BFu+zhbNF1CP6endtbk2kjdLtyu06XaJkY8Ac8TexaYb9wvvfDNfdpQGhIMRpdQDhjLMdLT3VfkNBmOU1w2214zl6YzqxTh0OXrsZC64IPM="
Expand Down
35 changes: 35 additions & 0 deletions hw_twitter_printing/README.rst
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
96 changes: 96 additions & 0 deletions hw_twitter_printing/__init__.py
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()
34 changes: 34 additions & 0 deletions hw_twitter_printing/__manifest__.py
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,
}
4 changes: 4 additions & 0 deletions hw_twitter_printing/doc/changelog.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
`1.0.0`
-------

- Init version
24 changes: 24 additions & 0 deletions hw_twitter_printing/doc/index.rst
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
Binary file added hw_twitter_printing/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 34f9518

Please sign in to comment.