-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathgame_library.py
More file actions
51 lines (41 loc) · 1.44 KB
/
game_library.py
File metadata and controls
51 lines (41 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import json
from dotenv import load_dotenv
import os
env=os.getenv
load_dotenv()
def open_library(library):
try:
return open(library, encoding="utf8")
except FileNotFoundError as e:
print("Some library locations not found: "+str(e))
except TypeError as e:
print("Check your .env files has been updated")
exit(1)
GOG_LIBRARY=os.path.join(env('PATHO'), env('GOG_LIBRARY'))
AMAZON_LIBRARY=os.path.join(env('PATHO'), env('AMAZON_LIBRARY'))
EPIC_LIBRARY=os.path.join(env('PATHO'), env('EPIC_LIBRARY'))
GOG_LIBRARY=open_library(GOG_LIBRARY)
AMAZON_LIBRARY=open_library(AMAZON_LIBRARY)
EPIC_LIBRARY=open_library(EPIC_LIBRARY)
library_dict={}
def library(library,root_json: str):
try:
data=json.load(library)
for i in data[root_json]:
if 'gog' in str(library):
appname=i['app_name']+'_gog'
if 'legendary' in str(library):
appname=i['app_name']+'_legendary'
if 'nile' in str(library):
appname=i['app_name']+'_nile'
try:
if i['app_name']!= 'gog-redist_gog':
library_dict.update({i['title']:appname})
except KeyError:
continue
library.close()
except (KeyError, AttributeError) as e:
print(str(e)+'. Game library likely not found.')
library(GOG_LIBRARY, 'games')
library(AMAZON_LIBRARY, 'library')
library(EPIC_LIBRARY, 'library')