Skip to content

Commit

Permalink
adding auto-upload option to https://nano-faucet.org/beta/chart
Browse files Browse the repository at this point in the history
  • Loading branch information
Srayman committed Sep 16, 2019
1 parent 4e5f274 commit 7dd9bbd
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions config.py.sample
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dpow_enable = 'false'
dpow_url = ''
dpow_api_key = ''
dpow_user = ''
upload = 'false'
upload_user =
upload_key =
#BETA
Expand Down
4 changes: 4 additions & 0 deletions node_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import time
import datetime
import statistics
import upload
import config
from collections import defaultdict
from sys import exit
from time import sleep
Expand Down Expand Up @@ -72,6 +74,8 @@ async def main():
filename2 = 'stats_'+(datetime.utcnow() + timedelta(hours=0)).strftime("%Y-%m-%d")+'.json'
if filename2 != filename:
writeBkup()
if config.upload == 'true':
upload.upload(filename)
timeString = (datetime.utcnow() + timedelta(hours=0)).strftime("%Y-%m-%d")
json_data = []
filename = filename2
Expand Down
4 changes: 4 additions & 0 deletions record_confirmations.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import json
import time
import datetime
import upload
import config
from collections import defaultdict
from sys import exit
from time import sleep
Expand Down Expand Up @@ -70,6 +72,8 @@ async def main():
filename2 = 'confirmation_history_'+(datetime.utcnow() + timedelta(hours=0)).strftime("%Y-%m-%d")+'.json'
if filename2 != filename:
writeBkup()
if config.upload == 'true':
upload.upload(filename)
writeString = timeString+'|'+str(len(json_data))+'\n'
with open('files.txt', 'a') as files:
files.write(writeString)
Expand Down
30 changes: 30 additions & 0 deletions upload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python3
import argparse
import requests
import json
import config

parser = argparse.ArgumentParser()
parser.add_argument('-host', '--node_url', type=str, help='Nano node url', default='localhost')
parser.add_argument('-port', '--node_port', type=str, help='Nano node port', default='55000')
parser.add_argument('-save', '--save', type=int, help='Save blocks to disk how often (in seconds) should be multiple of --delay', default=180)
parser.add_argument('-delay', '--delay', type=int, help='recorder delay (in seconds)', default=15)
parser.add_argument('-timeout', '--timeout', type=float, help='rpc request timeout (in seconds)', default=60)
parser.add_argument('-file', '--file', type=str, help='Filename to upload', default='')
args = parser.parse_args()

def upload(file):
data = {"source":config.upload_user,"key":config.upload_key}

url = 'https://nano-faucet.org/beta/chart/upload/'

with open(file, 'rb') as payload:
files = {'file': (file, payload)}
r = requests.post(url=url, data=data, files=files)
#print(r.status_code)
print(r.text)

if args.file != '':
upload(args.file)
else:
print('Please provide a filename with -file')

0 comments on commit 7dd9bbd

Please sign in to comment.