-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch_itch_data.py
64 lines (57 loc) · 1.91 KB
/
fetch_itch_data.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
import requests
import math
import sys
# funcs
def sort_list_by_rating(v):
return v["rating_count"]
def sort_list_by_coolness(v):
return v["coolness"]
def sort_list_by_karma(v):
c = v["coolness"]
r = v["rating_count"]
return math.log(1 + c) - math.log(1 + r) / math.log(5)
def find_game_index(game_id, game_list):
i = 0
while i < len(game_list):
game = game_list[i]
# if game["game"]["title"] == game_name:
# return i + 1
if game["game"]["id"] == game_id:
return i + 1
i += 1
return -1
def find_game_name(game_id: int, game_list: list):
i = 0
while i < len(game_list):
game = game_list[i]
if game["game"]["id"] == game_id:
return game["game"]["title"]
i += 1
return -1
def run_data(jam_id: str, game_id: int) -> str:
r = requests.get(f"https://itch.io/jam/{jam_id}/entries.json")
data = r.json()
game_list = data["jam_games"]
orignal_list = list(game_list)
game_count = len(game_list)
rount_to_digit = 2
popular_num = find_game_index(game_id, orignal_list)
game_list.sort(reverse=True, key=sort_list_by_rating)
ranking_num = find_game_index(game_id, game_list)
game_list.sort(reverse=True, key=sort_list_by_coolness)
coolness_num = find_game_index(game_id, game_list)
game_list.sort(reverse=True, key=sort_list_by_karma)
karma_num = find_game_index(game_id, game_list)
game_name = find_game_name(game_id, game_list)
output = f"""Results for "{game_name}" - {game_id}:
Popular rank: #{popular_num} - {round(popular_num / game_count * 100, rount_to_digit)}%
Rating rank: #{ranking_num} - {round(ranking_num / game_count * 100, rount_to_digit)}%
Coolness rank: #{coolness_num} - {round(coolness_num / game_count * 100, rount_to_digit)}%
karma_num rank: #{karma_num} - {round(karma_num / game_count * 100, rount_to_digit)}%
""".strip()
return output
if __name__ == "__main__":
jam_id = str(sys.argv[1])
game_id = int(sys.argv[2])
output = run_data(jam_id=jam_id, game_id=game_id)
print(output)