-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
61 lines (52 loc) · 2.93 KB
/
main.py
File metadata and controls
61 lines (52 loc) · 2.93 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
56
57
58
59
60
61
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
PROMISED_DOWN = 150
PROMISED_UP = 10
TWITTER_EMAIL = "Client's Twitter Email"
TWITTER_PASSWORD = "Client's Twitter Password"
class InternetSpeedTwitterBot:
def __init__(self):
self.up = 0
self.down = 0
self.options = Options()
self.service = Service()
self.driver = webdriver.Chrome(service=Service(ChromeDriverManager().install(), options=Options))
#This grabs the speedtest homepage and clicks on the go button
def get_internet_speed(self):
self.driver.get("https://www.speedtest.net/")
# accept_button = self.driver.find_element_by_id("_evidon-banner-acceptbutton")
# accept_button.click()
# time.sleep(3)
go_button = self.driver.find_element(By.CSS_SELECTOR ,".start-button a")
go_button.click()
time.sleep(60)
self.up = self.driver.find_element(By.XPATH,'//*[@id="container"]/div/div[3]/div/div/div/div[2]/div[3]/div[3]/div/div[3]/div/div/div[2]/div[1]/div[2]/div/div[2]/span').text
self.down = self.driver.find_element(By.XPATH,'//*[@id="container"]/div/div[3]/div/div/div/div[2]/div[3]/div[3]/div/div[3]/div/div/div[2]/div[1]/div[3]/div/div[2]/span').text
#This block of code logs in to twitter, make a tweet.
def tweet_at_provider(self):
self.driver.get("https://twitter.com/login")
time.sleep(2)
email = self.driver.find_element(By.XPATH, '//*[@id="react-root"]/div/div/div[2]/main/div/div/div[1]/form/div/div[1]/label/div/div[2]/div/input')
password = self.driver.find_element(By.XPATH, '//*[@id="react-root"]/div/div/div[2]/main/div/div/div[1]/form/div/div[2]/label/div/div[2]/div/input')
email.send_keys(TWITTER_EMAIL)
password.send_keys(TWITTER_PASSWORD)
time.sleep(2)
password.send_keys(Keys.ENTER)
time.sleep(5)
tweet_compose = self.driver.find_element(By.XPATH, '//*[@id="react-root"]/div/div/div[2]/main/div/div/div/div/div/div[2]/div/div[2]/div[1]/div/div/div/div[2]/div[1]/div/div/div/div/div/div/div/div/div/div[1]/div/div/div/div[2]/div/div/div/div')
tweet = f"Hey Internet Provider, why is my internet speed {self.down}down/{self.up}up when I pay for {PROMISED_DOWN}down/{PROMISED_UP}up?"
tweet_compose.send_keys(tweet)
time.sleep(3)
tweet_button = self.driver.find_element(By.XPATH, '//*[@id="react-root"]/div/div/div[2]/main/div/div/div/div/div/div[2]/div/div[2]/div[1]/div/div/div/div[2]/div[4]/div/div/div[2]/div[3]')
tweet_button.click()
time.sleep(2)
self.driver.quit()
bot = InternetSpeedTwitterBot()
bot.get_internet_speed()
bot.tweet_at_provider()