Commit c71d3339 authored by birk's avatar birk
Browse files

added Twitter support

parent c5b4e13e
......@@ -452,6 +452,18 @@ class MediaEntryParams():
return ''
return '/api/media-entries/?{}'.format(urllib.parse.urlencode(self.data).replace('%27','%22').replace('True','true').replace('False','false'))
@property
def web_url(self):
f = {
'list[filter]': self.filter_by,
'list[show_filter]': 'true',
'list[page]': 1,
'list[per_page]': 12,
'list[order]': 'created_at DESC',
'list[layout]': 'grid'
}
return '/entries?{}'.format(urllib.parse.urlencode(f).replace('%27','%22').replace('True','true').replace('False','false'))
def __str__(self):
return self.url
......
......@@ -98,6 +98,16 @@ class Program(EventDispatcher):
return self._params.url
return None
@property
def web_url(self):
"""
Returns a url for the Madek web app and not the API.
:return: String
"""
if self._params:
return self._params.web_url
return None
class FollowupProgram(Program):
......
......@@ -7,6 +7,7 @@ import simplejson as json
import click
import pyglet
from random import shuffle
import twitter
from api_access import api_user, api_pass, api_server
from content.api import ApiClient
......@@ -14,6 +15,7 @@ from content.dispatcher import Dispatcher
from content.program import Program, FollowupProgram
from system.config import Config
from system.machine import Machine
from twitter_access import twitter_consumer_key, twitter_consumer_secret, twitter_access_token, twitter_access_token_secret
@click.command()
......@@ -35,6 +37,10 @@ class Main(object):
font_directory = os.path.join(os.path.dirname(__file__), 'fonts')
self._machine = Machine(font_directory)
self._api = ApiClient(api_server, api_user, api_pass)
self._twitter_api = twitter.Api(consumer_key=twitter_consumer_key,
consumer_secret=twitter_consumer_secret,
access_token_key=twitter_access_token,
access_token_secret=twitter_access_token_secret)
# defining the screens
screen1 = self._machine.create_screen()
......@@ -107,6 +113,7 @@ class Main(object):
self.log_program(program.name)
self._dispatcher.set_program(program)
self._dispatcher.start()
self.tweet_program(program)
except AssertionError:
print('Error loading program.')
else:
......@@ -116,5 +123,14 @@ class Main(object):
with open(str(Path(self._config.log_dir,'programs_{}.txt'.format(datetime.now().strftime('%Y-%m-%d')))), 'a') as f:
f.write('{} {}\n'.format(datetime.now().strftime('%H:%M:%S'),name_))
def tweet_program(self, program_):
try:
if not self._config.dev_mode:
self._twitter_api.PostUpdate('{} {}{}'.format(program_.name, api_server, program_.web_url))
except:
print('Twitter error ...')
if __name__ == '__main__':
m = Main()
twitter_consumer_key = 'consumer_key'
twitter_consumer_secret = 'consumer_secret'
twitter_access_token = 'access_token'
twitter_access_token_secret = 'access_token_secret '
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment