tudoanh / python-facebook-bot

Get facebook events from location with Python 3
40 stars 15 forks source link

Events_by_location is pulling in events on incorrect dates #2

Open nspilman opened 6 years ago

nspilman commented 6 years ago

Thank you for the great application. I have found that the location based searches work, except instead if pulling in results for Today, I get results across the board.

For example, I'm looking for Music events in Madison, WI-

TODAY = time.strftime("%Y-%m-%d")
fulllist = facebook_bot.get_events_by_location(43.0730517, -89.4012302, place_type='*',
                           distance=1000, scan_radius=500, base_time=TODAY,
                           fields=EVENT_FIELDS, f=None)

for line in fulllist:
    try:
        if line[0]['category'] == 'EVENT_MUSIC':
            try:
                eventname = line[0]['name']
                eventid = line[0]['id']
                eventstart = line[0]['start_time']
                eventlocation = line[0]['place']['location']['street']
                eventid = {'name':eventname, 'starttime': eventstart, 'location': eventlocation}
                if eventid not in dicts:
                    dicts.append(eventid)
            except:
                print('uhhm')
    except:
        continue

for i in dicts:
    print(i)

My results are as follows. Notice I get ZERO results for today, but instead results for dates across the board.

{'name': 'Le Vent Du Nord', 'location': '800 Langdon St', 'starttime': **'2018-05-05**T20:00:00-0500'}
{'name': "University Opera's La Boheme", 'location': '800 Langdon St', 'starttime': **'2018-02-23**T19:30:00-0600'}
{'name': 'Jack and Kitty: Vaudeville Jug Band Folk', 'location': '201 State St', 'starttime': '**2018-08-07**T19:00:00-0500'}
{'name': 'Propaganda Concert', 'location': '365 E Campus Mall, Ste 200', 'starttime': '2018-03-03T19:00:00-0600'}
{'name': 'Dirty Walter & The Fellas LIVE at SconnieBar', 'location': '1421 Regent Street', 'starttime': '2018-02-17T21:00:00-0600'}
{'name': 'Madtown Undergound Summer Kickoff!', 'location': '1206 Regent Street', 'starttime': '2018-06-02T19:00:00-0500'}
{'name': 'The Lacs - Dirt Rock Tour - The Annex, Madison, WI', 'location': '1206 Regent Street', 'starttime': '2018-04-15T18:00:00-0500'}

Thank you, Nate

tudoanh commented 6 years ago

Yes, because it's the base time, which mean it'll crawl all the events start from today and not limited by any date at all.

You can fix that by adding until query param in this line:
https://github.com/tudoanh/python-facebook-bot/blob/master/facebook_bot/facebook_bot.py#L133

I'll update soon to add the stop date point when filter. You can check the Facebook official docs here for more infomation.
https://developers.facebook.com/docs/graph-api/using-graph-api#time

Thanks for using my lib. Hope you guys will continue report more bugs so I can improve it. P/s: Please using the ``` for code syntax. Like this:

import string
print(string.ascii_letters)
nspilman commented 6 years ago

Thank you for your response!

In regards to the fix you suggest above - my version of the API already has said code in the getevents() function.

events = s.get( BASE_URL + API_VERSION, params={ "ids": page_id, "fields": ( "events.fields({0}).since({1})" .format(','.join(fields), base_time) ), "access_token": token, } ) return events.json()

tudoanh commented 6 years ago

Yes, I mean you could monkey patching my lib until I fix it :D