Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save inavadeep1205/cba483261e502e5af0c734ea262d1c71 to your computer and use it in GitHub Desktop.
Save inavadeep1205/cba483261e502e5af0c734ea262d1c71 to your computer and use it in GitHub Desktop.
Twitter Automation using Python SELENIUM
```python
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
promised_down = 50
promised_up = 25
twitter_email = "YOUR EMIAL"
twitter_password = "YOUR PASSWORD"
class InternetSpeedTwitterBot:
def init(self):
self.go_button = None
self.twitter_link = None
self.email = None
self.next_button = None
self.driver = webdriver.Chrome()
self.up = 0
self.down = 0
def get_internet_speed(self):
self.driver.get("https://www.speedtest.net/")
self.go_button = self.driver.find_element(By.XPATH,
'//*[@id="container"]/div/div[3]/div/div/div/div[2]/div[3]/div[1]/a/span[4]')
self.go_button.click()
time.sleep(55)
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[1]/div/div[2]/span')
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[2]/div/div[2]/span')
print(f"down: {self.up.text}")
print(f"up: {self.down.text}")
def tweet_at_provider(self):
self.driver.get("https://twitter.com/i/flow/login")
time.sleep(3)
self.email = self.driver.find_element(By.XPATH,
'//*[@id="layers"]/div/div/div/div/div/div/div[2]/div[2]/div/div/div[2]/div[2]/div/div/div/div[5]/label/div/div[2]/div/input')
self.email.send_keys(twitter_email)
time.sleep(2)
self.next_button = self.driver.find_element(By.XPATH, '//*[@id="layers"]/div/div/div/div/div/div/div[2]/div[2]/div/div/div[2]/div[2]/div/div/div/div[6]/div/span/span')
self.next_button.click()
time.sleep(2)
#If it asks you to enter phone or username from line 54 to 60
self.phone_or_username = self.driver.find_element(By.XPATH, '//*[@id="layers"]/div/div/div/div/div/div/div[2]/div[2]/div/div/div[2]/div[2]/div[1]/div/div[2]/label/div/div[2]/div/input')
self.phone_or_username.send_keys("9154461978")
time.sleep(2)
self.next = self.driver.find_element(By.XPATH, '//*[@id="layers"]/div/div/div/div/div/div/div[2]/div[2]/div/div/div[2]/div[2]/div[2]/div/div/div/div/div/span/span')
self.next.click()
#It ends here
time.sleep(2)
self.password = self.driver.find_element(By.XPATH, '//*[@id="layers"]/div/div/div/div/div/div/div[2]/div[2]/div/div/div[2]/div[2]/div[1]/div/div/div[3]/div/label/div/div[2]/div[1]/input')
self.password.send_keys(twitter_password)
self.login = self.driver.find_element(By.XPATH, '//*[@id="layers"]/div/div/div/div/div/div/div[2]/div[2]/div/div/div[2]/div[2]/div[2]/div/div[1]/div/div/div/div/span/span')
self.login.click()
time.sleep(5)
self.post = self.driver.find_element(By.XPATH, '//*[@id="react-root"]/div/div/div[2]/header/div/div/div/div[1]/div[3]/a')
self.post.click()
self.tweet = self.driver.find_element(By.XPATH, '//*[@id="layers"]/div[2]/div/div/div/div/div/div[2]/div[2]/div/div/div/div[3]/div[2]/div[1]/div/div/div/div[1]/div[2]/div/div/div/div/div/div/div[2]/div/div/div/div/label/div[1]/div/div/div/div/div/div[2]/div')
self.tweet.send_keys(f"My Internet Sucks")
self.post = self.driver.find_element(By.XPATH, '//*[@id="layers"]/div[2]/div/div/div/div/div/div[2]/div[2]/div/div/div/div[3]/div[2]/div[1]/div/div/div/div[2]/div[2]/div/div/div[2]/div[4]/div/span/span')
self.post.click()
project = InternetSpeedTwitterBot()
project.get_internet_speed()
time.sleep(3)
project.tweet_at_provider()
time.sleep(2)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment