Skip to content

Instantly share code, notes, and snippets.

@onurvarol
Last active August 22, 2017 02:35
Show Gist options
  • Save onurvarol/d0b09fe8cb38c5aa9919cfd46ab954a9 to your computer and use it in GitHub Desktop.
Save onurvarol/d0b09fe8cb38c5aa9919cfd46ab954a9 to your computer and use it in GitHub Desktop.
Delete Twitter's application keys to clean profile
import os, sys
import json
import uuid
import urllib2
from selenium.webdriver import Firefox#, PhantomJS
import selenium as sl
LIST_APP_PAGE = 'https://apps.twitter.com/app'
LOGIN_BEFORE_APP_PAGE = 'https://twitter.com/login?redirect_after_login=https%3A/apps.twitter.com/app'
def fill_login_page(driver, username, password):
driver.get(LOGIN_BEFORE_APP_PAGE)
driver.implicitly_wait(2)
driver.find_element_by_xpath('//*[@id="page-container"]/div/div[1]/form/fieldset/div[1]/input').send_keys(username)
driver.implicitly_wait(2)
driver.find_element_by_xpath('//*[@id="page-container"]/div/div[1]/form/fieldset/div[2]/input').send_keys(password)
driver.implicitly_wait(2)
# Second attemp needed because of some message box. Can be commented out if it works in single attempt
driver.find_element_by_xpath('//*[@id="page-container"]/div/div[1]/form/fieldset/div[2]/input').send_keys(password)
driver.find_element_by_xpath('//*[@id="page-container"]/div/div[1]/form/div[2]/button').click()
return True
def delete_application_key(driver):
driver.get(LIST_APP_PAGE)
# Click top link
driver.find_element_by_xpath('//*[@id="gaz-content-body"]/div[3]/div/ul/li[1]/div/div[2]/h2/a').click()
driver.implicitly_wait(2)
# Click delete button
driver.find_element_by_xpath('//*[@id="gaz-content-body"]/div[3]/div/fieldset/div/a').click()
driver.implicitly_wait(2)
# Confirm deletion
driver.find_element_by_xpath('//*[@id="edit-submit-delete"]').click()
driver.implicitly_wait(3)
# Reload page
driver.find_element_by_xpath('//*[@id="messages"]/div/a').click()
driver.implicitly_wait(5)
# Confirm deletion again
driver.find_element_by_xpath('//*[@id="edit-submit-delete"]').click()
if __name__ == '__main__':
NLIMIT = 100
MAX_TRY = 500
# If you have more than one account
credentials = [('username1', 'password1'),
('username2', 'password2')]
kCount, eCount = 0, 0
for cr in credentials:
driver = Firefox()
print('Login with', cr[0])
loginState = fill_login_page(driver, cr[0], cr[1])
if loginState:
count = 0
while count < MAX_TRY:
try:
# Delete the top application
delete_application_key(driver)
kCount += 1
except:
eCount += 1
count += 1
if eCount == NLIMIT:
break
driver.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment