From d1819dc50c6309fa5c4ada8c6aa06b4f39027972 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 13 May 2023 23:24:43 +0200 Subject: [PATCH] added trs_lib --- trs_lib.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 trs_lib.py diff --git a/trs_lib.py b/trs_lib.py new file mode 100644 index 0000000..425868d --- /dev/null +++ b/trs_lib.py @@ -0,0 +1,24 @@ +from random import Random; +from jsonrpcclient import Request +from jsonrpcclient.http_client import HTTPClient +import sys,os +class TRS(Random): + def __init__(self,apikey_path): + try: + with open (apikey_path, 'r') as f: + apikey=f.readline() + except: + print("Please provide a file that contains only your apikey with the -a option, if no option is provided the script assumes that the apikey file has this path: " + args.apikey) + exit(1) + #Prevent program segments from blabbering to stdout/stderr + with open(os.devnull, "w") as devnull: + old_stdout = sys.stdout + sys.stdout = devnull + old_stderr = sys.stderr + sys.stderr = devnull + client = HTTPClient("https://api.random.org/json-rpc/2/invoke") + response = client.send(Request("generateIntegers", apiKey=apikey,n="1",min='1',max="1000000000")) + seed=response["random"]["data"] + sys.stdout = old_stdout + sys.stderr = old_stderr + super().seed(seed[0])