-
Notifications
You must be signed in to change notification settings - Fork 1
/
collectBitcoinDataStoreInMongo.py
37 lines (31 loc) · 1.06 KB
/
collectBitcoinDataStoreInMongo.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
import urllib
import json
from pymongo import MongoClient
import pymongo
from bson import ObjectId
profileLinks = ['https://blockchain.info/address/115p7UMMngoj1pMvkpHijcRdfJNXj6LrLn', 'https://blockchain.info/address/13AM4VW2dhxYgXeQepoHkHSQuy6NgaEb94', 'https://blockchain.info/address/12t9YDPgwueZ9NyMgw519p7AA8isjr6SMw']
# Connect to MongoDB
client = MongoClient("localhost", 27017, maxPoolSize=50)
# Connect to db bitcoindb
db=client.bitcoindb
for profiles in profileLinks:
offset = 0
while offset < 101:
fullUrl = profiles + '?format=json&offset=' + str(offset) + '&filter=2'
response = urllib.urlopen(fullUrl)
data = json.loads(response.read())
if offset > 0:
matchedUser = db.wannacry.find_one({'profileID': profiles[32:]})
txsData = []
print matchedUser['_id']
txsData.append(data['txs'])
print data['txs']
db.wannacry.update({'_id': ObjectId(matchedUser['_id'])}, {'$push': {'data': {'txs':{data['txs']}}}})
else:
result = db.wannacry.insert_one(
{
"profileID" : profiles[32:],
"data" : data
}
)
offset = offset + 50