bukjdrefresh.py
· 1.2 KiB · Python
Raw
import requests
from bs4 import BeautifulSoup as Soup
data = requests.get("http://jd.bukkit.org/dev/apidocs/index-all.html")
soup = Soup(data.text)
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]
# 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)
else:
# Make a new list for this method
methods[method] = [classn]
# Check for duplicate classes. Shouldn't be a problem unless someone's lazy
if not classn.split("/")[-1] in classes:
# And add to the list
classes[classn.split("/")[-1]] = classn
# 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 | data = requests.get("http://jd.bukkit.org/dev/apidocs/index-all.html") |
| 4 | soup = Soup(data.text) |
| 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 | |
| 33 |