-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
73 lines (42 loc) · 1.4 KB
/
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
70
71
72
73
# The code shown below is an excerpt from:
# https://github.com/woctezuma/steam-market/blob/master/utils.py
import datetime
import json
from pathlib import Path
def get_data_folder():
data_folder = 'data/'
Path(data_folder).mkdir(exist_ok=True)
return data_folder
def get_bot_listing_file_name():
bot_listing_file_name = get_data_folder() + 'asf_bots.json'
return bot_listing_file_name
def get_temp_base_file_name_suffixe():
temp_file_name = 'temp.json'
return temp_file_name
def get_temp_base_file_name():
temp_base_file_name = '{}_{}'.format(
get_current_day_as_str(),
get_temp_base_file_name_suffixe(),
)
return temp_base_file_name
def get_current_day_as_str():
current_day_as_str = datetime.date.today().isoformat()
return current_day_as_str
def save_to_disk(data, base_file_name=None):
if base_file_name is None:
base_file_name = get_temp_base_file_name()
output_file_name = get_data_folder() + base_file_name
with open(output_file_name, 'w') as f:
json.dump(data, f)
return
def load_from_disk(base_file_name=None):
if base_file_name is None:
base_file_name = get_temp_base_file_name()
input_file_name = get_data_folder() + base_file_name
with open(input_file_name) as f:
data = json.load(f)
return data
def main():
return True
if __name__ == '__main__':
main()