Last active 1451433555

bukjdm Refresh data for new Bukkit snapshot

Revision c6224c031ef89c1aa4d0a17bbc51c763fe98b937

bukjdrefresh.py Raw
1import requests
2from bs4 import BeautifulSoup as Soup
3data = requests.get("http://jd.bukkit.org/dev/apidocs/index-all.html")
4soup = Soup(data.text)
5methods = {}
6classes = {}
7for dt in soup.findAll('dt'):
8 # If more than one link in definition (i.e. a class or method definition)...
9 if len(dt.findAll('a')) > 1:
10 # Get the class name in format "org/bukkit/ab/cd.html"
11 classn = dt.findAll('a')[1]["href"][2:]
12 # Check if this is a method
13 if "(" in dt.find('b').text.split(" ")[0] and dt.find('b').text[0].islower():
14 # Get method name without ()
15 method = dt.find('b').text.split("(")[0].lower()
16 # If a method of this name has been seen before
17 if method in methods:
18 # Add class name with package to list
19 methods[method].append(classn)
20 else:
21 # Make a new list for this method
22 methods[method] = [classn]
23 # Check for duplicate classes. Shouldn't be a problem unless someone's lazy
24 if not classn.split("/")[-1][:-5] in classes:
25 # And add to the list
26 classes[classn.split("/")[-1][:-5]] = classn
27
28# Save data for copying to bukjdm.py
29with open("bukjd.py", "w") as f:
30 f.write("methods = " + str(methods) + "\n\n")
31 f.write("classes = " + str(classes) + "\n\n")
32
33