Skip to content

Instantly share code, notes, and snippets.

@bthallplz
Last active January 29, 2018 08:50
Show Gist options
  • Save bthallplz/593ef2a193bb89b5f9c6 to your computer and use it in GitHub Desktop.
Save bthallplz/593ef2a193bb89b5f9c6 to your computer and use it in GitHub Desktop.
"Unlikr" - modified from Brandon DeRosier's (@bdero) code at http://blog.cheesekeg.com/unlikr-unlike-everything-on-tumblr
#!/usr/bin/env python
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from time import sleep
from sys import argv
find_likes = lambda browser: browser.find_elements_by_css_selector('.post_control.like.liked')
def find_next_page(browser):
try:
return browser.find_element_by_id('next_page_link')
except NoSuchElementException, e:
return None
def login(browser, username, password):
# Login to Tumblr
browser.get('https://www.tumblr.com/login')
e = browser.find_element_by_name('user[email]')
e.send_keys(username)
e = browser.find_element_by_name('user[password]')
e.send_keys(password)
# Original code forgot to submit the form
e.submit()
def unlikr(username, password):
## get the Firefox profile object
firefoxProfile = FirefoxProfile()
## Disable images
firefoxProfile.set_preference('permissions.default.image', 2)
browser = webdriver.Firefox(firefoxProfile)
login(browser, username, password)
# Go to likes page
browser.get('https://www.tumblr.com/likes')
# Destroy those likes!
likes = find_likes(browser)
while True:
for button in likes:
button.click()
# You can technically just floor it, but you might look too much like a robot
sleep(0.1)
browser.get(browser.current_url) # Faster than refreshes
likes = find_likes(browser)
# Every once in a while you have to move to a new page instead of refreshing
# Tumblr seems like kind of a fuck up in this regard
next_page = find_next_page(browser)
while next_page and not likes:
next_page.click()
likes = find_likes(browser)
next_page = find_next_page(browser)
def usage():
print 'usage: unlikr [username] [password]'
def die(code):
usage()
exit(code)
if __name__ == '__main__':
if len(argv) != 3:
die(1)
username, password = argv[1:]
unlikr(username, password)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment