1
0

marketMonitor.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from tinydb import TinyDB, Query
  2. import requests
  3. from bs4 import BeautifulSoup
  4. from logger import logger
  5. # URL of the shop page
  6. SHOP_URL = 'https://play.boobylegends.com/market/'
  7. # File to save the card data
  8. DATA_FILE = 'monitor_market.json'
  9. # Initialize TinyDB
  10. db = TinyDB(DATA_FILE)
  11. def MarketMonitor(session):
  12. logger.debug("Market Fetching Data.")
  13. response = session.get(SHOP_URL)
  14. soup = BeautifulSoup(response.content, 'html.parser')
  15. cards = []
  16. container = soup.select_one('.container-buy') # Select the container first
  17. for card in container.select('.wrapper-market-card'): # Then select each card within the container
  18. card_name = card.select_one('div.titre-card h2').text.strip()
  19. card_id = card.select_one('.wrapper-market-card a').get('card-id')
  20. level = card.select_one('.wrapper-market-card a').get('level')
  21. pornstar_number = int(card.select_one('div.titre-card span.pornstar-number').text.strip())
  22. cost = card.select_one('div.cost span').text.strip()
  23. amount = int(card.select_one('div.wrapper-market-card div h6 strong').text.strip())
  24. cards.append({
  25. 'name': card_name,
  26. 'ID': card_id,
  27. 'level': level,
  28. 'number': pornstar_number,
  29. 'cost': cost,
  30. 'amount': amount
  31. })
  32. return cards
  33. def update_card_data(cards):
  34. for card in cards:
  35. db.upsert(card, Query().name == card['name'])
  36. def main():
  37. with requests.Session() as session:
  38. cards = MarketMonitor(session)
  39. update_card_data(cards)
  40. logger.debug("Market Data Updated.")
  41. if __name__ == "__main__":
  42. main()