from tinydb import TinyDB, Query import requests from bs4 import BeautifulSoup from logger import logger # URL of the shop page SHOP_URL = 'https://play.boobylegends.com/market/' # File to save the card data DATA_FILE = 'monitor_market.json' # Initialize TinyDB db = TinyDB(DATA_FILE) def MarketMonitor(session): logger.debug("Market Fetching Data.") response = session.get(SHOP_URL) soup = BeautifulSoup(response.content, 'html.parser') cards = [] container = soup.select_one('.container-buy') # Select the container first for card in container.select('.wrapper-market-card'): # Then select each card within the container card_name = card.select_one('div.titre-card h2').text.strip() card_id = card.select_one('.wrapper-market-card a').get('card-id') level = card.select_one('.wrapper-market-card a').get('level') pornstar_number = int(card.select_one('div.titre-card span.pornstar-number').text.strip()) cost = card.select_one('div.cost span').text.strip() amount = int(card.select_one('div.wrapper-market-card div h6 strong').text.strip()) cards.append({ 'name': card_name, 'ID': card_id, 'level': level, 'number': pornstar_number, 'cost': cost, 'amount': amount }) return cards def update_card_data(cards): for card in cards: db.upsert(card, Query().name == card['name']) def main(): with requests.Session() as session: cards = MarketMonitor(session) update_card_data(cards) logger.debug("Market Data Updated.") if __name__ == "__main__": main()