Browse Source

Refresh

7rc0
Laurent Kislaire 3 years ago
parent
commit
09b02fc488
  1. 18
      pyfbx/__main__.py

18
pyfbx/__main__.py

@ -15,14 +15,25 @@ log_level = (logging.WARNING, logging.INFO, logging.DEBUG)
def console(log, level):
log.setLevel(level)
formatter = logging.Formatter('%(asctime)s - %(name)14s - %(levelname)s - %(message)s')
if level == logging.DEBUG:
formatter = logging.Formatter('%(asctime)s - %(name)14s - %(levelname)7s - %(funcName)10s:%(lineno)3d - %(message)s')
else:
formatter = logging.Formatter('%(asctime)s - %(name)14s - %(levelname)7s - %(message)s')
stream_handler = logging.StreamHandler()
stream_handler.setFormatter(formatter)
log.addHandler(stream_handler)
def output(fbx, command, json_output, send_url):
res = eval("fbx.{}".format(command))
try:
res = eval("fbx.{}".format(command))
except Exception as exc:
if "403 Client Error" in str(exc):
fbx.log.info("Got 403, refreshing token")
fbx.mksession()
res = eval("fbx.{}".format(command))
else:
raise(exc)
if send_url:
try:
r = requests.post(send_url, json=res)
@ -62,6 +73,7 @@ def main():
app_id = args.app_id
if not args.command:
args.command = ["System.Get_the_current_system_info()"]
myfb = Fbx(nomdns=args.http, url=args.url)
if token:
if token.startswith('f:'):
@ -73,9 +85,9 @@ def main():
device=os.uname().nodename)
log.warning("Save your application token: {}".format(token))
myfb.mksession(app_id=app_id, token=token)
pp = pprint.PrettyPrinter(indent=4)
while True:
log.debug("\n")
for command in args.command:
output(myfb, command, args.json, args.send)
if not args.delay:

Loading…
Cancel
Save