forked from 30mb1/ExchangeTickerCollector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
download.py
46 lines (37 loc) · 1.12 KB
/
download.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
import boto3
from database import Data
import json
import sys
db = Data()
coursor = db.get_tickers()
res_dict = {}
first = True
for ticker in coursor:
if first:
_from = ticker['time']
first = False
time = ticker['time']
last = time
ticker.pop('time')
ticker.pop('_id')
res_dict[time] = ticker
if len(res_dict) == 0:
print ('No data to download in database.')
sys.exit(0)
data_name = _from[:10] + ' - ' + last[:10] + '.json'
tmp = 'tickers/' + data_name
with open(tmp, 'w') as outfile:
json.dump(res_dict, outfile)
client = boto3.client('s3', region_name='us-east-2')
response = client.list_buckets()
buckets = [bucket['Name'] for bucket in response['Buckets']]
bucket_name = 'exchange_data'
if bucket_name not in buckets:
client.create_bucket(Bucket=bucket_name, CreateBucketConfiguration={
'LocationConstraint': 'us-east-2'
})
client.upload_file(tmp, bucket_name, data_name)
presigned_url = client.generate_presigned_url('get_object', Params = {'Bucket': bucket_name, 'Key': data_name})
print ('Your link for downloading: ')
print (presigned_url)
db.del_tickers()