Last active 3 hours ago

tre revised this gist 3 hours ago. Go to revision

No changes

tre revised this gist 4 hours ago. Go to revision

1 file changed, 74 insertions

dw-delete.py(file created)

@@ -0,0 +1,74 @@
1 + from selenium.common import exceptions
2 + from selenium.webdriver.common.by import By
3 + from selenium.webdriver.common.keys import Keys
4 + from selenium import webdriver
5 + import time
6 +
7 + theuser = "USERNAME"
8 + thepass = "PASSWORD"
9 + targets = ["journal1","journal2","journal3","et cetera"] # just the username, no .dreamwidth.org, hyphens not underscores
10 + startyear = 2022 # year the first comments were left
11 +
12 + browser = webdriver.Firefox()
13 + browser.get("https://www.dreamwidth.org/login")
14 +
15 + username = browser.find_element(By.ID,"user")
16 + username.send_keys(theuser)
17 + password = browser.find_element(By.ID,"lj_loginwidget_password")
18 + password.send_keys(thepass)
19 + password.send_keys(Keys.RETURN)
20 + time.sleep(5)
21 +
22 + for target in targets:
23 +
24 + browser.get("https://" + target + ".dreamwidth.org")
25 + time.sleep(3)
26 + firstentry = browser.find_element(By.XPATH,"//h3[contains(@class,'entry-title') and not(contains(@class, 'sticky-entry-title'))]")
27 + firstentry.click()
28 + time.sleep(3)
29 +
30 + date = browser.find_element(By.CLASS_NAME,"datetime")
31 +
32 + try:
33 + while (int(date.text[0:4])) >= startyear:
34 + try:
35 + expand = browser.find_element(By.CLASS_NAME,"expand_all")
36 + expand.click()
37 + time.sleep(5)
38 + except:
39 + pass
40 + try:
41 + deletes = browser.find_elements(By.CLASS_NAME,"delete_comment")
42 + except:
43 + deletes = []
44 + if len(deletes) > 1:
45 + goback = False
46 + else:
47 + goback = True
48 + while len(deletes) > 0:
49 + try:
50 + deletes[0].click()
51 + confirm = browser.find_element(By.CLASS_NAME,"ui-button")
52 + confirm.click()
53 + except:
54 + deletes = []
55 + time.sleep(2)
56 + if goback:
57 + try:
58 + thenext = browser.find_element(By.XPATH,"//li[contains(@class,'page-next') and not(contains(@class, 'disabled'))]")
59 + thenext.click()
60 + except:
61 + backbutton = browser.find_element(By.CLASS_NAME,"link_prev")
62 + backbutton.click()
63 + else:
64 + browser.refresh()
65 + try:
66 + date = browser.find_element(By.CLASS_NAME,"datetime")
67 + except:
68 + date = 0
69 + break
70 + time.sleep(2)
71 + except exceptions.StaleElementReferenceException:
72 + time.sleep(10)
73 +
74 + browser.quit()
Newer Older