Skip to content

Instantly share code, notes, and snippets.

@fsargent
Created May 9, 2024 04:44
Show Gist options
  • Save fsargent/91331d805ff7db051fd6a46687f6729f to your computer and use it in GitHub Desktop.
Save fsargent/91331d805ff7db051fd6a46687f6729f to your computer and use it in GitHub Desktop.
Have mysterious duolingo friends you don't want anymore? Remove them with this script inspired by Travis Shears
[tool.poetry]
name = "remove_duo_friends"
version = "0.1.0"
description = ""
authors = ["Felix Sargent <felix.sargent@gmail.com>"]
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.8"
requests = "^2.31.0"
playwright = "^1.43.0"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
"""
Have mysterious duolingo friends you don't want anymore? Remove them with this script inspired by Travis Shears.
`pip install requests playwright`
first run will tell you to run `playwright install`
"""
import os
import random
from playwright.sync_api import sync_playwright
duolingo_user = "YOUR_PROFILE"
duolingo_pw = ""
def get_random_wait():
return random.randint(1, 2)
def main():
with sync_playwright() as p:
browser = p.chromium.launch(headless=False)
context = browser.new_context()
# Uncomment the following line to enable video recording
# context.tracing.start({"screenshots": True, "snapshots": True})
page = context.new_page()
page.goto("https://www.duolingo.com/?isLoggingIn=true")
page.wait_for_timeout(get_random_wait() * 1000)
page.click('[data-test="have-account"]')
page.fill('[data-test="email-input"]', duolingo_user)
page.fill('[data-test="password-input"]', duolingo_pw)
page.click('[data-test="register-button"]')
page.wait_for_timeout(5000)
while True:
page.goto(f"https://www.duolingo.com/profile/{duolingo_user}/following")
page.wait_for_timeout((get_random_wait()) * 1000)
try:
friend_urls = page.eval_on_selector_all('a.Euydo[data-test="friend-entry"]', 'nodes => nodes.map(n => n.href)')
print(friend_urls)
for url in friend_urls:
page.goto(url)
page.wait_for_timeout((get_random_wait()) * 1000)
page.click('button[data-test="friend-added-button"]')
page.wait_for_timeout(1000)
except Exception as e:
print("Problem retrying:", e)
# Uncomment the following line to stop video recording
# context.tracing.stop({"path": "trace.zip"})
context.close()
browser.close()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment