Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from bs4 import BeautifulSoup
- import csv
- import json
- def load_id_dict():
- with open('strings.csv', 'r', newline='') as f:
- file_data = csv.reader(f, delimiter=',')
- id_dic = {row[0]: (row[1]) for row in file_data}
- return id_dic
- headers = {
- "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'}
- api = requests.get("https://poe.ninja/api/Data/GetCurrencyOverview?league=Standard")
- api_json = api.json()
- #api_str = json.dumps(api_json, indent=2)
- #print(api_str)
- for key in api_json["lines"]:
- print (key["currencyTypeName"])
- print (key["chaosEquivalent"])
- workingString = ""
- for _, v in load_id_dict().items():
- URL = 'http://poe.trade/search/' + v
- page = requests.get(URL, headers=headers)
- soup = BeautifulSoup(page.content, 'html.parser')
- item_name = soup.findAll("tbody", {"id": "item-container-0"})
- item_prices = soup.findAll("span", {"class": "currency"})
- title = item_name[0]["data-name"]
- prices = []
- for container in item_prices[:5]:
- price = container["title"]
- if "chaos" in price:
- price = price.replace(' chaos', '')
- price = int(price)
- prices.append(price)
- elif():
- for key in api_json["lines"]:
- currency_name = key["currencyTypeName"]
- exchange_rate = key["chaosEquivalent"]
- if currency_name in price:
- print(currency_name, exchange_rate)
- price = int(price)
- prices.append(price)
- avgPrice = sum(prices) / len(prices) if prices else "N/A"
- workingString += f"{title},{avgPrice}\n"
- print(workingString)
- filename = "out.csv"
- with open(filename, "w") as output_file:
- output_file.write(workingString)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement