1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-12-18 07:34:20 +00:00
royalnet/update.py

110 lines
3.4 KiB
Python
Raw Normal View History

2017-10-10 21:30:06 +00:00
import db
import errors
import time
2017-10-30 09:46:37 +00:00
session = db.Session()
2017-10-10 21:30:06 +00:00
# Stop updating if Ctrl-C is pressed
try:
# Update Steam
print("STEAM")
2017-10-30 09:46:37 +00:00
for user in session.query(db.Steam).all():
2017-10-27 09:53:05 +00:00
t = time.clock()
2017-10-10 21:30:06 +00:00
print(f"Updating {user.royal.username}", end="\t\t", flush=True)
try:
user.update()
except errors.RequestError:
print("Request Error")
except errors.NotFoundError:
print("Not Found Error (?)")
else:
print("OK")
finally:
2017-10-27 09:53:05 +00:00
sleep_time = 1 - time.clock() + t
time.sleep(sleep_time if sleep_time > 0 else 0)
2017-10-10 21:30:06 +00:00
# Update Rocket League
print("ROCKET LEAGUE")
2017-10-30 09:46:37 +00:00
for user in session.query(db.RocketLeague).all():
2017-10-27 09:53:05 +00:00
t = time.clock()
2017-10-10 21:30:06 +00:00
print(f"Updating {user.steam.royal.username}", end="\t\t", flush=True)
try:
user.update()
except errors.RequestError:
print("Request Error")
except errors.NotFoundError:
print("Not Found Error (?)")
else:
print("OK")
finally:
2017-10-27 09:53:05 +00:00
sleep_time = 1 - time.clock() + t
time.sleep(sleep_time if sleep_time > 0 else 0)
2017-10-10 21:30:06 +00:00
# Update Dota 2
print("DOTA 2")
2017-10-30 09:46:37 +00:00
for user in session.query(db.Dota).all():
2017-10-27 09:53:05 +00:00
t = time.clock()
2017-10-10 21:30:06 +00:00
print(f"Updating {user.steam.royal.username}", end="\t\t", flush=True)
try:
user.update()
except errors.RequestError:
print("Request Error")
except errors.NotFoundError:
print("Not Found Error (?)")
else:
print("OK")
finally:
2017-10-27 09:53:05 +00:00
sleep_time = 1 - time.clock() + t
time.sleep(sleep_time if sleep_time > 0 else 0)
2017-10-10 21:30:06 +00:00
# Update League of Legends
print("LEAGUE OF LEGENDS")
2017-10-30 09:46:37 +00:00
for user in session.query(db.LeagueOfLegends).all():
2017-10-27 09:53:05 +00:00
t = time.clock()
2017-10-10 21:30:06 +00:00
print(f"Updating {user.royal.username}", end="\t\t", flush=True)
try:
user.update()
except errors.RequestError:
print("Request Error")
except errors.NotFoundError:
print("Not Found Error (?)")
else:
print("OK")
finally:
2017-10-27 09:53:05 +00:00
sleep_time = 1 - time.clock() + t
time.sleep(sleep_time if sleep_time > 0 else 0)
2017-10-10 21:30:06 +00:00
# Update Osu!
print("OSU!")
2017-10-30 09:46:37 +00:00
for user in session.query(db.Osu).all():
2017-10-27 09:53:05 +00:00
t = time.clock()
2017-10-10 21:30:06 +00:00
print(f"Updating {user.royal.username}", end="\t\t", flush=True)
try:
user.update()
except errors.RequestError:
print("Request Error")
except errors.NotFoundError:
print("Not Found Error (?)")
else:
print("OK")
finally:
2017-10-27 09:53:05 +00:00
sleep_time = 1 - time.clock() + t
time.sleep(sleep_time if sleep_time > 0 else 0)
2017-10-17 18:49:28 +00:00
# Update Overwatch
print("OVERWATCH")
2017-10-30 09:46:37 +00:00
for user in session.query(db.Overwatch).all():
2017-10-27 09:53:05 +00:00
t = time.clock()
2017-10-17 18:49:28 +00:00
print(f"Updating {user.royal.username}", end="\t\t", flush=True)
try:
user.update()
except errors.RequestError:
print("Request Error")
except errors.NotFoundError:
print("Not Found Error (?)")
else:
print("OK")
finally:
2017-10-27 09:53:05 +00:00
sleep_time = 1 - time.clock() + t
time.sleep(sleep_time if sleep_time > 0 else 0)
2017-10-10 21:30:06 +00:00
except KeyboardInterrupt:
pass
finally:
print("Committing...\t\t")
2017-10-30 09:46:37 +00:00
session.commit()
2018-02-26 09:34:44 +00:00
print("OK")