-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·48 lines (35 loc) · 1.21 KB
/
main.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
#!/usr/bin/env python
from lib.services import *
from lib.ingest_data import run_ingestion, ingest_one
import argparse
def full_ingestion():
print('Running full ingestion')
f, i = get_mongo_collections()
run_ingestion(f, i)
def produce():
data, _ = get_data_from_source()
print('Publishing data from source...' )
with get_message_queue() as q:
for message in data:
print('Publishing message...', message)
q.publish(json.dumps(message))
def consume():
f, i = get_mongo_collections()
def cb(ch, method, properties, body):
body = json.loads(body.decode("utf-8"), 'utf-8')
print('Message received, ingesting...', body)
ingest_one(f, i, body)
with get_message_queue() as q:
q.consume(cb)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Ingest and stream data from NYC open data set")
parser.add_argument('mode', help='the mode to run in: full, produce, consume')
args = parser.parse_args()
if args.mode == 'full':
full_ingestion()
elif args.mode == 'produce':
produce()
elif args.mode == 'consume':
consume()
else:
print(parser.print_help())