-
Notifications
You must be signed in to change notification settings - Fork 1
/
server-side.py
47 lines (41 loc) · 1.43 KB
/
server-side.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
import praw
import requests
import json
import os
import time
def jsondumper():
clientSecret = os.environ.get('REDDIT_SECRET_KEY')
password = os.environ.get('BOTT_PASSWORD')
reddit = praw.Reddit(client_id='WvfB2YOqYcUlMg',client_secret=clientSecret,username='jsonbot',password=password,user_agent='prawtryv1')
reddit.validate_on_submit=True
with open('dump.json') as inp:
dumpValue=json.load(inp)
selftext = "{}".format(dumpValue)
title = "-json-dump-"
reddit.subreddit("jsondump").submit(title, selftext=json.dumps(dumpValue))
def getValue():
api = os.environ.get('CRYPTO_API')
Headers={
'Accept': 'application/json'
}
parameters = {
'CMC_PRO_API_KEY': api,
'id' : '1,1839,4687,1831,2010,1975,4943,74,1027,2,6636,3890,5426,512,2416,825,3408,7083,3717,52'
}
list_id = [1,1839,4687,1831,2010,1975,4943,74,1027,2,6636,3890,5426,512,2416,825,3408,7083,3717,52]
url = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest'
response = requests.get(url,params=parameters)
recievedValue = response.json()
with open('dump.json','r') as inp:
dumpValue=json.load(inp)
while(len(dumpValue['1'])>23):
for i in list_id:
dumpValue["{}".format(i)].pop(0)
for i in list_id:
dumpValue["{}".format(i)].append("{}".format(recievedValue['data'][str(i)]['quote']['USD']['price']))
with open('dump.json','w') as out:
json.dump(dumpValue,out,indent = 2)
if __name__ == "__main__":
getValue()
jsondumper()
print('Done')