Skip to content

Instantly share code, notes, and snippets.

@AEnterprise
Created August 4, 2018 15:54
Show Gist options
  • Save AEnterprise/73695f2d017000ea0956d2313c33501d to your computer and use it in GitHub Desktop.
Save AEnterprise/73695f2d017000ea0956d2313c33501d to your computer and use it in GitHub Desktop.
async def update():
await GearbotLogging.logToBotlog(f"{Emoji.get_chat_emoji('REFRESH')} Updating translations")
project_key = Configuration.getMasterConfigVar("CROWDIN_KEY")
session: aiohttp.ClientSession = bot.aiosession
async with session.get(f"https://api.crowdin.com/api/project/Gearbot/export?key={project_key}&json",) as reply:
if reply.status is not 200:
await GearbotLogging.logToBotlog(f"{Emoji.get_chat_emoji('WARNING')} Crowdin api error, got response code {reply.status}")
else:
response = await reply.json()
if response["success"]["status"] == "built":
async with session.get(
f"https://api.crowdin.com/api/project/Gearbot/download/all.zip?key={project_key}") as reply:
data = await reply.read()
with open("zip.zip", "wb") as file:
file.write(data)
with zipfile.ZipFile("zip.zip", "r") as archive:
if os.path.isdir("temp"):
os.remove("temp")
os.mkdir("temp")
archive.extractall("temp")
for entry in archive.filelist:
if not entry.filename.endswith(".json"):
continue
filename =entry.filename[-10:]
print(f"Processing {filename}")
if os.path.isfile("lang/{filename}"):
os.remove("lang/{filename}")
os.rename(f"temp/{entry.filename}", f"lang/{filename}")
os.remove("temp")
load_translations()
await GearbotLogging.logToBotlog(f"{Emoji.get_chat_emoji('YES')} Translations have been updated")
else:
await GearbotLogging.logToBotlog(f"{Emoji.get_chat_emoji('WARNING')} Crowdin build status was `{response['success']['status']}`, no translation update required")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment