Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Commit

Permalink
fetch and apply revised zhtext from cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
violarulan committed Nov 8, 2017
1 parent 67b93b5 commit a2b2766
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Chinese Patch on EVE Online https://zhpatch.evemodx.com/

Author: [Wangym5106](https://github.com/wangym5106)
Author: [Wangym5106](https://github.com/wangym5106), [ybai](https://github.com/violarulan)

LICENSE: GPLv3

Expand Down
35 changes: 32 additions & 3 deletions zhPatch.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Version: 20170805
# Website: http://zhpatch.evemodx.com/
# Version: 20171108
# Website: https://zhpatch.evemodx.com/
# QQ Group Number: 494245573

import blue
import localization
import localization.internalUtil
import localization.localizationBase
Expand Down Expand Up @@ -33,6 +34,34 @@ def wrapper(self, messageID, languageID=None, **kwargs):
localization._ReadLocalizationLanguagePickles = localization.LOCALIZATION_REF._ReadLocalizationLanguagePickles
localization.GetByMessageID = localization.LOCALIZATION_REF.GetByMessageID

def patch_zhtext():
def load_text():
import requests
try:
headers = {
'User-Agent': 'requests/zhpatch'
}
data = requests.get(r'https://nosni.lodestone.zhpatch.evemodx.com/api/all', headers=headers).json()
if data['status'] != 200:
raise Exception('Patch error', 'API server not responding correct data')
return None
return data['data']
except:
return None

def _LoadPickleData_decorator(func):
# zhtext_revised = load_text() # ERROR: local variable 'data' referenced before assaignment
def wrapper(self, pickleName, dataType):
ret = func(self, pickleName, dataType)
if 'zh' in pickleName:
zhtext_revised = load_text()
if zhtext_revised:
for messageID, text_revised in zhtext_revised.items():
ret[1][int(messageID)] = (text_revised, None, None)
return ret
return wrapper

localization.localizationBase.Localization._LoadPickleData = _LoadPickleData_decorator(localization.localizationBase.Localization._LoadPickleData)

def patch_font():
from carbonui import languageConst, fontconst
Expand All @@ -41,7 +70,7 @@ def patch_font():
except:
pass


patch_zhtext()
patch_localization()
patch_font()

Expand Down

0 comments on commit a2b2766

Please sign in to comment.