-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproducer_meetups.py
32 lines (26 loc) · 1006 Bytes
/
producer_meetups.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
import pycurl, sys
from AWS_CREDS import *
OPEN_EVENT_STREAM="http://stream.meetup.com/2/open_events"
events_data = list()
MULTIPLE_POST_SEND_LIMIT = 100
if len(sys.argv) == 2:
MULTIPLE_POST_SEND_LIMIT = int(sys.argv[1])
KINESIS_PUT_BATCH_SIZE = MULTIPLE_POST_SEND_LIMIT / 10
KINESIS_PUT_BATCH_SIZE = 1 if KINESIS_PUT_BATCH_SIZE == 0 else KINESIS_PUT_BATCH_SIZE
KINESIS_PUT_BATCH_SIZE = 500 if KINESIS_PUT_BATCH_SIZE > 500 else KINESIS_PUT_BATCH_SIZE
leftOverData = ""
def on_receive(data):
global leftOverData
try:
lines = (leftOverData + data).split("\n")
for l in lines[:-1]:
putDataToKinesisStream(json.loads(l), TYPE_MEETUPS, MULTIPLE_POST_SEND_LIMIT, KINESIS_PUT_BATCH_SIZE)
leftOverData = lines[-1]
except KeyboardInterrupt:
print "Streaming interrupted by someone!"
except Exception as e:
print e
conn = pycurl.Curl()
conn.setopt(pycurl.URL, OPEN_EVENT_STREAM)
conn.setopt(pycurl.WRITEFUNCTION, on_receive)
conn.perform()