Cut Out Toxic Friends from Your Life (Using Python)

03 November, 2019 - 5 min read

To live a healthy and happy life, one must cut out all toxic relationships from their life. For people who are deeply flawed and insecure, that means all relationships.

Oscar Wilde said "Most people are other people. Their thoughts are someone else's opinions, their lives a mimicry, their passions a quotation". That's why it is important to distance yourself from people. The only original life is a friendless life.

We, at LetsDevashish Pvt. Ltd., scoured the internet for methods that would help us cut out toxic friends from our life. However, everything we found was archaic and would have required a lot of tedious manual effort. One of our core values at LetsDevashish is "Keep the Entrepreneur Roaring". This means always keep innovating, tinkering, and incorrectly using Selenium. Left with no choice, we decided to build ghostman - an in-house friend-cutting engine. Ghostman automates the process of cutting out toxic relationships from your life. We have open sourced it so you don't have to waste time reinventing the wheel and your start-up can focus on the important things - getting actionable insight from some data.

Check out ghostman in action in the video below!

Case Study

Reading is important. It is one of the few things that makes you appear intelligent at the airport, while also actually making you intelligent at the airport. Most readers use Goodreads to catalogue their reading lists and get book reviews. But because goodreads is also a social media website, it encourages some vanity metrics. Such as -

  • How many books have you read?
  • Have you read X Book?

(X is usually The Subtle Art of Not Giving a Fuck)

Goodreads creates an artificial motivation to force-finish a book so you can increase your read count, or just because it is popular. We, at LetsDevashish, wanted to avoid that all costs. One of our core values at LetsDevashish is "Never Finish a Book".

So it was absolutely prudent to unfriend everyone on Goodreads.

It is incredibly difficult to delete friends on Goodreads (Not emotionally difficult. It just takes a lot of fucking clicks to get there).

One Deletion

The above GIF shows the process of deleting a friend on Goodreads. Doing this once is fine. In fact, thrilling. But repeating it for 180+ friends is a disgusting waste of human life. Goodreads has exposed an unfollow API, but we at LetsDevashish firmly believe that unfollowing is weak. Real men unfriend.

So we wrote a python script with selenium to delete toxic friends (all) from Goodreads. (Fun Fact: The metal Selenium is also toxic)

This snippet logs into goodreads. After logging in, it can directly GET the friends page. Chrome manages the session.

def log_in_to_goodreads(driver, email_id, password):
    sing_in_elem = driver.find_element_by_id('userSignInFormEmail')
    sing_in_elem.send_keys(email_id)
    password_elem = driver.find_element_by_xpath('//*[@id="user_password"]')
    password_elem.send_keys(password)

    sign_in_elem = driver.find_element_by_xpath('//*[@id="sign_in"]/div[3]/input[1]')
    sign_in_elem.click()
    return driver

Logging In

The friends page is sorted by alphabetical order to keep the order consistent on refreshes.

This snippet activates the edit friends mode, deletes a friend and confirms deletion on Chrome’s Pop Up.

def activate_edit_friends(driver):
    edit_friends_elem = driver.find_element_by_id('edit_friends_button')
    edit_friends_elem.click()
    return driver

def execute_deletion(driver,friend_element,is_dry_run):
    print 'Deleted', friend_element.text
    deletion_element = friend_element.find_element_by_xpath("../../div[4]/div/a")
    if is_dry_run is False:
        deletion_element.click()
        time.sleep(5)
        alert_obj = driver.switch_to.alert
        alert_obj.accept()
        is_break = True
    else:
        is_break = False
    return is_break

Auto Deletion

Selenium identifies the delete element by its x-path. The loop runs until no delete element is found in that x-path. At this point, the loop breaks.

The below snippet checks if a friend is toxic

def is_friend_toxic(friend_name):
    return True

We have added a provision to retain some select friends. However, you must specify their exact goodreads name or it won’t work and you will lose them forever.This next snippet checks the name of the friend that is being deleted against the list of friends to retain.

def check_if_friend_in_dnd(friend_name,dnd_list):

    if friend_name in dnd_list:
        return True
    else:
        return False

Currently, we only have support to retain 30 friends. Why? Because LetsDevashish is a product company. We pride ourselves for having domain knowledge. One of our core values at LetsDevashish is "Be a Product Company".

LetsDevashish is hiring. LetsDevashish is an early stage start-up working at the intersection of technology, design and Devashish. Apply on our careers page if you are interested in solving interesting problems and being a part of a thrilling journey that will change the way the world Devashishs.


Share this blog!