diff --git a/api/buff/api.py b/api/buff/api.py index 0539aee..36759cb 100644 --- a/api/buff/api.py +++ b/api/buff/api.py @@ -46,12 +46,11 @@ def get_best_offer_for_item_list(self, names: List[str]) -> List[Item]: def create_cookies(self): # TODO: Replace with custom loading cookies since these need to be replaced regularly return { - "Device-Id": "ZXeO6pQgFmJ2w1aryQf7", + 'Device-Id': 'l40vB6x92paqjkhfYVqc', 'Locale-Supported': 'en', + 'session': '1-1xRYWCTSO4oCdoh_2Iux2L9n7Ymajsniy8CTzgIhM31c2032647117', 'game': 'csgo', - 'session': '1-hUgTR7Fip4NKzLmvl-GbdCehT4T6_3SQBb5CJs1IPqzZ2032647117', - 'client_id': 'xgl9XGnPqh1x7-gdtmaxGg', - 'display_appids': '"[730\\054 570]"' + 'csrf_token': 'ImZiZWUxY2I0ZDkyZTU5ZGYzMmY3N2U2ZTkwZjY0YjE1NWI4Y2U1Yzgi.F0to5A.ej3puC3GTHTOHNXGAIfus7L7wnU', } def get_items_from_buff(self, item: Item): @@ -112,6 +111,44 @@ def delete_buy_offer(self, buy_offer_id: str): def get_buy_offers(self): raise NotImplemented() + def accept_sell_offer(self): + headers = { + 'Accept': 'application/json, text/javascript, */*; q=0.01', + 'Accept-Language': 'de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7,uk;q=0.6,af;q=0.5', + 'Cache-Control': 'no-cache', + 'Connection': 'keep-alive', + # 'Cookie': 'Device-Id=l40vB6x92paqjkhfYVqc; Locale-Supported=en; session=1-1xRYWCTSO4oCdoh_2Iux2L9n7Ymajsniy8CTzgIhM31c2032647117; game=csgo; csrf_token=ImZiZWUxY2I0ZDkyZTU5ZGYzMmY3N2U2ZTkwZjY0YjE1NWI4Y2U1Yzgi.F0tooA.69xp-N3PpOFuGTOMyRd_lOs7InY', + 'Pragma': 'no-cache', + 'Referer': 'https://buff.163.com/market/sell_order/to_deliver?game=csgo', + 'Sec-Fetch-Dest': 'empty', + 'Sec-Fetch-Mode': 'cors', + 'Sec-Fetch-Site': 'same-origin', + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36', + 'X-Requested-With': 'XMLHttpRequest', + 'sec-ch-ua': '"Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"', + 'sec-ch-ua-mobile': '?0', + 'sec-ch-ua-platform': '"Windows"', + } + params = { + '_': str(int(time.time() * 1000)), + } + response = requests.get('https://buff.163.com/api/market/steam_trade', params=params, cookies=self.create_cookies(), + headers=headers).json() + dataBody = [] + for x in response['data']: + assetList = [] + for y in x['items_to_trade']: + assetList.append(y['assetid']) + goodsID = x['items_to_trade'][0]['goods_id'] + #ToDo Here TradeOffer akzeptieren + print("Offer here: https://steamcommunity.com/tradeoffer/" + str(x['tradeofferid'])) + keys = ["tradeofferid", "Item", "amount", 'assets', "status"] + values = [x['tradeofferid'], x['goods_infos'][str(goodsID)]['market_hash_name'], len(x['items_to_trade']), + assetList, "offer accepted - check if trade succeed"] + dataBody.append(dict(zip(keys, values))) + + return dataBody + def get_closed_buy_offers(self): raise NotImplemented() diff --git a/database/handler/updateTargets.py b/database/handler/updateTargets.py index 04d0948..c07ac69 100644 --- a/database/handler/updateTargets.py +++ b/database/handler/updateTargets.py @@ -2,7 +2,7 @@ from api.marketplace import Item from api.dMarket import api as dMarketApi -from database.createDatabase import csgo_cur +from database.createDatabase import csgo_cur, csgoDB last_offer_id: str @@ -14,10 +14,8 @@ def update_buy_offers(): time1 = round(time.time(), 1) for buy_offer in closed_buy_offers: t = csgo_cur.execute( - 'SELECT COUNT(*) FROM buy WHERE buy_id_3p ="' + buy_offer.asset_id + '"').fetchone()[0] - + 'SELECT COUNT(*) FROM buy WHERE buy_id_3p ="' + buy_offer.offer_id + '"').fetchone()[0] if t == 0: - print(buy_offer.name) def_index = \ csgo_cur.execute('SELECT def_index FROM item_basis WHERE itemName="' + buy_offer.name + '"').fetchone()[0] print(def_index) @@ -29,3 +27,4 @@ def update_buy_offers(): csgo_cur.execute('INSERT INTO buy VALUES (?,NULL,?,?,?,?)', (internal_id, buy_offer.offer_id, buy_offer.price, buy_offer.on_market.name, time1)) + csgoDB.commit() diff --git a/main.py b/main.py index 459ab99..5397255 100644 --- a/main.py +++ b/main.py @@ -6,12 +6,10 @@ def main(): - # Create database if not available or if env is set - if (not os.path.isfile("CSGO.db")) or (bool(os.getenv('DATABASE_RESET'))): + if (not os.path.isfile("CSGO.db")) or (os.getenv('DATABASE_RESET') == 'true'): print("Created new Database") createDatabase.createDatabase() - update_buy_offers() if __name__ == '__main__':