-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlogo.py
More file actions
82 lines (76 loc) · 2.65 KB
/
logo.py
File metadata and controls
82 lines (76 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import threading
import time
import urllib
import json
import urllib2
import Image
import ImageDraw
import constants
import logs
import requests
class logo:
def __init__(self, base):
self.base = base
self.config = base.config
self.pic = None
self.loadImageFromFile()
def loadImageFromFile(self):
try:
self.pic = Image.open("./api/uploads/0")
self.pic.thumbnail((128,32), Image.ANTIALIAS)
except Exception, e:
logs.logger.info(
'Logo module', extra={
'status': 0,
'job': 'logo_module',
'error': str(e)
})
self.getImageURL()
def fetchImage(self, link):
image = urllib.URLopener()
try:
image.retrieve(link, "./api/uploads/0")
self.pic = Image.open("./api/uploads/0")
self.pic.thumbnail((128,32), Image.ANTIALIAS)
except Exception, e:
logs.logger.info(
'Logo module', extra={
'status': 0,
'job': 'logo_module',
'error': str(e)
})
def getImageURL(self):
try:
url = 'https://api.trainsignapi.com/prod-get-image/get'
payload = {
'clientId': self.config['settings']['client_id'],
'signId': self.config['settings']['sign_id'],
'logoKey': '0'
}
headers = {
'Content-Type': 'application/json',
'x-api-key': self.config['settings']['dev_api_key']
}
response = requests.request(
'POST', url, headers=headers, json=payload)
self.fetchImage(json.loads(response.text)['link'])
except Exception, e:
logs.logger.info(
'Logo module', extra={
'status': 0,
'job': 'logo_module',
'error': str(e)
})
def draw(self):
self.config = self.base.config
if self.config["logo"]["updated"] == True:
baseurl = "http://127.0.0.1:3000/setConfig/logo/updated/false"
try:
result = urllib2.urlopen(baseurl, timeout = 5)
except urllib2.URLError as e:
error_message = e.reason
logs.logger.info('API logo module', extra={'status': 0, 'job': 'api_logo_update', 'error': str(e)})
else:
self.getImageURL()
self.base.matrix.SetImage(self.pic.convert('RGB'), 0, 0)
time.sleep(self.base.getTransitionTime())