Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
week start from Thursday
# 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()
@howardpen9
Copy link

howardpen9 commented Oct 31, 2020

NICE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment