forked from GiansCode/eco-updater
-
Notifications
You must be signed in to change notification settings - Fork 0
/
updater.py
61 lines (43 loc) · 1.59 KB
/
updater.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
import json
import os
from requests import get
import utils
from updaters.essentials import Essentials
from updaters.shopguiplus import ShopGuiPlus
items_per_page = 45
raw_url = 'https://raw.githubusercontent.com/Biggsen/vz-price-guide/main/src/_data/{}.json'
shops = ['drops', 'earth', 'food', 'ores', 'sand', 'stone', 'utility', 'wood']
# See https://github.com/Biggsen/vz-price-guide/blob/df71cb75d684a575dab282ea8bf5382a23c3b539/src/index.njk#L3-L4
price_multiplier = 1
sell_margin = 0.30
shop_gui_plus = ShopGuiPlus(items_per_page, price_multiplier, sell_margin)
essentials = Essentials(items_per_page, price_multiplier, sell_margin)
def get_content(shop_name):
"""
Do a GET request for the given shop and return the content
:param shop_name: the file name
:type shop_name: str
:return content as json or None
"""
response = get(raw_url.format(shop_name))
if not response.ok:
utils.log(
'',
shop_name,
f"Request for {response.url} failed with status code {response.status_code}:\n {response.reason}"
)
return None
return json.loads(response.content)
def run():
"""The entry point of this script"""
if not os.path.exists("./shops"):
os.mkdir("./shops")
for shop in shops:
utils.log('', shop, "Updating...")
content = get_content(shop)
if content is None:
utils.log('', shop, 'Could not get the content, skippint this shop!\n')
continue
shop_gui_plus.update(shop, content)
essentials.update(shop, content)
essentials.save()