/
avents.py
61 lines (47 loc) · 1.58 KB
/
avents.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# -*- coding: utf-8 -*-
import json
import click
import requests
from blessings import Terminal
from terminaltables import AsciiTable
config = dict()
def read_config(config_file_path):
"""
Function is used to read config file into config dictionary
"""
global config
config = json.loads(open(config_file_path).read())
def get_events(city):
"""
This method is used to get list of evens for a given city
"""
results = []
#Prams for Meetup
# City ID: 1018090
# Category ID for Tech: 34
# Category ID for Career & Business: 2
URL = "https://api.meetup.com/2/concierge?offset=0&city=%s&format=json&category_id=34&photo-host=public&page=500&sign=true&key=%s&raduis=100" % (city, config.get('meetup_api_key'))
response = requests.get(URL)
if response.status_code == 200:
data = json.loads(response.text)
for event in data['results']:
record = []
record.append(event['group']['name'])
if 'venue' in event and 'name' in event['venue']:
record.append(event['venue']['name'])
if 'venue' in event and 'address_1' in event['venue']:
record.append(event['venue']['address_1'])
record.append(event['event_url'])
results.append(record)
return results
@click.command()
@click.option('--city', default='mumbai', help='City from where you want to see events of')
def show_events(city):
events = [['Group Name', 'Venue Name','Address', 'URL']] + get_events(city)
terminal = Terminal()
print "Showing events from city:", terminal.bold(city)
event_table = AsciiTable(events)
print event_table.table
if __name__ == "__main__":
read_config('config.json')
show_events()