-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from selenium import webdriver | ||
import time | ||
|
||
class SpeedCheck: | ||
|
||
def __init__(self): | ||
self.driver = webdriver.Chrome(executable_path="_YOUR_DRIVER_PATH_") | ||
self.webpage = "https://www.speedtest.net/" | ||
|
||
|
||
def get_speed(self): | ||
self.driver.get(self.webpage) | ||
print(">>> webpage loaded") | ||
|
||
time.sleep(2) | ||
go_button = self.driver.find_element_by_class_name("start-text") | ||
go_button.click() | ||
|
||
print(">>> scan begun") | ||
print("wait...") | ||
time.sleep(60) | ||
print(">>> scan complete") | ||
time.sleep(2) | ||
|
||
|
||
def download_speed(self): | ||
print(">>> getting download") | ||
download_check = self.driver.find_element_by_css_selector( | ||
"#container > div > div.main-content > div > div > div > " | ||
"div.pure-u-custom-speedtest > " | ||
"div.speedtest-container.main-row > div.main-view > div > " | ||
"div.result-area.result-area-test > div > div > " | ||
"div.result-container-speed.result-container-speed-active " | ||
"> div.result-container-data > " | ||
"div.result-item-container.result-item-container-align" | ||
"-center > div > div.result-data.u-align-left > span") | ||
download_result = download_check.text | ||
print(f'{download_result}Mbps') | ||
return download_result | ||
|
||
|
||
|
||
def upload_speed(self): | ||
time.sleep(1) | ||
print(">>> getting upload") | ||
upload_check = self.driver.find_element_by_css_selector( | ||
"#container > div > div.main-content > div > div > div > " | ||
"div.pure-u-custom-speedtest > " | ||
"div.speedtest-container.main-row > div.main-view > div > " | ||
"div.result-area.result-area-test > div > div > " | ||
"div.result-container-speed.result-container-speed-active > " | ||
"div.result-container-data > " | ||
"div.result-item-container.result-item-container-align-left " | ||
"> div > div.result-data.u-align-left > span") | ||
upload_result = upload_check.text | ||
print(f'{upload_result}Mbps') | ||
return upload_result | ||
|
||
|
||
def quit(self): | ||
self.driver.quit() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from check_internet_speed import SpeedCheck | ||
from twitter_bot import TwitterBot | ||
import time | ||
|
||
check_internet_speed = SpeedCheck() | ||
check_internet_speed.get_speed() | ||
|
||
# runs the speed test | ||
upload_speed = float(check_internet_speed.upload_speed()) | ||
# assigns variables for condition and f-strings | ||
download_speed = float(check_internet_speed.download_speed()) | ||
check_internet_speed.quit() | ||
|
||
print(">>> checking msg_condition") | ||
if download_speed < 100.00: # change to match the guaranteed terms of your isp | ||
time.sleep(1) | ||
print(">>> main.preparing msg") | ||
twitter = TwitterBot() | ||
twitter.sign_in() | ||
time.sleep(1) | ||
message = f"♪┏(・o・)┛♪ UPLOAD SPEED: {upload_speed}\n┗ ( ・o・) ┓♪ DOWNLOAD SPEED: {download_speed}" | ||
twitter.tweet(message) | ||
print(">>> main.message sent") | ||
twitter.quit() # comment out to keep window open at the end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from selenium import webdriver | ||
from selenium.webdriver.common.keys import Keys | ||
import time | ||
|
||
class TwitterBot: | ||
|
||
def __init__(self): | ||
self.driver = webdriver.Chrome(executable_path="_YOUR_DRIVER_PATH_") | ||
self.username = "_TWITTER_USER_NAME_GOES_HERE_" | ||
self.password = "_TWITTER_PASSWORD_GOES_HERE_" | ||
self.webpage = "https://twitter.com/home" | ||
|
||
def sign_in(self): | ||
self.driver.get(self.webpage) | ||
print("connected to Twitter") | ||
time.sleep(1) | ||
print(">>> attempt to log in") | ||
time.sleep(1) | ||
print(">>> user input") | ||
time.sleep(1) | ||
user_input = self.driver.find_element_by_css_selector( | ||
"#react-root > div > div > div.css-1dbjc4n.r-13qz1uu.r-417010 > main > div > div > " | ||
"div.css-1dbjc4n.r-13qz1uu > " | ||
"form > div > div:nth-child(6) > label > div > " | ||
"div.css-1dbjc4n.r-18u37iz.r-16y2uox.r-1wbh5a2.r-1udh08x.r-1inuy60.r-ou255f.r-vmopo1 > div > input") | ||
user_input.send_keys(self.username) | ||
print(">>> user entered") | ||
time.sleep(1) | ||
print(">>> password input") | ||
time.sleep(1) | ||
user_pass = 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') | ||
user_pass.send_keys(self.password) | ||
print(">>> password entered") | ||
time.sleep(1) | ||
user_pass.send_keys(Keys.ENTER) | ||
print("wait...") | ||
time.sleep(5) | ||
|
||
print(">>> log in successful") | ||
|
||
def tweet(self, message): | ||
print(">>> compose tweet") | ||
compose_tweet = 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''') | ||
print(">>> bot.preparing msg") | ||
compose_tweet.send_keys(message) | ||
|
||
print(">>> click tweet") | ||
time.sleep(2) | ||
tweet_btn = 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_btn.click() | ||
print(">>> bot.message sent") | ||
|
||
def quit(self): | ||
self.driver.quit() |