Skip to content

Instantly share code, notes, and snippets.

@naoyamakino
Created February 22, 2011 01:04
Show Gist options
  • Save naoyamakino/838043 to your computer and use it in GitHub Desktop.
Save naoyamakino/838043 to your computer and use it in GitHub Desktop.
iCal feed parser for HearNear.org
from icalendar import Calendar, Event
import simplejson as json
import re
import web
from mimerender import mimerender
import sys
event = {}
urls = (
'https://api.geoloqi.com/1/place/create', 'place'
)
class place:
def POST(self, event):
'''
need to post event here
'''
def get_lat(d):
if d.find("<Latitude>") > 0:
event['latitude'] = d[d.find("<Latitude>")+10:d.find("</Latitude>")]
def get_longitude(d):
if d.find("<Longitude>") > 0:
event["longitude"] = d[d.find("<Longitude>")+11:d.find("</Longitude>")]
def get_lat_long(detail):
for d in detail:
get_lat(d)
get_longitude(d)
if __name__ == '__main__':
if len(sys.argv) != 2:
print 'Usage: python parser.py [ics file]'
sys.exit()
else:
try:
cal = Calendar.from_string(open(sys.argv[1], 'rb').read())
except:
print 'error opening ' + sys.argv[1]
sys.exit()
for component in cal.walk():
if component.name == "VEVENT":
extra = {}
uid = component.get('UID')
match = re.search('[0-9]+', uid)
event['name'] = match.group(0)
event['radius'] = 500
event['layer_id'] = 'go'
dtstart = component.get('DTSTART')
summary = str(component.get('SUMMARY'))
location = str(component.get('LOCATION'))
detail = component.get('X-TRUMBA-CUSTOMFIELD')
get_lat_long(detail)
date = str(dtstart)
event['date_from'] = date[:8]
extra['summary'] = summary
extra['location'] = location
event['extra'] = extra
#TODO: need to post this event to 'https://api.geoloqi.com/1/place/create'
#currently I'm using http://webpy.org/ to REST.
print event
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment