import requests import time import json # CONFIGURATION LEAGUE = "Standard" # PoE2 league name DISCORD_WEBHOOK_URL = "https://discord.com/api/webhooks/1354003262709305364/afkTjeXcu1bfZXsQzFl-QqSb3R1MmQ4hdZhosR3vm4I__QVEyZ0jO9cqndUTQwb1mt5Z" SEARCH_INTERVAL = 300 # 5 minutes in seconds POESESSID = "e6f8684e56b4ceb489b10225222640f4" # Test session ID # Memory to store previously seen listings last_seen_ids = set() # Headers and cookies for authenticated requests HEADERS = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)" } COOKIES = { "POESESSID": POESESSID } # EXAMPLE WISHLIST FILTER for PoE2 query = { "query": { "status": {"option": "online"}, "name": "Taryn's Shiver", "type": "Gelid Staff", "stats": [ { "type": "and", "filters": [ { "id": "skill.freezing_shards", "value": {"min": 10}, "disabled": False }, { "id": "explicit.stat_3291658075", "value": {"min": 100}, "disabled": False } ], "disabled": False } ], "filters": { "req_filters": { "filters": { "lvl": { "max": 40, "min": None } }, "disabled": False }, "trade_filters": { "filters": { "price": { "max": 1, "min": None, "option": None } }, "disabled": True } } } } def search_items(): global last_seen_ids # Step 1: Submit search query response = requests.post(f"https://www.pathofexile.com/api/trade2/search/poe2/{LEAGUE}", json=query, headers=HEADERS, cookies=COOKIES) response.raise_for_status() data = response.json() search_id = data.get("id") result_ids = data.get("result", [])[:10] # Limit to first 10 results if not result_ids: print("No results found.") return new_ids = [item_id for item_id in result_ids if item_id not in last_seen_ids] if not new_ids: print("No new items since last check.") return # Step 2: Fetch item details joined_ids = ",".join(new_ids) fetch_url = f"https://www.pathofexile.com/api/trade2/fetch/{joined_ids}?query={search_id}" details = requests.get(fetch_url, headers=HEADERS, cookies=COOKIES).json() for item in details.get("result", []): item_id = item.get("id") last_seen_ids.add(item_id) item_info = item.get("item", {}) listing = item.get("listing", {}) name = item_info.get("name", "") type_line = item_info.get("typeLine", "") price = listing.get("price", {}).get("amount", "?") currency = listing.get("price", {}).get("currency", "?") account = listing.get("account", {}).get("name", "") whisper = listing.get("whisper", "") icon = item_info.get("icon", "") item_lvl = item_info.get("ilvl", "?") required_lvl = item_info.get("requirements", []) # Requirements formatting req_str = "" for r in required_lvl: if r.get("name") == "Level": req_str += f"Level {r.get('values')[0][0]}" else: req_str += f", {r.get('values')[0][0]} {r.get('name')}" # Extract key stats for display (if available) stats = item_info.get("explicitMods", []) stat_text = "\n".join([f"{s}" for s in stats]) if stats else "No explicit stats." # Construct listing URL listing_url = f"https://www.pathofexile.com/trade2/search/poe2/{LEAGUE}/{search_id}" + f"/item/{item_id}" embed = { "embeds": [ { "author": { "name": f"{name} — {type_line}" }, "title": f"{price} {currency} • Listed by {account}", "url": listing_url, "description": f"**Item Level:** {item_lvl}\n**Requirements:** {req_str}\n\n{stat_text}\n\n**Whisper:**\n`{whisper}`", "thumbnail": {"url": icon}, "color": 7506394, "footer": {"text": "Click the title to view full item details."} } ] } send_to_discord_embed(embed) def send_to_discord_embed(embed_payload): response = requests.post(DISCORD_WEBHOOK_URL, json=embed_payload) if response.status_code == 204: print("Embed sent to Discord.") else: print(f"Failed to send embed: {response.status_code}\n{response.text}") if __name__ == "__main__": while True: print("Searching for wishlist items...") try: search_items() except Exception as e: print(f"Error: {e}") time.sleep(SEARCH_INTERVAL)