-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcookieclicker.py
107 lines (83 loc) · 3.16 KB
/
cookieclicker.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
from http import cookies
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
import keyboard as kb
import time
from dotenv import load_dotenv
import os
load_dotenv()
service = Service(executable_path="chromedriver.exe")
driver = webdriver.Chrome(service = service)
with open("save.txt", "r", encoding='utf-8') as fr:
saveCode = fr.read()
driver.get("https://orteil.dashnet.org/cookieclicker/")
actions = ActionChains(driver)
def selectLanguage():
WebDriverWait(driver, 10).until(
ec.presence_of_element_located((By.ID, "languageSelectHeader"))
)
selectEnglishButton = driver.find_element(By.ID, "langSelect-EN")
selectEnglishButton.click()
def loadSave():
WebDriverWait(driver, 10).until(
ec.presence_of_element_located((By.ID, "prefsButton"))
)
actions.key_down(Keys.CONTROL).send_keys('o').key_up(Keys.CONTROL).perform()
textAreaPrompt = WebDriverWait(driver, 10).until(
ec.presence_of_element_located((By.ID, "textareaPrompt"))
)
textAreaPrompt.send_keys(saveCode + Keys.ENTER)
def clickCookie():
cookie_id = "bigCookie"
WebDriverWait(driver, 10).until(
ec.presence_of_element_located((By.ID, cookie_id))
)
cookie = driver.find_element(By.ID, cookie_id)
while True:
if kb.is_pressed('q'):
break
cookie.click()
cookiesCount = driver.find_element(By.ID, "cookies").text.split(" ")[0]
cookiesCount = int(cookiesCount.replace(",", ""))
unlockedProducts = driver.find_elements(By.CSS_SELECTOR, ".product.unlocked.enabled")
unlockedCrateProducts = driver.find_elements(By.CSS_SELECTOR, ".crate.upgrade.enabled")
unlockedProducts += unlockedCrateProducts
print(len(unlockedProducts))
for product in unlockedProducts:
# productPrice = product.find_element(By.CLASS_NAME, "price").text.replace(",", "")
# if not productPrice.isdigit():
# continue
# productPrice = int(productPrice)
try:
# if cookiesCount >= productPrice:
product.click()
except:
continue
def save():
options = WebDriverWait(driver, 10).until(
ec.presence_of_element_located((By.CLASS_NAME, "subButton"))
)
options.click()
exportSave = WebDriverWait(driver, 10).until(
ec.presence_of_element_located((By.XPATH, "//*[contains(text(), 'Export save')]"))
)
exportSave.click()
textarea = WebDriverWait(driver, 10).until(
ec.presence_of_element_located((By.ID, "textareaPrompt"))
)
with open("save.txt", "w", encoding='utf-8') as fw:
fw.write(textarea.text)
print("Saved")
selectLanguage()
loadSave()
clickCookie()
save()
time.sleep(3)
driver.quit()