-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
162 lines (124 loc) · 5.44 KB
/
main.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import time
from selenium import webdriver
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from selenium.webdriver.chrome.options import Options as ChromeOptions
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.events import EventFiringWebDriver, AbstractEventListener
from selenium.webdriver.common.action_chains import ActionChains
# Listener class to listen to events
class Mylistener(AbstractEventListener):
def before_navigate_to(self, url, driver):
print("before_navigate_to %s" % url)
def after_navigate_to(self, url, driver):
print("after_navigate_to %s" % url)
def before_click(self, element, driver):
print("before_click %s" % element)
def after_click(self, element, driver):
print("after_click %s" % element)
def after_navigate_forward(self, driver):
print("after_navigate_forward")
def before_navigate_forward(self, driver):
print("before_navigate_forward")
def after_navigate_back(self, driver):
print("after_navigate_back")
def before_navigate_back(self, driver):
print("before_navigate_back")
def before_change_value_of(self, element, driver):
print("before_change_value_of")
def after_change_value_of(self, element, driver):
value = element.text
value = int(value.replace(',', ''))
# if value % 7 == 0:
# print(value)
# Driver for Chrome
def createChromeDriver():
options = ChromeOptions()
options.add_argument("--headless")
driver = webdriver.Chrome(options=options)
edriver = EventFiringWebDriver(driver, Mylistener())
edriver.get("https://www.worldometers.info/world-population/")
return edriver
# Driver for Chrome
def createFirefoxDriver():
options = FirefoxOptions()
options.add_argument("--headless")
driver = webdriver.Firefox(options=options)
return driver
# Facebook login
def facebookLogin(driver, email, password):
driver.get("https://www.facebook.com")
emailInput = driver.find_element_by_id("email")
emailInput.send_keys(email)
passwordInput = driver.find_element_by_id("pass")
passwordInput.send_keys(password)
passwordInput.send_keys(Keys.RETURN)
print("Facebook Login Successful")
# Twitter login and tweet
def twitterPost(driver, email, password):
driver.get("https://twitter.com/login")
time.sleep(5)
emailInput = driver.find_element_by_name("session[username_or_email]")
emailInput.send_keys(email)
passwordInput = driver.find_element_by_name("session[password]")
passwordInput.send_keys(password)
passwordInput.send_keys(Keys.RETURN)
time.sleep(5)
tweetBtn = driver.find_element_by_xpath("//a[@aria-label='Tweet']")
tweetBtn.click()
time.sleep(2)
textbox = driver.find_element_by_xpath("//div[@role='textbox']")
textbox.send_keys("My First Tweet")
button = driver.find_element_by_xpath("//div[@data-testid='tweetButton']")
button.click()
# Get World Population
def worldPopulation(edriver):
listener = Mylistener()
# Get Births Today
birth_today = edriver.find_elements_by_xpath("//span[@rel='births_today']")
# listener.after_change_value_of(birth_today[0], edriver)
# print(f"Birth Today : {birth_today[0].text}")
# Get Births this Year
birth_year = edriver.find_elements_by_xpath("//span[@rel='births_this_year']")
listener.after_change_value_of(birth_year[0], edriver)
# print(f"Birth this Year : {birth_year[0].text}")
# Get Deaths Today
death_today = edriver.find_elements_by_xpath("//span[@rel='dth1s_today']")
# listener.after_change_value_of(death_today[0], edriver)
# print(f"Death Today : {death_today[0].text}")
# Get Deaths this Year
death_year = edriver.find_elements_by_xpath("//span[@rel='dth1s_this_year']")
# listener.after_change_value_of(death_year[0], edriver)
# print(f"Death this Year : {death_year[0].text}")
# Get Population Growth Today
population_growth_today = edriver.find_elements_by_xpath("//span[@rel='absolute_growth']")
# listener.after_change_value_of(population_growth_today[0], edriver)
# print(f"Population Growth Today : {population_growth_today[0].text}")
# Get Population Growth this Year
population_growth_year = edriver.find_elements_by_xpath("//span[@rel='absolute_growth_year']")
# listener.after_change_value_of(population_growth_year[0], edriver)
# print(f"Population Growth this Year : {population_growth_year[0].text}")
# for country in edriver.find_elements_by_class_name("t20-country"):
# print(country.text)
def cookieClick(driver):
driver.get("https://orteil.dashnet.org/cookieclicker/")
driver.implicitly_wait(5)
cookie = driver.find_element_by_id("bigCookie")
cookie_count = driver.find_element_by_id("cookies")
items = [driver.find_element_by_id("productPrice" + str(i)) for i in range(1, -1, -1)]
actions = ActionChains(driver)
actions.click(cookie)
for i in range(20):
actions.perform()
count = int(cookie_count.text.split(" ")[0])
for item in items:
value = int(item.text)
if value <= count:
upgrade_actions = ActionChains(driver)
upgrade_actions.move_to_element(item)
upgrade_actions.click()
upgrade_actions.perform()
driver.quit()
if __name__ == '__main__':
driver = createChromeDriver()
while True:
worldPopulation(driver)