-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_market_urls.py
46 lines (37 loc) · 1.72 KB
/
generate_market_urls.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from bs4 import BeautifulSoup
import pandas as pd
STRANGE_PATH_STRING = "https://steamcommunity.com/market/listings/440/Strange%20"
KILLSTREAK_PREFIX_STRING = "Killstreak%20"
RENDER_PATH_STRING = "/render"
QUERY_STRING_SEPARATOR = "?"
HALLOWEEN_SPELL_QUERY_STRING = "&filter=halloween+spell"
ITEM_COUNT_QUERY_STRING = "&count=100"
CURRENCY_QUERY_STRING = "¤cy=1"
def generate_spelled_items_urls(spelled_items_names, get_api_results: bool):
spelled_items_urls = []
for item in spelled_items_names:
item = item.replace(' ', "%20")
if get_api_results:
spelled_items_urls.append(
STRANGE_PATH_STRING + item + RENDER_PATH_STRING + QUERY_STRING_SEPARATOR +
HALLOWEEN_SPELL_QUERY_STRING + ITEM_COUNT_QUERY_STRING + CURRENCY_QUERY_STRING
)
else:
spelled_items_urls.append(
STRANGE_PATH_STRING + item + QUERY_STRING_SEPARATOR +
HALLOWEEN_SPELL_QUERY_STRING + ITEM_COUNT_QUERY_STRING
)
data = {"Item URL": spelled_items_urls}
df = pd.DataFrame(data)
df.to_csv("spelled_item_urls.csv", index=False)
# if get_api_results is true, we get spelled item data from api
# if not, we will scrape the data using beautiful soup
def generate_market_urls(get_api_results: bool):
soup = BeautifulSoup(open("spelled_item_pricelist.html"), 'html.parser')
spelled_items_table = soup.find_all("div", class_="subSectionTitle")
spelled_items_names = []
for entry in spelled_items_table:
if "✔️" in entry.text:
new_entry = entry.text.replace('✔️', '')
spelled_items_names.append(new_entry.strip())
generate_spelled_items_urls(spelled_items_names, get_api_results)