Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csv
- import datetime
- import json
- import logging
- import requests
- import threading
- import web
- urls = ('/', 'Random')
- app = web.application(urls, globals())
- class Random:
- def GET(self):
- retval = None
- with open('.otp.json') as fin:
- retval_ = json.loads(fin.read())
- retval = retval_.values()
- return retval
- def HEAD(self):
- # Get 6-digit random.org digit
- param = {'num':'1', 'min': '0', 'max': '1000000', 'col':'1', 'base':'10','format': 'plain', 'rnd': 'new'}
- random_six_digits = requests.get('https://www.random.org/integers/', params=param, verify=False).content
- password = random_six_digits.strip()
- expiration_ = datetime.datetime.now() + datetime.timedelta(minutes=1)
- logging.debug("OTP until {1} is {0}".format(password, expiration_))
- expiration = expiration_.strftime('%s')
- with open('.otp.json','w') as fout:
- fout.write(json.dumps({'password': password, 'expiration': expiration}))
- if __name__ == '__main__':
- logging.basicConfig(level=logging.FATAL)
- r = Random()
- r.expiration = datetime.datetime.min
- r.HEAD()
- threading.Timer(60, (lambda:r.HEAD())).start()
- app.run()
Advertisement
Add Comment
Please, Sign In to add comment