Last active
February 10, 2022 06:09
-
-
Save hellman/f146e896b9ff95ca20cd6c668f3c2283 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#-*- coding:utf-8 -*- | |
import sys, re | |
from ics import Calendar | |
from urllib2 import urlopen | |
import requests | |
print >>sys.stderr, "[i] Starting..." | |
urls = [ | |
"http://www.hackerrank.com/calendar/cal.ics", | |
"https://calendar.google.com/calendar/ical/hackerearth.com_73f0o8kl62rb5v1htv19p607e4%40group.calendar.google.com/public/basic.ics", | |
] | |
whitelist_words = """ | |
Codechef | |
101 Hack | |
20/20 Hack | |
Codeforces | |
SRM | |
TCO | |
cipher | |
crypto | |
Ad Infinitum | |
HourRank | |
Game Theory | |
Easy ' | |
Clash ' | |
Marathon ' | |
Battle Of Bots | |
Circuits | |
Week of Code | |
""".strip().split("\n") | |
whitelist_regexp = [ | |
] | |
events = [] | |
for url in urls: | |
print >>sys.stderr, "[i] Query", url | |
if url.startswith("file://"): | |
text = open(url[7:]).read().decode("utf-8") | |
else: | |
text = requests.get(url).text | |
events += Calendar(text).events | |
print >>sys.stderr, "[i] Finished queries" | |
cal = Calendar() | |
for ev in events: | |
name = ev.name.lower() | |
good = ( | |
False | |
| any(w for w in whitelist_words if w.lower() in name) | |
| any(w for w in whitelist_regexp if re.search(w, name, flags=re.I)) | |
) | |
if good: | |
try: | |
cal.events.add(ev) | |
except: | |
cal.events.append(ev) | |
else: | |
print >>sys.stderr, "REMOVED:", ev.name | |
print >>sys.stderr, "------\n" | |
print """ | |
HTTP/1.1 200 OK | |
Cache-Control: max-age=0, private, must-revalidate | |
Content-Type: text; charset=utf-8 | |
Server: nginx | |
Status: 200 OK | |
Vary: Accept-Encoding | |
Connection: keep-alive | |
""".strip() + "\n" | |
# hack?.. | |
print "BEGIN:VCALENDAR" | |
print "VERSION:2.0" | |
print "CALSCALE:GREGORIAN" | |
print "METHOD:PUBLISH" | |
print "PRODID:hellman" | |
for e in cal.events: | |
print str(e) | |
print "END:VCALENDAR" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ screen -AmS cally socat TCP-l:3030,fork,reuseaddr 'system:./cally.py'