Example #1
0
 def mergeOrderedArrays(self, first_list, first_field, second_list, second_field):
     merge = []
     first_index = 0
     second_index = 0
     
     while first_index < len(first_list) and second_index < len(second_list):
         first = first_list[first_index]
         second = second_list[second_index]
         first_date = iso8601.parse_date(first[first_field])
         second_date = iso8601.parse_date(second[second_field])
         if first_date > second_date:
             merge.append(first)
             first_index += 1
         else:
             merge.append(second)
             second_index += 1
     
     merge.extend(first_list[first_index:])
     merge.extend(second_list[second_index:])
     
     return merge
Example #2
0
 def eventFromData(self, data):
     """
     costruisce una istanza di Event a partire da un evento di facebook
     o ritorna l'istanza salvata se esiste
     """
     # read event if exists
     query = Event.all()
     query.filter('facebook_id =', data["id"])
     event = query.get()
     if event:
         return event
         
     # create new event
     if not "venue" in data:
         return None
     venue = data["venue"]
     
     if not "latitude" in venue or not "longitude" in venue:
         return None
     coordinate = db.GeoPt(venue["latitude"], venue["longitude"])
     
     event = Event(facebook_id = data["id"], location = coordinate, name = data["name"])
     if "location" in data:
         event.venue_name = data["location"]
     if "country" in venue:
         event.country = venue["country"]
     event.address = self.postalAddressFromVenueData(venue)
     
     event.period = [iso8601.parse_date(data["start_time"]), iso8601.parse_date(data["end_time"])]
     
     if "description" in data:
         event.description = data["description"]
     if "picture" in data:
         event.picture_url = data["picture"]
     event.put()
     return event
Example #3
0
 def test_compare_iso_dates(self):
     first_date  = iso8601.parse_date("2011-01-12T12:30:55+0000")
     second_date = iso8601.parse_date("2011-02-04T05:30:00+0000")
     self.assertTrue(first_date < second_date)
     
     first_date  = iso8601.parse_date("2012-01-12T12:30:55+0000")
     second_date = iso8601.parse_date("2010-02-04T05:30:00+0000")
     self.assertTrue(first_date > second_date)
     
     first_date  = iso8601.parse_date("2010-01-20T10:30:55+0000")
     second_date = iso8601.parse_date("2010-01-20T12:30:55+02:00")
     self.assertEqual(first_date, second_date)
Example #4
0
def parse_iso_date(date_str):
	"""Wrapper around iso8601 library."""
	return iso8601.parse_date(date_str)