-
Notifications
You must be signed in to change notification settings - Fork 0
/
guiLib.py
171 lines (123 loc) · 4.08 KB
/
guiLib.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
from Game import *
from GuiLootItem import *
import random
from LootItem import *
hex_digits = "0123456789ABCDEF"
modifiers = ["bad", "ok", "good", "awesome", "godly"]
types = ["sword", "gun", "churro", "noodle", "shield"]
conjs = ["of", "in", "with", "without", "having", "derived from", "inside of", "outside of"]
attrs = ["justice", "evil", "zits", "pastries", "noodle-osity", "helplessness", "body odor"]
types2 = ["weapon", "armor", "consumable", "sellable"]
def parent(w: Widget):
"""
:param w: The child widget.
:return: The parent of widget ``w``.
"""
return w.nametowidget(name=w.winfo_parent())
def printif(*thing, b=False):
"""
Print ``thing`` if ``b`` is true
:param thing: The thing.
:param b: The condition.
:return: None
"""
if (b):
print(*thing)
def random_item(list):
"""
Randomly select an element from ``list``.
:return: Return a random item in list ``list`` between ``0`` and ``len(list)``.
"""
if len(list) is 0:
return None
return list[random.randrange(0, len(list))]
def randomLootItem() -> LootItem:
"""
Generate a random ``LootItem`` object.
:return: A random ``LootItem``.
"""
name = f"{random_item(modifiers)} {random_item(types)} {random_item(conjs)} {random_item(attrs)}"
rarity = random.uniform(0, 1)
type = random_item(types2)
return LootItem(name, rarity, type)
def random_hex_digit():
"""
Return a random single-digit hex string.
:return: The hex string.
Example:
``random_hex_digit() -> "E"``
"""
return random_item(hex_digits)
def random_hex_string(l=6):
"""
Return a random hex color string.
:param l: How long the hex string will be.
:return: The hex string.
Example:
``random_hex_string(l=3) -> "A0E"``
``random_hex_string(l=1) -> "F"``
"""
return ''.join([random_hex_digit() for i in range(l)])
# https://csgostash.com/img/skins/large_1920/s500.png
# https://csgostash.com/img/containers/c238.png
def generate_URLS(url: str = "https://csgostash.com/img/skins/large_1920/s", times: int = 1000, suffix: str = ".png"):
"""
Generate a list of icon URLs.
:param url: The prefix to apply to the URL.
:param times: How many URLs to generate.
:param suffix: The file suffix to apply to the URL.
:return: A list of URL strings that probably have images.
"""
urls = []
for i in range(times):
urls.append(url + str(i) + suffix)
return urls
def save_URL_to_file(url: str, filepath: str) -> None:
"""
Save the content located at ``url`` to a file located at ``filepath``.
:param url:
:param filepath:
:return:
"""
def generate_URL_file(urls: list, path: str = "./_data/icon_URLs/", name: str = "testlist", ext: str = ".txt") -> None:
"""
Save ``urls`` to a file.
:param urls: The list of URLs.
:param path: The path for the ``urls`` file to be saved.
:param name: The name of the file.
:param ext: The extension of the file.
"""
f = open(path + name + ext, "w")
for url in urls:
f.write(url + "\r\n")
f.close()
def generate_all_URLs():
"""
Generate all URL list files that reference images.
"""
generate_URL_file(generate_URLS("https://csgostash.com/img/skins/large_1920/s"), name="skins")
generate_URL_file(generate_URLS("https://csgostash.com/img/containers/c"), name="containers")
def download_all_files(dir: str = "_data/icon_URLs"):
"""
Download all files pointed to by text files inside of directory ``dir``.
"""
pass
def main():
"""
Interactive function-list REPL for doing various maintenance tasks.
"""
callbacks = {
"quit": lambda: exit(0),
"urls": generate_all_URLs,
}
while True:
print("options: ")
pprint(callbacks)
inp = input(" > ")
if inp in callbacks:
print(f"Running {callbacks[inp].__name__}()...")
callbacks[inp]() # call what they specify
else:
print(f"'{inp}' not in callback list!")
if __name__ == "__main__":
main()