-
-
Save aaronpk/839701 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
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 | |
req = urllib2.Request("https://api.geoloqi.com/1/place/create", event, {'content-type':'application/json', 'authorization':'OAuth xxxxxxxxxxGEOLOQI_ACCESS_TOKENxxxxxxxx'}) | |
response_stream = urllib2.urlopen(req) | |
response = response_stream.read() | |
print response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment