-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
executable file
·41 lines (34 loc) · 1.1 KB
/
app.py
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
#!/usr/bin/python -u
import os
import redis
import traceback
import validators
from instapaperlib import Instapaper
config = {
'CHANNEL': 'instapaper',
'USERNAME': '',
'PASSWORD': '',
}
print "Launching redis to instapaper component"
# take config items from environment where present
for configitem in config:
if configitem in os.environ:
config[configitem] = os.environ[configitem]
i = Instapaper(config['USERNAME'], config['PASSWORD'])
try:
red = redis.StrictRedis("redis")
red_pubsub = red.pubsub()
red_pubsub.subscribe(config['CHANNEL'])
except:
print "Failed to subscribe to channel"
try:
while True:
for item in red_pubsub.listen():
if (str(item['data']).lower().split(":")[0] in ['http', 'https']) and validators.url(item['data']):
print "Adding item: " , item['data']
(statuscode, statusmessage) = i.add_item(item['data'])
print "Instapaper response: ", statuscode, statusmessage
else:
print "Bad data: ", item['data']
except Exception as e:
print traceback.format_exc()