-
Notifications
You must be signed in to change notification settings - Fork 0
/
ge_query.py
101 lines (78 loc) · 2.78 KB
/
ge_query.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import requests
import click
import os
import json
@click.command()
@click.argument('query_type', type=str)
def run(query_type):
"""GE-query script
this script accesses the GE-proton git repo to either:
a) return the tarball download link, or;
b) return the name of the release, or;
c) check if the update is already installed
Args:
query_type (str): choose either "url" or "name" to
get the respective data, or "check" to check if the
update is already installed
Returns:
str: either the tarball download URL or the tarball filename
"""
# filter user input
query_type = str(query_type).lower()
# pass the query type into the main function
query(query_type)
def get_data(data, query_type):
""" Data filtering function
Args:
data (dict): the data to filter through
query_type (str): the type of data to look for
Returns:
str: returns the desired data
"""
asset = None
# iterate over assets
for asset in data:
# check each asset
if asset["browser_download_url"][-6:] == "tar.gz":
# if the file is ".tar.gz" its the right one
# return either the URL or name depending on the user's selection
if query_type == "url":
return asset["browser_download_url"]
if query_type == "name":
return asset["name"]
# return nothing if the tar can't be found
return None
def can_update(data):
""" Release check
Compares the newest release with what is currently installed in
order to avoid downloading the same update twice
Args:
data (dir): the data of the current release
Returns:
True if already up-to-date, else false
"""
# get the current GE-proton version
current = get_data(data, "name")
# get the path to .steam/root/compatibilitytools.d/
path = os.path.expanduser("~/.steam/root/compatibilitytools.d/")
versions = os.listdir(path)
return False if current[:-7] in versions else True
def query(query_type):
""" the main function
Args:
query_type (str): the type of data to look for
"""
# initialize empty headers dict
headers = {}
# grab token from auth.json
with open("auth.json", "r") as f:
headers = json.load(f)
# get latest release information
result = requests.get("https://api.github.com/repos/GloriousEggroll/proton-ge-custom/releases/latest", headers=headers).json()
# make an assets dir, this will contain all of the latest release information
assets = result["assets"]
if query_type == "check":
print(can_update(assets))
else:
print(get_data(assets, query_type))
run()