· 5 years ago · Jul 24, 2020, 07:34 AM
1import requests
2import json
3import threading
4import configparser
5import time
6import datetime
7import atexit
8
9'''
10 Wersja tego skryptu skupia się jedynie na rynku itemu, który daje największy profit z możliwych
11'''
12
13# ścieżki do API
14loginPathAPI = "https://api.footballteam.pl/auth/login" # logowanie
15logoutPathAPI = "https://footballteam.pl/?logout" # wylogowanie
16userPathAPI = "https://api.footballteam.pl/user" # gracz
17itemsGreenPathAPI = "https://api.footballteam.pl/auctions/items?page=1&dir=ASC&name=&rarity=rare&skill=&sort=auction_price&type=" # zielone itemy
18itemsRedPathAPI = "https://api.footballteam.pl/auctions/items?page=1&dir=ASC&name=&rarity=epic&skill=&sort=auction_price&type=" # czerwone itemy
19itemsGoldPathAPI = "https://api.footballteam.pl/auctions/items?page=1&dir=ASC&name=&rarity=legendary&skill=&sort=auction_price&type=" # złote itemy
20
21# ustawienia
22maxGreen = 40 # cena dla itemów zielonych
23maxBoost = 5 # cena dla boosterów
24maxGP = 14 # cena dla złotych paczek
25maxRed = 200 # cena dla czerwonych itemów
26maxGold = 500 # cena dla złotych
27version = "1.2"
28
29sec = [
30 1,4,7,10,13,16,19,22,25,28,31,34,37,40,43,46,49,52,55,58
31]
32
33# data do POST
34loginDataPOST = {
35 "email" : "",
36 "password" : ""
37}
38
39# zmienne dotyczące użytkownika
40PlayerInfo = { #informacje o graczu
41 "token" : "",
42 "zalogowano" : "",
43 "id" : 0,
44 "wygasa" : 0,
45 "money" : 0,
46 "energy" : 0
47}
48
49# nagłówki
50headerAPI = {
51 "X-Auth-Id" : str(PlayerInfo["id"]),
52 "X-Auth-Token" : PlayerInfo["token"],
53 "User-Agent" : "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Mobile Safari/537.36"
54 }
55
56def refeshHeaderX():
57 headerAPI["X-Auth-Token"] = PlayerInfo["token"]
58 headerAPI["X-Auth-Id"] = str(PlayerInfo["id"])
59
60def cPrint(count, message):
61 if(count < 10):
62 zwroc = "[.."+str(count)+"..] " + message
63 elif(count < 100 and count > 9):
64 zwroc = "[.." + str(count) + ".] " + message
65 elif (count < 1000 and count > 99):
66 zwroc = "[.." + str(count) + "] " + message
67 elif (count < 10000 and count > 999):
68 zwroc = "[." + str(count) + "] " + message
69 else:
70 zwroc = "[" + str(count) + "] " + message
71 return zwroc
72
73# ********** podstawowe czynności **********
74
75def login():
76 h = {
77 "User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Mobile Safari/537.36"
78 }
79 print("[TRY] Próba zalogowania się...")
80 response = requests.post(loginPathAPI, data = loginDataPOST, headers = h)
81 print("Response code: " + str(response.status_code))
82 # print("Response JSON: " + str(response.json()))
83 jsonData = json.loads(response.text)
84 PlayerInfo["token"] = jsonData["token"]
85 PlayerInfo["zalogowano"] = jsonData["info"]
86 PlayerInfo["id"] = jsonData["id"]
87 if(PlayerInfo["zalogowano"] == "Zalogowano"):
88 print("[SUCCESS] Zalogowano na konto ID:" + str(jsonData["id"]))
89 refeshHeaderX()
90
91def logout():
92 print("[TRY] Trwa wylogowywanie...")
93 response = requests.get(logoutPathAPI)
94 if(response == 200):
95 print("[SUCCESS] Wylogowano z konta")
96 else:
97 print("[FAIL] Coś poszło nie tak!")
98
99# ********** LOGI ***********
100def LogUser(Content):
101 file = open("user.txt", "a")
102 file.write("[" + str(datetime.datetime.now()) + "] " + str(Content) + "\n")
103 file.close()
104
105def LogMarket(Content):
106 file = open("market.txt", "a")
107 file.write("[" + str(datetime.datetime.now()) + "] " + str(Content) + "\n")
108 file.close()
109
110# ********** GRACZ **********
111def UpdatePlayerData(): # pobiera informacje o graczu, takie jak pieniądze, energia, kredyty itd.
112 LogUser("Pobieranie informacji o graczu")
113 response = requests.get(userPathAPI, headers=headerAPI)
114 LogUser("Response code: " + str(response.status_code))
115 jsonData = json.loads(response.text)
116 PlayerInfo["money"] = jsonData["user"]["euro"]
117 PlayerInfo["energy"] = jsonData["user"]["energy"]
118
119# ********** MARKET **********
120
121# 1. Wysyła zapytanie i zwraca:
122# 0 - w przypadku niepowodzenia
123# ZWRACANIE
124# DLA GET
125# JSON - w przypadku powodzenia
126# DLA POST
127# Response Code - w przypadku powodzenia
128def Req(Path, type=0, data={}):
129 if(type == 0): # GET
130 try:
131 response = requests.get(Path, headers=headerAPI)
132 jsonData = json.loads(response.text)
133 if (response.status_code == 200):
134 return jsonData
135 else:
136 print("[FAIL] Nie udało się pobrać danych z serwera!")
137 LogMarket("[FAIL] Nie udało się pobrać danych z serwera!")
138 except json.JSONDecodeError as jError:
139 LogMarket(jError.message)
140 print("[FAIL] Błąd przetwarzania JSON!")
141 return 0
142 except requests.RequestException as rq:
143 LogMarket(rq.message)
144 print("[FAIL] Błąd request!")
145 return 0
146 elif(type == 1): # POST
147 try:
148 response = requests.post(Path, data=data, headers=headerAPI)
149 return response.status_code
150 except requests.RequestException as rq:
151 LogMarket(rq.message)
152 print("[FAIL] Błąd request!")
153 return 0
154 elif (type == 2): # PUT
155 try:
156 response = requests.put(Path, data=data, headers=headerAPI)
157 return response.status_code
158 except requests.RequestException as rq:
159 LogMarket(rq.message)
160 print("[FAIL] Błąd request!")
161 return 0
162
163# 2. Kupowanie itemu
164# ZWRACA:
165# 1 w przypadku powodzenia
166# 0 w przypadku błędu
167def BuyItem(type, id, price, name=""):
168 # kupno itemu
169 d = {
170 "item_id": str(id),
171 "price": str(price)
172 }
173 response = Req("https://api.footballteam.pl/auctions/items/", type=1, data=d)
174 if (response != 200):
175 print("[FAIL] Nie udało się kupić itemu | Szczegóły: " + name + " cena: " + str(price) + " ID: " + str(id) + " typ: " + type)
176 LogMarket("[FAIL] Nie udało się kupić itemu! | | Szczegóły: id:" + str(id) + " typ: " + type)
177 return 0
178 else:
179 print("[BUY] Kupiono item! | Szczegóły: " + name + " cena: " + str(price) + " ID: " + str(id) + " typ: " + type)
180 LogMarket("[BUY] Udany zakup ! | Szczegóły: id:" + str(id) + " typ: " + type)
181 return 1
182
183# 3. Wystawianie itemu
184# ZWRACA:
185# 1 w przypadku powodzenia
186# 0 w przypadku błędu
187def ListItem(type, id, price, name=""):
188 d = {
189 "item_id": str(id),
190 "price": str(price)
191 }
192 response = Req("https://api.footballteam.pl/auctions/items", type=2, data=d)
193 if (response != 200):
194 print("[FAIL] Nie udało się wystawić itemu | Szczegóły: " + name + " cena: " + str(price) + " ID: " + str(id) + " typ: " + type)
195 LogMarket("[FAIL] Nie udało się wystawić itemu! | Szczegóły id:" + str(id))
196 return 0
197 else:
198 print("[SUCCESS] Wystawiono item | Szczegóły: " + name + " cena: " + str(price) + " ID: " + str(id) + " typ: " + type)
199 LogMarket("[SUCCESS] Wystawiono item | Szczegóły id:" + str(id))
200 return 1
201
202def getGoldPacks():
203 login()
204 timeStart = time.perf_counter()
205 count = 0
206 while(1):
207 now = datetime.datetime.now()
208 nTime = time.perf_counter()
209 sekunda = now.second
210 if (nTime - timeStart >= 3):
211 roznica = nTime - timeStart
212 timeStart = nTime
213 message = "["+str(sekunda)+"s][" + str(int(round(roznica, 0))) + "s]" + " przeszukuje rynek..."
214 print(cPrint(count,message))
215 jsonData = Req(itemsGreenPathAPI)
216 if(jsonData != 0):
217 for key in jsonData:
218 if(key == "items"):
219 for i in range(len(jsonData[key])):
220 if(jsonData[key][i]["auction_price"] <= maxGreen):
221 print("GR_ITEM(" + str(i) + "):" + jsonData[key][i]["name"] + " cena: " + str(jsonData[key][i]["auction_price"]))
222 LogMarket("GR_ITEM(" + str(i) + "):" + jsonData[key][i]["name"] + " cena: " + str(jsonData[key][i]["auction_price"]))
223 # zakup przedmiotu
224 BuyItem("GR_ITEM", jsonData[key][i]["id"], jsonData[key][i]["auction_price"], name=jsonData[key][i]["name"])
225 # odrazu wystawienie za 110
226 #ListItem("GR_ITEM", jsonData[key][i]["id"], 110, name=jsonData[key][i]["name"])
227
228 jsonData = Req(itemsGoldPathAPI)
229 if (jsonData != 0):
230 for key in jsonData:
231 if(key == "items"):
232 for i in range(len(jsonData[key])):
233 if(jsonData[key][i]["auction_price"] <= maxGold):
234 print("GD_ITEM(" + str(i) + "):" + jsonData[key][i]["name"] + " cena: " + str(jsonData[key][i]["auction_price"]))
235 LogMarket("GD_ITEM(" + str(i) + "):" + jsonData[key][i]["name"] + " cena: " + str(jsonData[key][i]["auction_price"]))
236 # kupno itemu
237 BuyItem("GD_ITEM", jsonData[key][i]["id"], jsonData[key][i]["auction_price"], name=jsonData[key][i]["name"])
238 jsonData = Req(itemsRedPathAPI)
239 if (jsonData != 0):
240 for key in jsonData:
241 if (key == "items"):
242 for i in range(len(jsonData[key])):
243 if (jsonData[key][i]["auction_price"] <= maxRed):
244 print("RED ITEM(" + str(i) + "):" + jsonData[key][i]["name"] + " cena: " + str(jsonData[key][i]["auction_price"]))
245 LogMarket("RED ITEM(" + str(i) + "):" + jsonData[key][i]["name"] + " cena: " + str(jsonData[key][i]["auction_price"]))
246 BuyItem("RD_ITEM", jsonData[key][i]["id"], jsonData[key][i]["auction_price"], name=jsonData[key][i]["name"])
247 count += 1
248 else:
249 continue
250
251print("------------------ | FT Market BOT | ------------------")
252print("[Settings:]")
253print("MaxGreen: " + str(maxGreen))
254print("MaxGold: " + str(maxGold))
255print("MaxRed: " + str(maxRed))
256print("MaxGP: " + str(maxGP))
257print("MaxBoost: " + str(maxBoost))
258print("software version: " + version + " by C39")
259atexit.register(logout)
260while 1:
261 try:
262 #now = datetime.datetime.now()
263 #if((now.hour == 23 and now.minute > 54) or (now.hour == 0 and now.minute < 11)):
264 #continue
265 getGoldPacks()
266 except:
267 print("W aplikacji wystąpił nieoczekiwany wyjątek")
268 logout()
269
270