1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44: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
2018-06-05 08:47:13 +00:00
print("ROCKET LEAGUE")
for user in session.query(db.RocketLeague).all():
t = time.clock()
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:
sleep_time = 1 - time.clock() + t
time.sleep(sleep_time if sleep_time > 0 else 0)
# Update Dota 2
print("DOTA 2")
for user in session.query(db.Dota).all():
t = time.clock()
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:
sleep_time = 1 - time.clock() + t
time.sleep(sleep_time if sleep_time > 0 else 0)
# Update League of Legends
print("LEAGUE OF LEGENDS")
for user in session.query(db.LeagueOfLegends).all():
t = time.clock()
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:
sleep_time = 1 - time.clock() + t
time.sleep(sleep_time if sleep_time > 0 else 0)
# Update Osu!
print("OSU!")
for user in session.query(db.Osu).all():
t = time.clock()
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:
sleep_time = 1 - time.clock() + t
time.sleep(sleep_time if sleep_time > 0 else 0)
# Update Overwatch
print("OVERWATCH")
for user in session.query(db.Overwatch).all():
t = time.clock()
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:
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")