1
0
Fork 0
mirror of synced 2024-06-26 10:11:19 +12:00

Merge pull request #52 from gnanini/main

added modules for getting a game's steam id and its protondb tier!
This commit is contained in:
Dummerle 2021-05-04 18:30:31 +02:00 committed by GitHub
commit 2d3c1bf295
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 78 additions and 1 deletions

File diff suppressed because one or more lines are too long

74
rare/utils/id.py Normal file
View file

@ -0,0 +1,74 @@
import requests
import json
from datetime import date
file = "game_list.json"
url = "https://api.steampowered.com/ISteamApps/GetAppList/v2/"
def get_id(game_name):
global file
if check_time() == 1:
upgrade_content()
text = open(file, 'r')
game_list = json.load(text)
return game_list[game_name.lower()]
def upgrade_content(): # this function uploads the ids database, aka game_list.json
global url
global file
response = requests.get(url)
content = json.loads(response.text)
table = open(file, 'w')
game_list = {}
for game in content['applist']['apps']:
game_list[game['name'].lower()] = game['appid']
# uploding date on json
today = date.today()
game_list['data'] = {}
for i in "ymd":
game_list["data"][i] = today.strftime('%' + i)
json.dump(game_list, table)
table.close()
def check_time(): # this function check if it's time to update
global file
text = open(file, 'r')
json_table = json.load(text)
text.close()
today = date.today()
day = 0 # it controls how many days it's necessary for an update
for i in 'ymd':
if i == 'd':
day = 7
else:
day = 0
if int(today.strftime('%' + i)) > int(json_table['data'][i]) + day:
return 1
else:
return 0
# you should iniciate the module with the game's steam code
def get_grade(steam_code):
steam_code = str(steam_code)
url = 'https://www.protondb.com/api/v1/reports/summaries/'
res = requests.get(url + steam_code + '.json')
text = res.text
lista = json.loads(text)
# print(lista['tier']) # just for debug pourpouses!!!
return lista['tier']
def id(game_name):
return get_grade(get_id(game_name))

View file

@ -11,6 +11,8 @@ from PyQt5.QtCore import pyqtSignal, QLocale, QSettings
from rare import lang_path, __version__, style_path
from custom_legendary.core import LegendaryCore
import id
logger = getLogger("Utils")
s = QSettings("Rare", "Rare")
IMAGE_DIR = s.value("img_dir", os.path.expanduser("~/.cache/rare/images"), type=str)
@ -182,4 +184,4 @@ def create_desktop_link(app_name, core: LegendaryCore, type_of_link="desktop"):
else:
return
with open(path+igame.title+".bat", "w") as desktop_file:
desktop_file.write(f"rare launch {app_name}")
desktop_file.write(f"rare launch {app_name}")