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