forked from natronics/EOL-Photos
/
update.py
46 lines (36 loc) · 1.06 KB
/
update.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
41
42
43
44
45
46
import feedparser
import redis
import os
import sys
import json
import eol
REDIS_URL = os.getenv('REDISTOGO_URL', 'redis://localhost:6379')
r = redis.StrictRedis.from_url(REDIS_URL)
def update_guid(guid):
# check to see if set is new
if not r.sismember('eol-image-sets', guid):
print "Found new photos"
# get photo ids
link = eol.SETURL_BASE.format(guid=guid)
photos = eol.scrape_photos(link)
# push into redis
for photo in photos:
r.lpush('eol-'+str(guid), json.dumps(photo))
r.lpush('eol-image-set-list', guid)
r.sadd('eol-image-sets', guid)
def check_rss():
print "Checking EOL for updates"
url = "http://eol.jsc.nasa.gov/sseop/NewPhotos.xml"
d = feedparser.parse(url)
# Find the new image RSS entry in the list
for entry in d.entries:
if '-Images' in entry.guid:
guid = int(entry.guid[-15:-7])
update_guid(guid)
if len(sys.argv) == 2:
url = sys.argv[1]
guid = url[-15:-7]
update_guid(guid)
else:
check_rss()
print "Finished"