From 7dd9bbdaa461ca4f2382c8afd30df34c04bec423 Mon Sep 17 00:00:00 2001 From: Srayman Date: Sun, 15 Sep 2019 22:27:08 -0400 Subject: [PATCH] adding auto-upload option to https://nano-faucet.org/beta/chart --- config.py.sample | 1 + node_stats.py | 4 ++++ record_confirmations.py | 4 ++++ upload.py | 30 ++++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+) create mode 100644 upload.py diff --git a/config.py.sample b/config.py.sample index a4deded..13c63fb 100644 --- a/config.py.sample +++ b/config.py.sample @@ -8,6 +8,7 @@ dpow_enable = 'false' dpow_url = '' dpow_api_key = '' dpow_user = '' +upload = 'false' upload_user = upload_key = #BETA diff --git a/node_stats.py b/node_stats.py index 4e3b349..e0a89f6 100644 --- a/node_stats.py +++ b/node_stats.py @@ -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 @@ -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 diff --git a/record_confirmations.py b/record_confirmations.py index d20e9b7..8dcc760 100644 --- a/record_confirmations.py +++ b/record_confirmations.py @@ -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 @@ -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) diff --git a/upload.py b/upload.py new file mode 100644 index 0000000..7871a13 --- /dev/null +++ b/upload.py @@ -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') \ No newline at end of file