|
""" |
|
By Mitch Barnett |
|
Discord: Frogman#5072 |
|
""" |
|
from mwclient import Site # pip install mwclient |
|
import re |
|
|
|
|
|
# Wiki category to collect id's from |
|
wiki_category = "Pets" |
|
|
|
|
|
# Wiki URL and path to api.php |
|
site = Site("oldschool.runescape.wiki", path="/") |
|
|
|
|
|
def get_item_ids_from_page(page): |
|
"""Return the item id's found on the given page""" |
|
print("Getting ID(s) for " + page.page_title) |
|
# Regex pattern to find "|id? = ???", "|id? = ???,???,???" "|itemid? = ???" and "|itemid? = ???,???,???" |
|
item_id_regex = r"\|(?:item)?id\d*\s*=\s*(\d+(?:,?\s*\d+)*)" |
|
regex_matches = re.findall(item_id_regex, page.text()) |
|
ids_found = [] |
|
|
|
for match in regex_matches: |
|
match.replace(' ', '') # Remove spaces |
|
match_ids = match.split(',') # Split into single id's |
|
ids_found += match_ids |
|
|
|
if ids_found: |
|
print("Found ID(s): " + str(ids_found) + '\n') |
|
return ids_found |
|
else: |
|
print("No ID found \n") |
|
return ids_found |
|
|
|
|
|
def get_item_ids_from_category(category, checked_pages=None): |
|
"""Return the item id's found in the pages of the given category""" |
|
if checked_pages is None: |
|
checked_pages = [] |
|
item_ids = [] # List of item id's to be populated |
|
page_list = site.categories[category] # Page list to be iterated through |
|
|
|
for page in page_list: |
|
if page.page_title in checked_pages: # Don't check pages multiple times to save time |
|
continue |
|
if page.namespace == 14: # Page is in category namespace |
|
print("Subcategory " + page.page_title) |
|
item_ids += get_item_ids_from_category(page.page_title, checked_pages) # Recurse on the subcategory |
|
checked_pages.append(page.page_title) |
|
else: |
|
item_ids += get_item_ids_from_page(page) |
|
checked_pages.append(page.page_title) |
|
return item_ids |
|
|
|
|
|
item_ids = get_item_ids_from_category(wiki_category) |
|
item_ids = list(set(item_ids)) # Remove duplicates() |
|
item_ids.sort(key=int) |
|
|
|
|
|
import_string = wiki_category + ',' + item_ids[0] + ',' |
|
for item_id in item_ids: |
|
import_string += str(item_id) + ',' |
|
|
|
import_string = import_string[:-1] |
|
|
|
runelite_preview_link = "https://runelite.net/tag/show/" + import_string |
|
|
|
print('\n') |
|
print("Runelite import string:") |
|
print(import_string) |
|
print('\n') |
|
print("Runelite preview link:") |
|
print(runelite_preview_link) |