Repository navigation
Expand file tree
/
Copy pathDay48.py
More file actions
55 lines (40 loc) · 1.65 KB
/
Copy pathDay48.py
File metadata and controls
55 lines (40 loc) · 1.65 KB
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
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
options = webdriver.ChromeOptions()
options.add_experimental_option("detach", True)
driver = webdriver.Chrome(options=options)
print("Day 48 - 100 Days of Code.")
print("Welcome to Cookie Clicker Project.")
driver.get("http://orteil.dashnet.org/experiments/cookie/")
cookie = driver.find_element(by=By.ID, value="cookie")
item_ids = [item.get_attribute("id") for item in driver.find_elements(by=By.CSS_SELECTOR, value="#store div")]
timeout = time.time() + 1
end_time = time.time() + 60
while True:
cookie.click()
if time.time() > timeout:
all_prices = driver.find_elements(by=By.CSS_SELECTOR, value="#store b")
item_prices = []
for price in all_prices:
text = price.text
if "-" in text:
try:
cost = int(text.split("-")[1].strip().replace(__old=",", __new=""))
item_prices.append(cost)
except ValueError:
continue
upgrades = {cost: id_ for cost, id_ in zip(item_prices, item_ids)}
try:
money = int(driver.find_element(by=By.ID, value="money").text.replace(__old=",", __new=""))
except ValueError:
money = 0
affordable = {cost: id_ for cost, id_ in upgrades.items() if money >= cost}
if affordable:
best_upgrade = affordable[max(affordable)]
driver.find_element(By.ID, best_upgrade).click()
timeout = time.time() + 5
if time.time() > end_time:
print(driver.find_element(by=By.ID, value="cps").text.title())
break
driver.quit()