-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongo_add_loc.py
63 lines (45 loc) · 1.53 KB
/
mongo_add_loc.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
60
import collections
from pprint import pprint
import numpy
def mongo(collection_name):
from pymongo import MongoClient
db = MongoClient('gauss', 27017)
collection = db.database[collection_name]
return collection
def update(collection, dict):
collection.replace_one({
"_id": dict['_id']
},
dict
)
print('ok')
collections_list = ['manifestacoes', 'eventos', 'obras', 'tweets']
for c_name in collections_list:
cursor = mongo(c_name).find({'places_grid': {'$exists': True}}, no_cursor_timeout=True)
for c in cursor:
list_cursor_grid = list()
for places in c['places_grid']:
for g in places['grid']:
list_cursor_grid.append((g['w'], g['h']))
c['grid_union'] = list(set(list_cursor_grid))
update(mongo(c_name), c)
# list_locais_grid = list()
# for p in t['locais']:
# try:
# l = mongo()['locais'].find_one({'name': p}, no_cursor_timeout=True)
# list_locais_grid.append({'place': p, 'grid': l['grid']})
# except Exception:
# pass
#
# t['places_grid'] = list_locais_grid
# update(col['manifestacoes'], t)
# from bson.json_util import dumps
# if __name__ == '__main__':
# tweets = mongo()['tweets']
# cursor = tweets.find({})
# file = open("collection.json", "w")
# file.write('[')
# for document in cursor:
# file.write(dumps(document))
# file.write(',')
# file.write(']')