added trs_lib
This commit is contained in:
parent
f91a3a83a4
commit
d1819dc50c
24
trs_lib.py
Normal file
24
trs_lib.py
Normal file
|
|
@ -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])
|
||||||
Loading…
Reference in New Issue
Block a user