|
2 | 2 | get_location_bundle.py |
3 | 3 | Script to illustrate the basic usage of the swgoh_comlink wrapper library |
4 | 4 | """ |
| 5 | + |
5 | 6 | # import the SwgohComlink class from the swgoh_comlink module |
6 | | -from swgoh_comlink import SwgohComlink |
7 | 7 | import base64 |
8 | | -import zipfile |
9 | 8 | import io |
| 9 | +import zipfile |
| 10 | + |
| 11 | +from swgoh_comlink import SwgohComlink |
10 | 12 |
|
11 | 13 | # create an instance of a SwgohComlink object |
12 | 14 | comlink = SwgohComlink() |
|
20 | 22 | # Get the language bundle using the latest game data language version |
21 | 23 | # By default, Comlink compresses the data and encodes it into a BASE64 string for smaller payload and faster delivery. |
22 | 24 | # The result is a string value that must be decoded before using. |
23 | | -location_bundle = comlink.get_localization_bundle(localization_id=game_data_versions['language']) |
| 25 | +location_bundle = comlink.get_localization_bundle(localization_id=game_data_versions["language"]) |
24 | 26 |
|
25 | 27 | # Decode the Base64 result |
26 | | -loc_bundle_decoded = base64.b64decode(location_bundle['localizationBundle']) |
| 28 | +loc_bundle_decoded = base64.b64decode(location_bundle["localizationBundle"]) |
27 | 29 |
|
28 | 30 | # Create a zipfile object to access the compressed content |
29 | 31 | zip_obj = zipfile.ZipFile(io.BytesIO(loc_bundle_decoded)) |
|
32 | 34 | """ |
33 | 35 | Sample output: |
34 | 36 |
|
35 | | -['Loc_CHS_CN.txt', 'Loc_CHT_CN.txt', 'Loc_ENG_US.txt', 'Loc_FRE_FR.txt', 'Loc_GER_DE.txt', 'Loc_IND_ID.txt', |
36 | | - 'Loc_ITA_IT.txt', 'Loc_JPN_JP.txt', 'Loc_Key_Mapping.txt', 'Loc_KOR_KR.txt', 'Loc_POR_BR.txt', 'Loc_RUS_RU.txt', |
| 37 | +['Loc_CHS_CN.txt', 'Loc_CHT_CN.txt', 'Loc_ENG_US.txt', 'Loc_FRE_FR.txt', 'Loc_GER_DE.txt', 'Loc_IND_ID.txt', |
| 38 | + 'Loc_ITA_IT.txt', 'Loc_JPN_JP.txt', 'Loc_Key_Mapping.txt', 'Loc_KOR_KR.txt', 'Loc_POR_BR.txt', 'Loc_RUS_RU.txt', |
37 | 39 | 'Loc_SPA_XM.txt', 'Loc_THA_TH.txt', 'Loc_TUR_TR.txt'] |
38 | 40 |
|
39 | 41 | """ |
|
43 | 45 | # You could also use the various other zipfile methods to extra all files to disk |
44 | 46 | # (see https://docs.python.org/3/library/zipfile.html for more details), or loop through the namelist() |
45 | 47 | # output and select only specific languages you are interested in. |
46 | | -eng_obj = zip_obj.read('Loc_ENG_US.txt') |
| 48 | +eng_obj = zip_obj.read("Loc_ENG_US.txt") |
47 | 49 |
|
48 | 50 | # Decode to string then split into individual lines |
49 | | -eng_obj_decoded = eng_obj.decode('utf-8') |
| 51 | +eng_obj_decoded = eng_obj.decode("utf-8") |
50 | 52 | eng_obj_lines = eng_obj_decoded.splitlines() |
51 | 53 |
|
52 | 54 | """ |
53 | | -Alternatively, if you elected to have Comlink send an unzipped response, the result is a dictionary containing keys |
| 55 | +Alternatively, if you elected to have Comlink send an unzipped response, the result is a dictionary containing keys |
54 | 56 | for all of the language files (similar to the namelist() output from the zipfile method above. |
55 | 57 | """ |
56 | | -location_bundle_unzipped = comlink.get_localization_bundle(id=game_data_versions['language'], unzip=True) |
| 58 | +location_bundle_unzipped = comlink.get_localization_bundle(localization_id=game_data_versions["language"], unzip=True) |
57 | 59 |
|
58 | 60 | """ |
59 | 61 | Each key of the result dictionary is a string that can be split into individual lines, or written to files. |
60 | 62 |
|
61 | 63 | >>> location_bundle_unzipped.keys() |
62 | | -dict_keys(['Loc_CHS_CN.txt', 'Loc_CHT_CN.txt', 'Loc_ENG_US.txt', 'Loc_FRE_FR.txt', 'Loc_GER_DE.txt', 'Loc_IND_ID.txt', |
63 | | -'Loc_ITA_IT.txt', 'Loc_JPN_JP.txt', 'Loc_Key_Mapping.txt', 'Loc_KOR_KR.txt', 'Loc_POR_BR.txt', 'Loc_RUS_RU.txt', |
| 64 | +dict_keys(['Loc_CHS_CN.txt', 'Loc_CHT_CN.txt', 'Loc_ENG_US.txt', 'Loc_FRE_FR.txt', 'Loc_GER_DE.txt', 'Loc_IND_ID.txt', |
| 65 | +'Loc_ITA_IT.txt', 'Loc_JPN_JP.txt', 'Loc_Key_Mapping.txt', 'Loc_KOR_KR.txt', 'Loc_POR_BR.txt', 'Loc_RUS_RU.txt', |
64 | 66 | 'Loc_SPA_XM.txt', 'Loc_THA_TH.txt', 'Loc_TUR_TR.txt']) |
65 | 67 |
|
66 | 68 | Depending on the speed of your connection and other resource factors, the time needed to retrieve the localization |
|
0 commit comments