1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 21:44:21 +00:00
royalnet/update.py

124 lines
4.1 KiB
Python
Raw Normal View History

2017-10-10 21:30:06 +00:00
import db
import errors
import time
2018-06-09 15:39:58 +00:00
session = None
2017-10-10 21:30:06 +00:00
# Stop updating if Ctrl-C is pressed
try:
2018-06-09 15:23:12 +00:00
while True:
session = db.Session()
# Update Steam
2018-06-13 22:29:51 +00:00
print("STEAM")
for user in session.query(db.Steam).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 Rocket League
# 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)
2018-06-13 22:29:51 +00:00
# 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)
2018-06-09 15:23:12 +00:00
# Update Overwatch
2018-08-05 10:07:35 +00:00
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)
2018-06-09 15:23:12 +00:00
print("Committing...\t\t")
session.commit()
print("OK")
print("Closing...\n\n")
session.close()
print("OK")
2018-06-09 15:27:55 +00:00
print("Waiting 1800s...\t\t")
for i in range(0, 20):
time.sleep(90)
print("")
2017-10-10 21:30:06 +00:00
except KeyboardInterrupt:
pass
finally:
2018-06-09 15:23:12 +00:00
print("Closing...")
try:
session.close()
except Exception:
print("Maybe")