Skip to content

Instantly share code, notes, and snippets.

@boisei0
Created March 7, 2019 14:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boisei0/830155e9b0be080ab4e59f11cec4565d to your computer and use it in GitHub Desktop.
Save boisei0/830155e9b0be080ab4e59f11cec4565d to your computer and use it in GitHub Desktop.
Find latest chapter you left comments on for an AO3 fic.

Find all comments left by a specific user on a fic on ArchiveOfOurOwn

Setup instructions

  1. Install Python 3; I've used similar code on both 3.6 as well as 3.7.
  2. Install https://github.com/tryolabs/requestium.git
  3. Make sure Chrome is installed, and insert the chromedriver file in the right directory.
  4. Change the necessary configuration on the script
  5. Run the script, preferably on the Python console directly so permission for GDPR can be given manually if relevant (see line 24 of the script)

Additional information

Note that this will only work for finding users with an account, not comments posted without an account.

Step 3

The folder structure should look like this:

Top level directory:

  • drivers:
    • chromedriver_linux64
    • chromedriver_mac64
    • chromedriver_win32.exe
  • find_comments.py

To get the chromedriver files, go to https://chromedriver.storage.googleapis.com/index.html?path=2.46/ and download the zip files, then unpack them in the driver directory.

Step 4

Go to the fic you want to look up info for, click "Entire Work", copy the web address and replace <address to entire work> with it in the configuration. Then, replace <username> by the username you want to search for, case-sensitive. For example, searching for all comments by "centuriesofexistence" on the fic "in love and war and politics" gives the following configuration: fic_address = 'https://archiveofourown.org/works/6277216?view_full_work=true' username = 'centuriesofexistence'

import sys
import os
from requestium import Session, Keys
# Config:
fic_address = '<address to entire work>'
username = '<username>'
if sys.platform.startswith('linux'):
PLATFORM = 'linux'
DRIVER_PATH = os.path.join('drivers', 'chromedriver_linux64')
elif sys.platform.startswith('win32'):
PLATFORM = 'win32'
DRIVER_PATH = os.path.join('drivers', 'chromedriver_win32.exe')
elif sys.platform.startswith('darwin'):
PLATFORM = 'mac'
DRIVER_PATH = os.path.join('drivers', 'chromedriver_mac64')
else:
raise RuntimeError('Platform not supported: {platform}'.format(platform=sys.platform))
s = Session(DRIVER_PATH, 'chrome', 15)
s.driver.get(fic_address)
# If in Europe, go to the browser now and accept the GDPR message
# If relevant, accept the adult rating of the fic too.
occurences = []
while True:
elems = s.driver.find_elements_by_xpath('//div[@id="comments_placeholder"]//h4[@class="heading byline"]/a[text()[contains(.,"{username}")]]/../span[1]'.format(username))
for elem in elems:
occurences.append(elem.text)
try:
s.driver.ensure_element_by_xpath('//div[@id="comments_placeholder"]//li[@class="next"]/a', 'clickable').ensure_click()
except exceptions.TimeoutException:
break
# Do things with occurences, for example occurences[0] is the chapter you first left comments on, occurences[-1] the last.
print('First comment {0}'.format(occurences[0]))
print('Last comment {0}'.format(occurences[-1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment