99import zstandard
1010import lzma
1111import csv
12+ import os
13+ import zipfile
1214from collections import defaultdict
1315
1416# Targets first index is the URL and the second is the filename. If filename
2628]
2729FINGERPRINT = "c4e8c2976dcf42530d68dcb1fdfb61d071085abf"
2830BASE_URL = f"https://game-assets.clashofclans.com/{ FINGERPRINT } "
31+ APK_URL = "https://d.apkpure.net/b/APK/com.supercell.clashofclans?version=latest"
2932
3033
3134def decompress (data ):
@@ -69,6 +72,7 @@ def decompress(data):
6972 decompressed = lzma .LZMADecompressor ().decompress (data )
7073 return decompressed
7174
75+
7276def process_csv (data , file_path , save_name ):
7377 decompressed = decompress (data )
7478
@@ -128,6 +132,10 @@ def process_csv(data, file_path, save_name):
128132
129133 jsonf .write (json .dumps (data , indent = 4 ))
130134
135+ # clean up the .csv file, it is not used in coc.py
136+ os .unlink (file_path )
137+
138+
131139def check_header (data ):
132140 if data [0 ] == 0x5D :
133141 return "csv"
@@ -137,6 +145,30 @@ def check_header(data):
137145 return "sig:"
138146 raise Exception (" Unknown header" )
139147
148+
149+ def get_fingerprint ():
150+ import aiohttp
151+ import asyncio
152+
153+ async def download ():
154+ async with aiohttp .request ('GET' , APK_URL ) as fp :
155+ c = await fp .read ()
156+ return c
157+
158+ data = asyncio .run (download ())
159+
160+ with open ("apk.zip" , "wb" ) as f :
161+ f .write (data )
162+ zf = zipfile .ZipFile ("apk.zip" )
163+ with zf .open ('assets/fingerprint.json' ) as fp :
164+ fingerprint = json .loads (fp .read ())['sha' ]
165+
166+ # clean up apk
167+ os .unlink ("apk.zip" )
168+
169+ return fingerprint
170+
171+
140172def main ():
141173 for target_file , target_save in TARGETS :
142174 target_save = target_file if target_save is None else target_save
0 commit comments