Created
October 30, 2020 11:21
-
-
Save buddies2705/db9b63fc644355b77356fc03138989d4 to your computer and use it in GitHub Desktop.
week start from Thursday
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Hello World program in Python | |
import requests | |
import datetime | |
def run_query(query): # A simple function to use requests.post to make the API call. | |
request = requests.post('https://graphql.bitquery.io/', | |
json={'query': query}) | |
if request.status_code == 200: | |
return request.json() | |
else: | |
raise Exception('Query failed and return code is {},{}'.format(request.status_code,query)) | |
# The GraphQL query | |
def prepare_query(start, end): | |
return """ | |
query { | |
ethereum(network: bsc) { | |
transactions( | |
options: {desc: "date.date"}, | |
date: {since: """+ start + """, till:""" + end + """}) | |
{ | |
date: date { | |
date(format: "%Y-%m-%d") | |
} | |
gasValue | |
gasValueAvg: gasValue(calculate: average) | |
gasPrice | |
avgGasPrice: gasPrice(calculate:average) | |
medGasPrice: gasPrice(calculate: median) | |
maxGasPrice: gasPrice(calculate: maximum) | |
Txs: count | |
Senders: count(uniq:senders) | |
} | |
} | |
}""" | |
def test(start, end): | |
start = '"' + start.strftime("%Y-%m-%d") + '"' | |
end = '"' + end.strftime("%Y-%m-%d") + '"' | |
query = prepare_query(start, end) | |
#do something with data | |
return run_query(query) | |
def loop(): | |
start = datetime.date(2020, 10, 1) | |
end = datetime.date(2020,10,30) | |
while start.weekday() != 3: # This is thursday | |
start += datetime.timedelta(1) | |
# now we have 1st thursday | |
thursday = start | |
wednesday = start + datetime.timedelta(7) | |
while wednesday < end: | |
data = test(thursday, wednesday) | |
print(data) | |
thursday += datetime.timedelta(7) | |
wednesday += datetime.timedelta(7) | |
loop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NICE