-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
131 lines (98 loc) · 5.02 KB
/
main.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
import json
import secrets
from stepn import StepnRequest, url_pics, mapping_chain_reversed, StepnNotFound, \
safe_evolution, safe_add_percent, safe_minus_percent, mapping_currency
from stepn_discord import StepnClient
DISCORD_ID = secrets.DISCORD_BOT_ID
DISCORD_TOKEN = secrets.DISCORD_BOT_TOKEN
DISCORD_PUBLIC = secrets.DISCORD_BOT_PUBLIC
STEPN_ACCOUNT = secrets.STEPN_ACCOUNT
STEPN_PASSWORD = secrets.STEPN_PASSWORD
GOOGLE_2AUTH = secrets.GOOGLE_2AUTH
rules_to_check = secrets.RULES
messages_dict = {
"mention": "stepnwatcher",
"messages": [],
}
def main():
stop = False
stepn = StepnRequest(email=STEPN_ACCOUNT, password=STEPN_PASSWORD, google_2auth_secret=GOOGLE_2AUTH)
for item in rules_to_check:
title = item.get("title") if item.get("title") else ''
page = item.get("params").get("page")
limit = item.get("limit", 1000)
price = item.get("price")
threshold = item.get("threshold")
chain = mapping_chain_reversed[item.get('params').get('chain')]
image_enabled = item.get("image_enabled")
nb_matched = 0
while page <= item["page_end"]:
item["params"]["page"] = page
# stop condition
page += 1
rows = stepn.get_orderlist(**item["params"])
rows = rows.get("data") if rows else []
if limit and "conditions_on_stats" not in item:
rows = rows[:limit]
# For every shoe's in dict
for row in rows:
message = ''
image = ''
row = stepn.reduce_item(details=row)
conditions = item.get("conditions")
conditions = stepn.replace_binded_vars(conditions=conditions, row=row)
sell_price = row.get('sellPrice')
if eval(conditions):
price_evolution = safe_evolution(row.get('sellPrice'), price, default=0)
print(price_evolution, threshold)
if (price_evolution and threshold and abs(price_evolution) > threshold) or not price:
image = f"{url_pics}/{row.get('img')}" if image_enabled else None
message = stepn.human_readable_stats(title=title, chain=chain, details=row)
if price:
message += f"\n{price_evolution}% from previous price, new price limit: "
message += f"{sell_price} ${mapping_currency[chain]} (+{safe_add_percent(sell_price, threshold)} ${mapping_currency[chain]}/-{safe_minus_percent(sell_price, threshold)} {mapping_currency[chain]}) ({threshold}%)"
with open(secrets.RATIO_FILENAME, 'w') as f:
new_price = {
"price": row.get('sellPrice'),
"threshold": threshold,
}
json.dump(new_price, f, indent=4)
with open("log.txt", "a") as log_file:
log_file.write(message)
stop = True
if conditions_on_stats := item.get("conditions_on_stats"):
try:
details = stepn.get_orderdata(order_id=row.get('id'))
conditions_on_stats = stepn.replace_detail_binded_vars(
conditions=conditions_on_stats,
row=details
)
message += f" - " + \
f"{stepn.get_orderdata_attrs(details, 'Efficiency') / 10} eff - " + \
f"{stepn.get_orderdata_attrs(details, 'Luck') / 10} luck - " + \
f"{stepn.get_orderdata_attrs(details, 'Comfort') / 10} com - " + \
f"{stepn.get_orderdata_attrs(details, 'Resilience') / 10} res\n"
with open("log.txt", "a") as log_file:
log_file.write(message)
if conditions_on_stats and eval(conditions_on_stats):
log_file.write('MATCHED!')
nb_matched += 1
else:
message = None
image = None
except StepnNotFound:
print(f"Met conditions but order {row.get('id')} is already gone.")
message = None
image = None
if message and (image or not image_enabled):
print(message)
messages_dict["messages"].append((message, image))
# This is for the details limit
if nb_matched >= limit or stop:
page = item["page_end"] + 1
break
if messages_dict["messages"]:
client = StepnClient(messages_dict=messages_dict)
client.run(DISCORD_TOKEN)
if __name__ == '__main__':
main()