def uservenue_factory(userinfo_param, j_venue_param, checkin_guid_list_param, checkin_list_param, is_unique_param):
   new_uservenue = UserVenue(parent=userinfo_param, location = db.GeoPt(j_venue_param['location']['lat'], j_venue_param['location']['lng']))
   j_venue_param_loc = j_venue_param['location']
   new_uservenue.update_location()
   new_uservenue.user = userinfo_param.user
   new_uservenue.venue_guid     = str(j_venue_param['id'])
   if 'name' in j_venue_param:
     new_uservenue.name         = j_venue_param['name']
   if 'address' in j_venue_param_loc:
     new_uservenue.address      = j_venue_param_loc['address'].replace('\n', ' ').replace('\r', ' ')
   if 'cross_street' in j_venue_param_loc:
     new_uservenue.cross_street = j_venue_param_loc['cross_street']
   if 'state' in j_venue_param_loc:
     new_uservenue.state        = j_venue_param_loc['state']
   if 'zip' in j_venue_param_loc:
     new_uservenue.zipcode      = j_venue_param_loc['zip']
   if 'phone' in j_venue_param:
     new_uservenue.phone        = j_venue_param['phone']
   new_uservenue.has_parent = True
   new_uservenue.is_unique = is_unique_param 
   new_uservenue.checkin_list = checkin_list_param
   new_uservenue.checkin_guid_list = checkin_guid_list_param
   if not new_uservenue.checkin_guid_list or len(new_uservenue.checkin_guid_list) is 0:
     new_uservenue.checkin_guid_list = [str(checkin_id) for checkin_id in new_uservenue.checkin_list]
   return new_uservenue
     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)
         else:
           logging.error("Venue missing location with JSON: %s" % str(j_venue))
 except KeyError:
   logging.error("There was a KeyError when processing the response: " + str(history))
     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)
         else:
           logging.error("Venue missing location with JSON: %s" % str(j_venue))
 except KeyError:
   logging.error("There was a KeyError when processing the response: " + str(history))