Follow TV Tropes


Python Script for Trope Overdosed

Go To

Dec 20th 2010 at 5:21:11 AM

For those who want a perfectly accurate count on Trope Overdosed, check out this Python script.

To get an accurate number of wicks for works where you have to add up wicks for several pages, you click each of the links for this work. You look at the source code of the HTML page, scroll down, and copy the line that starts with "<div class="wmglead" ><span style="color:chocolate;". (It's often a very long line, because it contains all the wicks, but treat it as a single one.) Copy this line (for each file) into a simple .txt file, and save it when you did this for all the links. Then you open the python script in your editor and change line 3 to the file address, instead of C:to.txt. Afterwards, you simply run the python script and check what it says about individual results. If you don't have a Python environment, you can download all the necessary stuff at ).

And here, the script itself (it's jumbled up here because of the whitespace rules, but in the page source, it appears correct, so copy it from there):

list = [] file = open('C:\\to.txt', 'r') lines = file.readlines() file.close() for line in lines: subList = re.findall(r'href="([^"]+)"', line) for element in subList: list.append(element.lower()) list.sort() print str(len(list)) + " Elements" # sort out WMG, JBM, TT, Tropers for i in range(len(list) - 1, -1, -1): if list[i].startswith("") or list[i].startswith("") or list[i].startswith("") or list[i].startswith(""): list[i:i+1] = [] for i in range(len(list) - 1, -1, -1): if list[i] == list[i-1]: list[i-1:i] = [] print str(len(list)) + " individual Elements"

edited 20th Dec '10 5:22:56 AM by Frank75

Fuhrmann, es kostet dir noch dein Leben
Apr 11th 2013 at 7:46:50 PM


I looked at the web addresses and it included stuff like Troper Tales and It Just Bugs Me, which no longer exist. Plus, I couldn't find phrases like "wmglead" in the HTML source code. Can someone care to update this Python script?

May 15th 2013 at 1:39:35 AM

[up] I've written a new trope-count script.

Unfortunately, TV Tropes doesn't standardize article structure, so it won't always work.


user@host$ ./ Film/MontyPythonAndTheHolyGrail
Film/MontyPythonAndTheHolyGrail: 210 tropes

edited 15th May '13 1:41:47 AM by MechanicalSnail

Add Post

Total posts: 4

How well does it match the trope?

Example of:


Media sources: