-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_utils.py
69 lines (47 loc) · 1.76 KB
/
print_utils.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
from steam_spy_utils import get_app_name, load_game_names_from_steamspy
from steam_store_utils import get_banner_url, get_store_url
def get_default_image_width():
default_image_width = 150
return default_image_width
def get_bb_code_linked_image(app_id):
image_link_str = '[url={}][img="width:{}px;"]{}[/img][/url]'
bb_code_linked_image = image_link_str.format(
get_store_url(app_id),
get_default_image_width(),
get_banner_url(app_id),
)
return bb_code_linked_image
def get_html_linked_image(app_id, app_name=None):
if app_name is None:
app_name = "Unknown"
# Reference: https://stackoverflow.com/a/14747656
image_link_str = '[<img alt="{}" src="{}" width="{}">]({})'
html_linked_image = image_link_str.format(
app_name,
get_banner_url(app_id),
get_default_image_width(),
get_store_url(app_id),
)
return html_linked_image
def print_ranking_for_app_id(
query_app_id,
reference_app_id_counter,
game_names=None,
num_elements_displayed=10,
):
if game_names is None:
game_names = load_game_names_from_steamspy()
query_app_name = get_app_name(query_app_id, game_names=game_names)
html_linked_image = get_html_linked_image(query_app_id, query_app_name)
print(f"\nQuery:\n\n{html_linked_image}\n\n")
for rank, app_id in enumerate(reference_app_id_counter, start=1):
app_name = get_app_name(app_id, game_names=game_names)
html_linked_image = get_html_linked_image(app_id, app_name)
print(html_linked_image, end="")
# Display results on two rows
if rank == num_elements_displayed / 2:
print("\n")
if rank >= num_elements_displayed:
break
print("\n")
return