-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsteam_market_bulk_sell.py
120 lines (90 loc) · 4.53 KB
/
steam_market_bulk_sell.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as ec
from selenium.common.exceptions import TimeoutException
from getpass import getpass
import time
username = input("Enter username: ")
password = getpass()
driver = webdriver.Firefox()
driver.get("https://steamcommunity.com/login/home/?goto=login")
# Wait for website to properly load dynamic content
WebDriverWait(driver, 360).until(
expected_conditions.presence_of_element_located((By.XPATH, "//form[contains(@class, 'LoginForm')]"))
)
username_field = driver.find_element(By.XPATH, "//input[@type='text']")
password_field = driver.find_element(By.XPATH, "//input[@type='password']")
username_field.send_keys(username)
password_field.send_keys(password)
# Un-tick "remember me" field for good measure
remember_me = driver.find_element(By.XPATH, "//div[contains(@tabindex, 0)]")
remember_me.click()
sign_in_field = driver.find_element(By.XPATH, "//button[@type='submit']")
sign_in_field.click()
WebDriverWait(driver, 360).until(
expected_conditions.url_contains("https://steamcommunity.com/id/" or
expected_conditions.url_contains("https://steamcommunity.com/profile/"))
)
inventory_url = driver.current_url + "/inventory/"
driver.get(inventory_url)
WebDriverWait(driver, 360).until(
expected_conditions.url_matches(inventory_url)
)
input("Select item to sell and press enter.")
selected_item = driver.execute_script("return g_ActiveInventory.selectedItem")
print(f'Selected item: {selected_item["description"]["name"]}')
number_to_sell = int(input("Enter number of items to sell: "))
price = input("Enter price of item to sell (what you will receive): ")
# go to start of inventory
while driver.execute_script("return g_ActiveInventory.m_iCurrentPage") != 0:
driver.execute_script("g_ActiveInventory.PreviousPage()")
items_sold = 0
while True:
current_page = driver.execute_script("return g_ActiveInventory.m_iCurrentPage")
active_inventory_page = driver.find_element(By.ID, "active_inventory_page")
ctn = list(filter(lambda x: x.value_of_css_property("display") != "none",
active_inventory_page.find_elements(By.CLASS_NAME, "inventory_ctn")))[0]
inventory_pages = ctn.find_elements(By.CLASS_NAME, "inventory_page")
current_inventory_page = list(filter(lambda x: x.value_of_css_property("display") == "block", inventory_pages))[0]
item_holders = current_inventory_page.find_elements(By.CLASS_NAME, "itemHolder")
continue_on_same_page = False
for holder in item_holders:
if "disabled" in holder.get_attribute("class"):
continue
holder.click()
i = driver.execute_script("return g_ActiveInventory.selectedItem")
if i["classid"] == selected_item["classid"]:
sell_item = i
print("found item on page")
driver.execute_script("SellCurrentSelection()")
subscriber_agreement_checkbox = driver.find_element(By.ID, "market_sell_dialog_accept_ssa")
if not subscriber_agreement_checkbox.is_selected():
subscriber_agreement_checkbox.click()
price_text = driver.find_element(By.ID, "market_sell_currency_input")
price_text.send_keys(price)
sell_accept = driver.find_element(By.ID, "market_sell_dialog_accept")
sell_accept.click()
WebDriverWait(driver, 20).until(ec.element_to_be_clickable((By.ID, "market_sell_dialog_ok"))).click()
try:
WebDriverWait(driver, 5).until(ec.element_to_be_clickable(
(By.XPATH, "//div[@class='btn_grey_steamui btn_medium']/span[text()='OK']"))).click()
except TimeoutException:
print('No additional confirmation needed.')
items_sold += 1
if items_sold == number_to_sell:
driver.close()
print(f"Sold {items_sold} items.")
exit(0)
# sell succeeded
if driver.find_element(By.ID, "market_headertip_itemsold").value_of_css_property("display") != "none":
continue_on_same_page = True
break
# if end of inventory, break
if current_page == driver.execute_script("return g_ActiveInventory.m_cPages") - 1:
print('End of inventory reached')
break
if not continue_on_same_page:
driver.execute_script("g_ActiveInventory.NextPage()")
time.sleep(2)