-
Notifications
You must be signed in to change notification settings - Fork 2
/
meetup.py
59 lines (48 loc) · 1.3 KB
/
meetup.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
"""Rough and ready meetup.com api wrapper."""
import json
import re
try:
from urllib import urlencode
from urllib2 import urlopen, Request
except ImportError:
from urllib.parse import urlencode
from urllib.request import urlopen, Request
from keys import API_KEY
DEBUG = 1
SECRET = 1
def meetup_call(slug, **kwargs):
kwargs['key'] = API_KEY
url = "https://api.meetup.com/" + slug
url += "?" + urlencode(kwargs)
return meetup_url_call(url)
def meetup_url_call(url):
if DEBUG > 0:
show_url = url
if SECRET:
show_url = re.sub(r"key=[0-9a-fA-F]{30}", "key=xyzzy", show_url)
print("opening %r" % show_url)
headers = { 'Accept-Charset': 'utf-8' }
req = Request(url, None, headers)
resp = urlopen(req)
j = resp.read()
try:
return json.loads(j)
except ValueError:
print(url)
print(resp.getcode())
print(repr(j))
raise
def meetup(slug, **kwargs):
results = []
response = meetup_call(slug, **kwargs)
while True:
try:
next = response['meta']['next']
except KeyError:
print(response)
raise
results.extend(response['results'])
if not next:
break
response = meetup_url_call(next)
return results