Last active 1451433555

bukjdm Refresh data for new Bukkit snapshot

Revision 02f90b451c2b0071025b2469fe82593da21764a1

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