Follow TV Tropes

Following

Python Script for Trope Overdosed

Go To

Frank75 Since: Jan, 2001
#1: 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 www.python.org ).

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("https://tvtropes.org/pmwiki/pmwiki.php/tropers/") or list[i].startswith("https://tvtropes.org/pmwiki/pmwiki.php/tropertales/") or list[i].startswith("https://tvtropes.org/pmwiki/pmwiki.php/wmg/") or list[i].startswith("https://tvtropes.org/pmwiki/pmwiki.php/justbugsme/"): 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
despoa Since: Aug, 2012
#3: Apr 11th 2013 at 7:46:50 PM

bump

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?

MechanicalSnail Since: May, 2013
#4: 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.

Example:

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

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

Add Post

Total posts: 4
Top