update synchronize/synchronize.py.

更新UA
This commit is contained in:
Bigsk 2020-06-24 22:40:47 +08:00 committed by Gitee
parent b2a025448e
commit 55bf25ae02

View File

@ -12,6 +12,8 @@ print('------------------------------------------------------------------------'
print('[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to specify global variables.')
SystemName='GeMC API Synchronize Tool'
SavePath='gemcapi/'
Version='2.3.0'
UserAgent={'User-Agent':'GeMCAPI/2.3.0 (GeMC Sync Release 2.3.0;Release)'}
Log='[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting the synchronizing system.\n' + '------------------------------------------------------------------------\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to specify global variables.\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Specifying global variables successful.\n'
print('[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Specifying global variables successful.')
@ -31,13 +33,14 @@ def log(logvar):
#Module Which Be Used To Synchronize Single File.
def synchronize(url, filepath):
global Log
global UserAgent
log('[INFO]:The ' + SystemName + ' is synchronizing the file ' + SavePath + filepath + '.')
try:
synchronize=requests.get(url)
synchronize=requests.get(url, headers=UserAgent)
with open(SavePath + filepath,"wb") as code:
code.write(synchronize.content)
except:
log('[ERROR]:There has a error in task of synchronizing the file ' + SavePath + filepath + '.Don\'t report this to Ghink Network Studio.This is not a bug.')
log('[ERROR]:There has a error in task of synchronizing the file ' + SavePath + filepath + '.')
else:
log('[INFO]:The file ' + SavePath + filepath + ' has been synchronized successfully.')
#Module Which Be Used To Determine Whether The Dir Exists.
@ -48,32 +51,24 @@ def make_sure_dir_exists(dirpath):
else:
log('[INFO]:The dir ' + SavePath + dirpath + ' does not exist.The ' + SystemName + ' will create one.')
os.makedirs(SavePath + dirpath)
#Module Which Be Used To Print Dividing Line.
def dividingline():
global Log
print('------------------------------------------------------------------------')
Log=Log + '------------------------------------------------------------------------' + '\n'
log('[INFO]:Loading all kinds of modules successfully.')
#------------------------------------------------------------------------#
dividingline()
print('------------------------------------------------------------------------')
Log=Log + '------------------------------------------------------------------------' + '\n'
#Save JSON In Global Variables
#Save MC Versions List Json In Global Variables
log('[INFO]:Starting to get the json of MC versions list.')
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to get the json of MC versions list.' + '\n'
#Save MC Versions List Json In Global Variables
mcversionsjson=requests.get(url='http://launchermeta.mojang.com/mc/game/version_manifest.json')
log('[INFO]:Get the json of MC versions successfully.')
#Save Liteloader Versions List Json In Global Variables
log('[INFO]:Starting to get the json of Liteloader Versions list.')
liteloaderversionsjson=requests.get(url='http://dl.liteloader.com/versions/versions.json')
log('[INFO]:Get the json of Liteloader Versions successfully.')
#Save authlib-injector List Json In Global Variables
authlibinjectorbuildsjson=requests.get(url='http://authlib-injector.yushi.moe/index.json')
log('[INFO]:Get the json of authlib-injector successfully.')
log('[INFO]:Get json of MC versions successfully.')
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Get json of MC versions successfully.' + '\n'
#------------------------------------------------------------------------#
dividingline()
print('------------------------------------------------------------------------')
Log=Log + '------------------------------------------------------------------------' + '\n'
#The Part of Determining Whether The Dir Exists.
@ -95,14 +90,11 @@ log('[INFO]:Determining whether the MC versions dir exists successfully.')
log('[INFO]:Starting to determine whether the Liteloader versions dir exists.')
make_sure_dir_exists('liteloader/dl/versions')
log('[INFO]:Determining whether the Liteloader versions dir exists successfully.')
#Determining Whether The authlib-injector Builds Dir Exists.
log('[INFO]:Starting to determine whether the authlib-injector builds dir exists.')
make_sure_dir_exists('yushi/authlib-injector/artifact')
log('[INFO]:Determining whether the authlib-injector builds dir exists successfully.')
log('[INFO]:Determining whether all of dirs exists successfully.')
#------------------------------------------------------------------------#
dividingline()
print('------------------------------------------------------------------------')
Log=Log + '------------------------------------------------------------------------' + '\n'
#The Part of Synchronizing Single Files.
@ -115,51 +107,14 @@ log('[INFO]:Synchronizing MC versions files successfully.')
log('[INFO]:Starting to synchronize Liteloader versions files.')
synchronize('http://dl.liteloader.com/versions/versions.json', 'liteloader/dl/versions/versions.json')
log('[INFO]:Synchronizing Liteloader versions files successfully.')
#Synchronizing The authlib-injector Builds List File.
log('[INFO]:Starting to synchronize authlib-injector builds files.')
synchronize('http://authlib-injector.yushi.moe/index.json', 'yushi/authlib-injector/index.json')
log('[INFO]:Synchronizing authlib-injector builds files successfully.')
#------------------------------------------------------------------------#
dividingline()
#authlib-injector Builds Synchronizing Part.
log('[INFO]:Starting to synchronize all of authlib-injector builds.')
log('[INFO]:Starting to synchronize the latest authlib-injector builds.')
synchronize('http://authlib-injector.yushi.moe/artifact/latest.json', 'yushi/authlib-injector/artifact/latest.json')
log('[INFO]:Synchronizing the latest authlib-injector builds successfully.')
log('[INFO]:Starting to synchronize the list of authlib-injector builds.')
synchronize('http://authlib-injector.yushi.moe/artifacts.json', 'yushi/authlib-injector/artifacts.json')
log('[INFO]:Synchronizing the list of authlib-injector builds successfully.')
log('[INFO]:Starting to get the list json of builds.')
try:
authlibinjectorbuildsjson=requests.get(url='https://authlib-injector.yushi.moe/artifacts.json')
authlibinjectorbuildstext=authlibinjectorbuildsjson.text
except:
log('[ERROR]:There has a error in task of synchronizing files in list json of builds.Don\'t report this to Ghink Network Studio.This is not a bug.')
else:
log('[INFO]:Get the list json of builds successfully.')
log('[INFO]:Starting to synchronize jsons of old builds.')
log('[INFO]:Starting to get list json of builds.')
authlibinjectorbuildstextjson = eval(authlibinjectorbuildstext, type('Dummy', (dict,), dict(__getitem__=lambda s,n:n))())
authlibinjectorbuildsnumber=authlibinjectorbuildstextjson['latest_build_number']
log('[INFO]:Geting list json of builds successfully.')
log('[INFO]:Starting to count how many authlib-injector builds in total.')
log('[INFO]:There has ' + str(authlibinjectorbuildsnumber) + ' authlib-injector builds in total .')
log('[INFO]:Counting how many how many authlib-injector builds in total successfully.')
log('[INFO]:Start to synchronize jsons of other builds.')
whiletimes=0#Set Var whiletimes To Avoid Error.
while(whiletimes < authlibinjectorbuildsnumber):
whiletimes=whiletimes + 1
synchronize('http://authlib-injector.yushi.moe/artifact/' + str(whiletimes) + '.json', 'yushi/authlib-injector/artifact/' + str(whiletimes) + '.json')
log('[INFO]:Synchronizing jsons of other builds successfully.')
#------------------------------------------------------------------------#
dividingline()
print('------------------------------------------------------------------------')
Log=Log + '------------------------------------------------------------------------' + '\n'
#MC Versions Synchronizing Part.
log('[INFO]:Starting to synchronize all of MC versions.')
log('[INFO]:Starting synchronize all of MC versions.')
log('[INFO]:Starting to count how many MC versions in total.')
#Count How Many MC Versions in total.
mcversionsjsontext=mcversionsjson.text
@ -198,18 +153,17 @@ while(whiletimes < mcversionsnumber):
onlineurlwithouthttps=onlineurl.replace('https://', 'http://')#Avoid Https Connetion Errors
log('[INFO]:Starting to get the json of MC libraries ' + onlineurl +' list.')
#Save MC Libraries Json In Global Variables
try:#Avoid Http/Httos Connection Errors Making Whole Synchronize Stop.
try:#Avoid Http/Https Connection Errors Making Whole Synchronize Stop.
mclibrariesjson=requests.get(url=onlineurlwithouthttps)
except:
log('[ERROR]:There has a error in task of getting json of MC libraries ' + onlineurl + '.Don\'t report this to Ghink Network Studio.This is not a bug.')
log('[ERROR]:There has a error in task of getting json of MC libraries ' + onlineurl + '.')
else:
log('[INFO]:Get json of MC libraries ' + onlineurl + ' successfully.')
#Read Json Of MC Libraries.
mclibrariesload=json.loads(mclibrariesjson.text)
#Synchronize Files In "downloads".
log('[INFO]:Starting to synchronize files in ”downloads".')
try:#Avoid Http/Httos Connection Errors Or Synchronize Module Download Failed Errors Making Whole Synchronize Stop.
#Synchronize Files In "downloads".
try:#Avoid Http/Https Connection Errors Or Synchronize Module Download Failed Errors Making Whole Synchronize Stop.
onlineurl2=mclibrariesload['downloads']['client']['url']
fileurl2='mojang/launcher/' + onlineurl2.replace('https://launcher.mojang.com/','')
filetosync2=fileurl2[::-1].split('/', 1)[-1][::-1]
@ -237,7 +191,7 @@ while(whiletimes < mcversionsnumber):
make_sure_dir_exists(filetosync2)
synchronize(onlineurl2, fileurl2)
except:
log('[ERROR]:There has a error in task of synchronizing files in "downloads" or "loggin".Don\'t report this to Ghink Network Studio.This is not a bug.')
log('[ERROR]:There has a error in task of synchronizing files in "downloads".')
else:
log('[INFO]:Synchronizing files in "downloads" successfully.')
log('[INFO]:Starting to count how many MC libraries files in ' + onlineurl + ' in total.')
@ -253,7 +207,7 @@ while(whiletimes < mcversionsnumber):
whiletimesload3=whiletimes3 - 1
#Synchronize Files In "libraries".
log('[INFO]:Starting to synchronize Files In "libraries".')
try:#Avoid Http/Httos Connection Errors Or Synchronize Module Download Failed Errors Making Whole Synchronize Stop.
try:#Avoid Http/Https Connection Errors Or Synchronize Module Download Failed Errors Making Whole Synchronize Stop.
#Synchronize Files In "libraries/.../downloads/artifact".
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['artifact']['url']
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
@ -297,15 +251,15 @@ while(whiletimes < mcversionsnumber):
make_sure_dir_exists(filetosync3)
synchronize(onlineurlwithouthttps3, fileurl3)
except:
log('[ERROR]:There has a error in task of synchronizing files in ”libraries".Don\'t report this to Ghink Network Studio.This is not a bug.')
log('[ERROR]:There has a error in task of synchronizing files in ”libraries".')
else:
log('[INFO]:Synchronizing files in "libraries" successfully.')
log('[INFO]:Synchronizing files and dirs on https://libraries.minecraft.net/ successfully.')
log('[INFO]:Synchronizing all of MC Versions successfully.')
#------------------------------------------------------------------------#
dividingline()
print('------------------------------------------------------------------------')
Log=Log + '------------------------------------------------------------------------' + '\n'
#Starting To Save Logs.
log('[INFO]:Starting to save logs.')