Last active
August 5, 2018 17:29
-
-
Save Zireael-N/30b143a5d53842523ec3317029355e55 to your computer and use it in GitHub Desktop.
Now has its own repository: https://github.com/Zireael-N/bw-locale-generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
import yaml | |
import requests | |
from bs4 import BeautifulSoup | |
localized_names = {} | |
def output(module): | |
for locale, mobs in localized_names.items(): | |
if locale == "enUS": | |
print('local L = mod:GetLocale()') | |
elif locale != "esES": | |
print('local L = BigWigs:NewBossLocale("%s", "%s")' % (module, locale)) | |
else: | |
print('local L = BigWigs:NewBossLocale("%s", "%s") or BigWigs:NewBossLocale("%s", "esMX")' % (module, locale, module)) | |
if locale != "enUS": | |
print('if not L then return end') | |
print('if L then') | |
for shortname, localized_name in mobs.items(): | |
print('\tL.%s = "%s"' % (shortname, localized_name)) | |
print('end\n') | |
return | |
def parse_page(locale, name, mobid): | |
url = 'http://%s.wowhead.com/npc=%d' % (locale[0], mobid) | |
try: | |
response = requests.get(url) | |
if 'notFound' in response.url: | |
print('[%s] No result' % locale) | |
else: | |
soup = BeautifulSoup(response.content, 'html.parser') | |
text = soup.find_all('h1', class_='heading-size-1')[0].get_text() | |
localized_names[locale[1]][name] = text | |
except: | |
print('[%s] Error!' % locale) | |
def go(yamlfile, module): | |
with open(yamlfile, 'r') as stream: | |
try: | |
data = yaml.safe_load(stream) | |
locales = [['www', 'enUS'], ['de', 'deDE'], ['es', 'esES'], ['fr', 'frFR'], ['it', 'itIT'], ['pt', 'ptBR'], ['ru', 'ruRU'], ['ko', 'koKR'], ['cn', 'zhCN']] | |
for locale in locales: | |
localized_names[locale[1]] = {} | |
for name, mobid in data.items(): | |
parse_page(locale, name, mobid) | |
output(module) | |
except yaml.YAMLError as exc: | |
print(exc) | |
if len(sys.argv) != 3: | |
print("usage: ./%s moblist.yaml \"Module Name\"" % sys.argv[0]) | |
sys.exit() | |
go(sys.argv[1], sys.argv[2]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
felguard: 123478 | |
flameweaver: 127233 | |
ravager: 126764 | |
deconix: 127723 | |
clobex: 127732 | |
stalker: 125549 | |
tarneth: 123533 | |
priestess: 128060 | |
aedis: 123680 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wrangler: 100216 | |
stormweaver: 91783 | |
crusher: 91782 | |
oracle: 95861 | |
siltwalker: 91790 | |
tides: 97173 | |
arcanist: 97171 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment