1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-24 03:54:20 +00:00

Aggiornato updater

This commit is contained in:
Steffo 2018-06-09 17:23:12 +02:00
parent 294e875236
commit f67c68e1f5

211
update.py
View file

@ -2,108 +2,119 @@ import db
import errors import errors
import time import time
session = db.Session() session = None
# Stop updating if Ctrl-C is pressed # Stop updating if Ctrl-C is pressed
try: try:
# Update Steam while True:
print("STEAM") global session
for user in session.query(db.Steam).all(): session = db.Session()
t = time.clock() # Update Steam
print(f"Updating {user.royal.username}", end="\t\t", flush=True) print("STEAM")
try: for user in session.query(db.Steam).all():
user.update() t = time.clock()
except errors.RequestError: print(f"Updating {user.royal.username}", end="\t\t", flush=True)
print("Request Error") try:
except errors.NotFoundError: user.update()
print("Not Found Error (?)") except errors.RequestError:
else: print("Request Error")
print("OK") except errors.NotFoundError:
finally: print("Not Found Error (?)")
sleep_time = 1 - time.clock() + t else:
time.sleep(sleep_time if sleep_time > 0 else 0) print("OK")
# Update Rocket League finally:
print("ROCKET LEAGUE") sleep_time = 1 - time.clock() + t
for user in session.query(db.RocketLeague).all(): time.sleep(sleep_time if sleep_time > 0 else 0)
t = time.clock() # Update Rocket League
print(f"Updating {user.steam.royal.username}", end="\t\t", flush=True) print("ROCKET LEAGUE")
try: for user in session.query(db.RocketLeague).all():
user.update() t = time.clock()
except errors.RequestError: print(f"Updating {user.steam.royal.username}", end="\t\t", flush=True)
print("Request Error") try:
except errors.NotFoundError: user.update()
print("Not Found Error (?)") except errors.RequestError:
else: print("Request Error")
print("OK") except errors.NotFoundError:
finally: print("Not Found Error (?)")
sleep_time = 1 - time.clock() + t else:
time.sleep(sleep_time if sleep_time > 0 else 0) print("OK")
# Update Dota 2 finally:
print("DOTA 2") sleep_time = 1 - time.clock() + t
for user in session.query(db.Dota).all(): time.sleep(sleep_time if sleep_time > 0 else 0)
t = time.clock() # Update Dota 2
print(f"Updating {user.steam.royal.username}", end="\t\t", flush=True) print("DOTA 2")
try: for user in session.query(db.Dota).all():
user.update() t = time.clock()
except errors.RequestError: print(f"Updating {user.steam.royal.username}", end="\t\t", flush=True)
print("Request Error") try:
except errors.NotFoundError: user.update()
print("Not Found Error (?)") except errors.RequestError:
else: print("Request Error")
print("OK") except errors.NotFoundError:
finally: print("Not Found Error (?)")
sleep_time = 1 - time.clock() + t else:
time.sleep(sleep_time if sleep_time > 0 else 0) print("OK")
# Update League of Legends finally:
print("LEAGUE OF LEGENDS") sleep_time = 1 - time.clock() + t
for user in session.query(db.LeagueOfLegends).all(): time.sleep(sleep_time if sleep_time > 0 else 0)
t = time.clock() # Update League of Legends
print(f"Updating {user.royal.username}", end="\t\t", flush=True) print("LEAGUE OF LEGENDS")
try: for user in session.query(db.LeagueOfLegends).all():
user.update() t = time.clock()
except errors.RequestError: print(f"Updating {user.royal.username}", end="\t\t", flush=True)
print("Request Error") try:
except errors.NotFoundError: user.update()
print("Not Found Error (?)") except errors.RequestError:
else: print("Request Error")
print("OK") except errors.NotFoundError:
finally: print("Not Found Error (?)")
sleep_time = 1 - time.clock() + t else:
time.sleep(sleep_time if sleep_time > 0 else 0) print("OK")
# Update Osu! finally:
print("OSU!") sleep_time = 1 - time.clock() + t
for user in session.query(db.Osu).all(): time.sleep(sleep_time if sleep_time > 0 else 0)
t = time.clock() # Update Osu!
print(f"Updating {user.royal.username}", end="\t\t", flush=True) print("OSU!")
try: for user in session.query(db.Osu).all():
user.update() t = time.clock()
except errors.RequestError: print(f"Updating {user.royal.username}", end="\t\t", flush=True)
print("Request Error") try:
except errors.NotFoundError: user.update()
print("Not Found Error (?)") except errors.RequestError:
else: print("Request Error")
print("OK") except errors.NotFoundError:
finally: print("Not Found Error (?)")
sleep_time = 1 - time.clock() + t else:
time.sleep(sleep_time if sleep_time > 0 else 0) print("OK")
# Update Overwatch finally:
print("OVERWATCH") sleep_time = 1 - time.clock() + t
for user in session.query(db.Overwatch).all(): time.sleep(sleep_time if sleep_time > 0 else 0)
t = time.clock() # Update Overwatch
print(f"Updating {user.royal.username}", end="\t\t", flush=True) print("OVERWATCH")
try: for user in session.query(db.Overwatch).all():
user.update() t = time.clock()
except errors.RequestError: print(f"Updating {user.royal.username}", end="\t\t", flush=True)
print("Request Error") try:
except errors.NotFoundError: user.update()
print("Not Found Error (?)") except errors.RequestError:
else: print("Request Error")
print("OK") except errors.NotFoundError:
finally: print("Not Found Error (?)")
sleep_time = 1 - time.clock() + t else:
time.sleep(sleep_time if sleep_time > 0 else 0) print("OK")
finally:
sleep_time = 1 - time.clock() + t
time.sleep(sleep_time if sleep_time > 0 else 0)
print("Committing...\t\t")
session.commit()
print("OK")
print("Closing...\n\n")
session.close()
print("OK")
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass
finally: finally:
print("Committing...\t\t") print("Closing...")
session.commit() try:
print("OK") session.close()
except Exception:
print("Maybe")