logging.error("no value for 'checkins' in history: " + str(history)) userinfo.put() return -1, 0 elif history['checkins']['items'] == None: userinfo.put() return 0, 0 history['checkins']['items'].reverse() logging.debug('will process %d items' % (len(history['checkins']['items']))) for checkin in history['checkins']['items']: if 'venue' in checkin: j_venue = checkin['venue'] if 'id' in j_venue: uservenue = UserVenue.all().filter('user = '******'venue_guid = ', str(j_venue['id'])).get() if not uservenue and 'location' in j_venue and 'lat' in j_venue['location'] and 'lng' in j_venue['location']: userinfo.venue_count = userinfo.venue_count + 1 uservenue = UserVenue(parent=userinfo, location = db.GeoPt(j_venue['location']['lat'], j_venue['location']['lng'])) uservenue.venue_guid = str(j_venue['id']) uservenue.update_location() uservenue.user = userinfo.user uservenue.checkin_guid_list = [] if uservenue: # if there's no uservenue by this point, then the venue was missing a location uservenue.checkin_guid_list.append(str(checkin['id'])) userinfo.checkin_count += 1 def put_updated_uservenue_and_userinfo(uservenue_param, userinfo_param, num_added): uservenue_param.put() userinfo_param.put() return num_added + 1 try: num_added = db.run_in_transaction(put_updated_uservenue_and_userinfo, uservenue, userinfo, num_added) except BadRequestError, err: logging.warning("Database transaction error due to entity restrictions: %s" % err)