SHARE
TWEET

Untitled

a guest Dec 12th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import requests
  2. from bs4 import BeautifulSoup
  3. import csv
  4. import json
  5.  
  6. def load_id_dict():
  7.     with open('strings.csv', 'r', newline='') as f:
  8.         file_data = csv.reader(f, delimiter=',')
  9.         id_dic = {row[0]: (row[1]) for row in file_data}
  10.     return id_dic
  11.  
  12. headers = {
  13.     "User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36'}
  14.  
  15. api = requests.get("https://poe.ninja/api/Data/GetCurrencyOverview?league=Standard")
  16. api_json = api.json()
  17. #api_str = json.dumps(api_json, indent=2)
  18. #print(api_str)
  19. for key in api_json["lines"]:
  20.     print (key["currencyTypeName"])
  21.     print (key["chaosEquivalent"])
  22.  
  23. workingString = ""
  24. for _, v in load_id_dict().items():
  25.     URL = 'http://poe.trade/search/' + v
  26.  
  27.     page = requests.get(URL, headers=headers)
  28.     soup = BeautifulSoup(page.content, 'html.parser')
  29.  
  30.     item_name = soup.findAll("tbody", {"id": "item-container-0"})
  31.     item_prices = soup.findAll("span", {"class": "currency"})
  32.  
  33.     title = item_name[0]["data-name"]
  34.  
  35.     prices = []
  36.     for container in item_prices[:5]:
  37.         price = container["title"]
  38.         if "chaos" in price:
  39.             price = price.replace(' chaos', '')
  40.             price = int(price)
  41.             prices.append(price)
  42.         elif():
  43.             for key in api_json["lines"]:
  44.                 currency_name = key["currencyTypeName"]
  45.                 exchange_rate = key["chaosEquivalent"]
  46.                 if currency_name in price:
  47.                     print(currency_name, exchange_rate)
  48.                     price = int(price)
  49.                     prices.append(price)
  50.  
  51.     avgPrice = sum(prices) / len(prices) if prices else "N/A"
  52.  
  53.     workingString += f"{title},{avgPrice}\n"
  54.  
  55. print(workingString)
  56.  
  57. filename = "out.csv"
  58. with open(filename, "w") as output_file:
  59.     output_file.write(workingString)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top