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