blob: 33c5c98f21deea324d5fae7dd74ae8a7eb0e180a (
plain)
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
|
from pymongo import MongoClient
from bson.json_util import dumps
import json
import csv
client = MongoClient('mongodb://localhost:27017/helpthehome')
#client = MongoClient('mongodb+srv://development:dreamteam@cluster0-krnr4.mongodb.net/helpthehome?retryWrites=true')
db = client.helpthehome
def read_coords_csv():
points = []
with open("../raw/dumb_coordinates.csv") as csvfile:
reader = csv.reader(csvfile, delimiter=",")
line_number = 0
for row in reader:
if line_number == 0:
line_number += 1
continue
# build in accordance with geojson www.geojson.org
points.append({
"type": "Point",
"coordinates" : [ float(row[1]), float(row[0]) ],
"another": "random field"
})
line_number += 1
return points
# into db
def insert_data(points):
print("WRITING to DB...")
for point in points:
result = db.dumbpointscollection.insert_one(point)
# from the db - not necessary
def find_data():
print("READING from DB...")
points = db.dumbpointscollection.find({})
return dumps(points)
# not necessary
def serialize(data, jfilepath):
jdata = find_data()
print("WRITING to FILE...")
with open("../out/dumbdata.json", "w+") as outfile:
outfile.write(jdata)
# load serialized data - not necessary
def read_data_json(jfilepath):
print("READING from FILE...")
with open(jfilepath, "r") as infile:
jdata = json.load(infile)
return jdata
##### Execute functions here #####
#points = read_coords_csv()
#insert_data(points)
jdata = find_data()
serialize(jdata, '../out/dumbdata.json')
#jdata = read_data_json('../out/dumbdata.json')
|