-
Notifications
You must be signed in to change notification settings - Fork 1
/
mongopull.py
32 lines (27 loc) · 1.02 KB
/
mongopull.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 csv
from pprint import pprint
import json
import pandas as pd
import pymongo
import ast
import os
# Create connection variable for Project3 database in MLab
# mongodb://<dbuser>:<dbpassword>@ds137003.mlab.com:37003/project3
# connMLAB = 'mongodb://localhost:27017'
# connMLAB = "mongodb://ibaloyan:[email protected]:37003/project3"
connMLAB = "mongodb://jonathan:Biomed#[email protected]:37003/project3"
# connMLAB = "mongodb://grothjd:Biomed#[email protected]:37003/"
# Pass connection to the pymongo instance.
client = pymongo.MongoClient(connMLAB)
# Connect to a database. Will create one if not already available.
# db = client.Apple_y_y
# Fix done for Heroku deployment
# db = client.heroku_8nx1c4b9
db = client.project3
posts = db.zip_community_test5.find({"response.result":{'$exists':True}})
zips = []
for post in posts:
zips.append(post["response"]["result"]["package"]["item"][0]["geo_code"])
with open("zips.csv","w") as file:
zipwriter = csv.writer(file)
zipwriter.writerow(zips)