PoEPriceGuess

Game Rules: You will be shown a random item for sale on PoE Trade. You have to guess whether the next item's price is "Higher" or "Lower" than the previous item's price. You'll accumulate points based on correct guesses. The game continues until you make an incorrect guess or choose to quit.
mail@pastecode.io avatar
unknown
plain_text
a year ago
2.0 kB
7
Indexable
Never
import requests
from bs4 import BeautifulSoup
import random

# Function to get a random item from PoE Trade in the current league
def get_random_poe_item():
    # PoE Trade URL for the current league (Ancestor)
    url = "https://www.pathofexile.com/trade/search/Ancestor"

    # Send an HTTP GET request
    response = requests.get(url)

    # Parse the HTML content of the page
    soup = BeautifulSoup(response.text, 'html.parser')

    # Extract item names and prices (you may need to modify this based on the website structure)
    item_names = [item.text.strip() for item in soup.find_all('div', class_='item-cell-name')]
    item_prices = [item.text.strip() for item in soup.find_all('div', class_='item-cell-price')]

    # Create a list of (item_name, item_price) pairs
    items = list(zip(item_names, item_prices))

    # Return a random item
    return random.choice(items)

# Main game loop
def play_higher_lower_game():
    score = 0
    prev_item = get_random_poe_item()
    
    while True:
        print(f"Current Item: {prev_item[0]} - Price: {prev_item[1]}")
        
        user_choice = input("Will the next item's price be 'Higher' or 'Lower'? ").lower()
        
        # Get the next random item
        next_item = get_random_poe_item()
        
        # Compare prices and update the score
        if next_item[1] > prev_item[1]:
            result = "Higher"
        elif next_item[1] < prev_item[1]:
            result = "Lower"
        else:
            result = "Same"
        
        if user_choice == result:
            score += 1
            print(f"Correct! Score: {score}")
        else:
            print(f"Incorrect! Your final score is: {score}")
            break
        
        prev_item = next_item

if __name__ == "__main__":
    print("Welcome to the Path of Exile 'Higher or Lower' Game in the Ancestor League!")
    print("Try to guess whether the next item's price is Higher or Lower.")
    play_higher_lower_game()