1 from xml.dom.minidom import parseString
2 from datetime import datetime, date
9 def parse_json(self, json, lat, long):
10 """ Parse json into usable format """
13 def parse_xml(self, xml, lat, long):
14 """ Parse xml into a dict """
17 dom = parseString(xml)
19 events = dom.getElementsByTagName('event')
21 start_date = self.parse_date(event.getElementsByTagName('startDate')[0].childNodes[0].data)
22 if start_date.date() == today:
23 title = event.getElementsByTagName('title')[0].childNodes[0].data
25 artists_element = event.getElementsByTagName('artists')[0]
27 for artist in artists_element.getElementsByTagName('artist'):
28 artist_list.append(artist.childNodes[0].data)
29 artists = ', '.join(artist_list)
31 venue_details = event.getElementsByTagName('venue')[0]
32 venue_name = venue_details.getElementsByTagName('name')[0].childNodes[0].data
33 address = self.get_address(venue_details.getElementsByTagName('location')[0])
34 geo_data = venue_details.getElementsByTagName('geo:point')[0]
35 venue_lat = geo_data.getElementsByTagName('geo:lat')[0].childNodes[0].data
36 venue_long = geo_data.getElementsByTagName('geo:long')[0].childNodes[0].data
37 distance = location.distance_between(float(lat),
42 events_list.append({'title': title,
50 def get_address(self, location):
51 """ Return the venues address details from the xml element """
56 if location.getElementsByTagName('street')[0].childNodes:
57 street = location.getElementsByTagName('street')[0].childNodes[0].data
58 if location.getElementsByTagName('city')[0].childNodes:
59 city = location.getElementsByTagName('city')[0].childNodes[0].data
60 if location.getElementsByTagName('country')[0].childNodes:
61 country = location.getElementsByTagName('country')[0].childNodes[0].data
62 if location.getElementsByTagName('postalcode')[0].childNodes:
63 postalcode = location.getElementsByTagName('postalcode')[0].childNodes[0].data
64 return '\n'.join([street, city, country, postalcode])
66 def parse_date(self, date_string):
67 """ Parse date string into datetime object """
68 fmt = "%a, %d %b %Y %H:%M:%S"
69 result = time.strptime(date_string, fmt)
70 return datetime(result.tm_year,