-
Notifications
You must be signed in to change notification settings - Fork 1
/
genrss.py
42 lines (33 loc) · 1.21 KB
/
genrss.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
import json,datetime,urllib2,random
from PyRSS2Gen import RSS2, RSSItem
timezones = json.load(file('tz.json'))
def getUTC():
return int((datetime.datetime.utcnow()-datetime.datetime(1970, 1, 1)).total_seconds())%(24*3600)
def get420offset():
offset = 16*3600+20*60-getUTC()
if offset<0:
offset += 24*3600
return offset
def next420():
offs = get420offset()
for tz in timezones:
if tz[0]<=offs:
return {'minutes':int((offs-tz[0])/60),'places':tz[1]}
return {'minutes':666,'places':["Snafu (Yes. It's a bug)"]}
def main():
fourtwenty = next420()
place = random.choice(fourtwenty['places'])
if len(fourtwenty['places'])>1:
title = "Get ready for #fourtwenty at {0} and other fine places.".format(place)
else:
title = "Get ready for #fourtwenty at {0}.".format(place)
file('420.rss','w').write(RSS2(
title='Global 4:20 clock',
link='https://zzzen.com/420',
description='Keep up with where #FourTwenty happens next',
language='en',
items=[RSSItem(
title=title,
link='https://zzzen.com/420#{0}'.format(urllib2.quote(place)))]).to_xml('utf-8'))
if __name__=='__main__':
main()