Ejemplo n.º 1
0
     except HTTPError:
         # Handle the case where a user no longer exists in the API
         #     (This probably will never occur -- 4sq presumably erase
         #     all friend connections with removed users.)
         logging.info( "HTTPError for friend %s. skipping.", friend_4sq_id )
         continue
     
     # Check that the friend user is a 'user' and not a brand (etc.)
     if friend_api_dict['type'].lower() != 'user':
         logging.info( "friend (4sq id =  %s) was not of type 'user'. skipping.", friend_4sq_id )
         continue 
     
     # Add the friend user if necessary
     friend_obj = dbw.get_user_from_database( friend_dict )
     if friend_obj is None:
         friend_obj = dbw.add_user_to_database( friend_dict )
         logging.debug( 'added new user to database: %s', friend_obj )
     
     # Add friendship in each direction (iff not already added in this run)
     friendship = dbw.get_friendship_from_database( user_obj, friend_obj, crawl_id ) 
     if len(friendship) == 0:
         fship_obj = dbw.add_friendship_to_database( user_obj, friend_obj, crawl_id )
         logging.debug( 'added new row to friendships: %s', fship_obj )
         friend_rows_added += 1
         
     friendship = dbw.get_friendship_from_database( friend_obj, user_obj, crawl_id )
     if len(friendship) == 0:
         fship_obj = dbw.add_friendship_to_database( friend_obj, user_obj, crawl_id )
         logging.debug( 'added new row to friendships: %s', fship_obj )
         friend_rows_added += 1