Add games library with IGDB, file explorer and static files script
This commit is contained in:
1 parent
a16444451a
commit
ec57bd73b3
65 files changed
+2230
-352
No files matched your search
@@ -0,0 +1,47 @@
|
||||
import sys
|
||||
import time
|
||||
|
||||
import games
|
||||
import jsonfile
|
||||
|
||||
ABOUT_FILE = "about.json"
|
||||
REQUEST_DELAY_SECONDS = 0.3
|
||||
|
||||
|
||||
def main() -> int:
|
||||
about = jsonfile.load(ABOUT_FILE)
|
||||
listed_games = about.get("games", [])
|
||||
if not listed_games:
|
||||
print("about.json has no games to import")
|
||||
return 0
|
||||
|
||||
try:
|
||||
already_listed = {game["name"].lower() for game in games.list_games()}
|
||||
except (OSError, ValueError) as error:
|
||||
print(f"Import stopped: {error}", file=sys.stderr)
|
||||
return 1
|
||||
failed = []
|
||||
for game in listed_games:
|
||||
if game["name"].lower() in already_listed:
|
||||
print(f"Already listed {game['name']}")
|
||||
continue
|
||||
try:
|
||||
saved = games.add_game(game.get("url"), game["name"], "played", None, game.get("image"))
|
||||
print(f"Imported {saved['name']} (IGDB {saved['igdbId']})")
|
||||
except (OSError, ValueError) as error:
|
||||
print(f"Skipped {game['name']}: {error}", file=sys.stderr)
|
||||
failed.append(game)
|
||||
time.sleep(REQUEST_DELAY_SECONDS)
|
||||
|
||||
if failed:
|
||||
print(f"{len(failed)} games were not imported, so about.json was left as it is. Fix them and run this again.", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
del about["games"]
|
||||
jsonfile.save(ABOUT_FILE, about)
|
||||
print(f"Imported {len(listed_games)} games and removed them from about.json")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in new issue
Block a user