Пример #1
0
def getAttending():
    totalIdCount = 0
    tableiter = TableIterator(EVENTTABLENAME, 'facebook_event_id')
    attendeeiter = TableIterator(ATTENDEETABLENAME,'facebook_user_id')
    first_response = tableiter.batchGetItemAttributes(ATTRIBUTES)
    last_key = first_response['LastEvaluatedKey']
    facebookapi = FacebookApi()
    facebookapi.generateAccessToken()

    for response in first_response['Items']:
        print(response)
        attendee_list = makeAttendeeList(facebookapi, response)
        updateAttendees(response, attendee_list, tableiter, attendeeiter)

    while last_key is not None:
        next_response = tableiter.batchGetItemAttributes(ATTRIBUTES, startkey=last_key)
        print(next_response)
        for response in next_response['Items']:
            attendee_list = makeAttendeeList(facebookapi, response)
            updateAttendees(response, attendee_list, tableiter, attendeeiter)
        try:
            last_key = next_response['LastEvaluatedKay']
        except KeyError:
            last_key = None
            pass
Пример #2
0
def iterateResponsesStarting(start_address_key):
    key_err = False
    facebookapi = FacebookApi()
    facebookapi.generateAccessToken()
    tableiter = TableIterator(TABLENAME)
    last_response = start_address_key
    nextResponse = tableiter.batchGetItemWithName(ATTRIBUTES, last_response)

    while key_err == False:
        for response in nextResponse['Items']:
            print("response", response)
            facebookNames = facebookapi.facebookSearchName(response['name'])
            try:
                for name in facebookNames['data']:
                    print(name)
                    facebookAddress = facebookapi.facebookGetAddress(name['id'])
                    try:
                        print(facebookAddress['location']['street'], " || ", response['location']['display_address'][0])
                        if addressEquals(facebookAddress['location']['street'], response['location']['display_address'][0]):
                            totalIdCount += 1
                            print("=================match on next response: ", totalIdCount)
                            tableiter.updateItemSet(response['address_key'], 'facebook_id', name['id'])
                            break
                    except Exception:
                        try:
                            parentId = facebookAddress['location']['located_in']
                            facebookAddress = facebookapi.facebookGetAddress(parentId)
                            print("second try: ", facebookAddress)
                            if facebookAddress['location']['street'] == response['location']['display_address'][0]:
                                totalIdCount += 1
                                print("=================match on next parent: ", totalIdCount)
                                tableiter.updateItemSet(response['address_key'], 'facebook_id', name['id'])
                                break
                        except Exception:
                            pass
                        pass
            except KeyError:
                pass

        tableiter.narcolepsy()
        try:
            last_response = nextResponse['LastEvaluatedKey']
            print("last response", last_response)
            nextResponse = tableiter.batchGetItemWithName(ATTRIBUTES, last_response)
        except KeyError:
            keyErr = True
    print("Done!")
Пример #3
0
def iterateFirstResponse():
    tableiter = TableIterator(TABLENAME)
    response = tableiter.batchGetItemWithNameFirst(ATTRIBUTES)
    return response
import requests
import re
from decimal import Decimal
from general.tableiterator import TableIterator
from facebookapi.facebookapi import FacebookApi


ITERATORTABLENAME = "YelpVenuesFiltered"
PAGETABLENAME = "FacebookPagesFiltered"
EVENTTABLENAME = "FacebookEventsFiltered"
ATTRIBUTES = "address_key, #L"
dynamodb = boto3.resource("dynamodb", region_name="us-west-2")
pagetable = dynamodb.Table(PAGETABLENAME)
eventtable = dynamodb.Table(EVENTTABLENAME)

tableiter = TableIterator(ITERATORTABLENAME, "address_key")
response = tableiter.batchGetItemWithFBID()
lastkey = response["LastEvaluatedKey"]
facebookapi = FacebookApi()
facebookapi.generateAccessToken()

while lastkey is not None:
    for item in response["Items"]:
        print(item)
        eventidlist = []
        (events, nextkey) = facebookapi.getHistoricalEvents(item["facebook_id"])
        if events is not None:
            eventslist = []
            for pagedevent in events:
                eventslist.append(pagedevent)
                while nextkey is not None: