Ejemplo n.º 1
0
def main():
   db = UntappdDB()
   cursor = db.query('user_feeds')
   client_id='A346C811ED9267F004471FF258E67A219D399BCB'
   client_secret='320CF0D911C7256FA58DC973CFDF91CBF5689F74'
   lat = 35.278222
   long = -120.666552
   requester = UntappdRequester(client_id, client_secret, 50)
   #requester.get_all_pub_activity(lat, long, 'pub_spikes')
   collected_users = set()
   for cur in db.query('user_feeds'):
      for item in cur['response']['checkins']['items']:
         collected_users.add(item['user']['user_name'])
         #print('USER: %s' % (item['user']['user_name']))
   pub_users = set()
   for cur in db.query('pub_spikes'):
      for item in cur['response']['checkins']['items']:
         pub_users.add(item['user']['user_name'])
         #print('USER: %s' % (item['user']['user_name']))
   for user in pub_users:
      print('PUB USER: %s' % (user))
   for user in collected_users:
      print('COLLECTED USER: %s' % (user))
   uncollected_users = pub_users - collected_users
   for user in uncollected_users:
      print('UNCOLLECTED USER: %s' % (user))
   print('NUM PUB USERS: %d' % (len(pub_users)))
   print('NUM COL USERS: %d' % (len(collected_users)))
   print('NUM UNC USERS: %d' % (len(uncollected_users)))
   return 0
def main():
    db = UntappdDB()
    beer_db = BeerDBMaker()
    transactions = defaultdict(list)
    print("INserting checkins...")
    for cur in db.query("user_feeds"):
        for checkin in cur["response"]["checkins"]["items"]:
            db.insert_document("checkins", checkin)
    # BUILD TRANSCACTIONS
    user_set = set()
    checkins = 0
    for checkin in db.query("checkins"):
        user = checkin["user"]["user_name"]
        rating = checkin["rating_score"]
        brewery = checkin["brewery"]["brewery_name"]
        beer = checkin["beer"]["beer_name"]
        id = beer_db.add_beer(brewery, beer)
        transactions[(user, rating)].append(id)
        user_set.add(user)
        checkins += 1
    # SAVE TRANSACTIONS FILE
    with open("out1_untappd.csv", "w") as transactions_file:
        for (user, rating), beer_list in transactions.items():
            print("%s-%s, %s" % (user, rating, str(beer_list).strip("[").strip("]")), file=transactions_file)
    # SAVE BEER DB
    with open("beers.csv", "w") as beer_db_file:
        beer_db.print_table(beer_db_file)

    # TEST PARSE
    beers = BeerDB("beers.csv")

    print("USERS   : %d" % (len(user_set)))
    print("CHECKINS: %d" % (checkins))

    return 0