优化代码结构,新增Forge同步
This commit is contained in:
parent
cca441aff5
commit
20b851f5a1
124
synchronize/synchronize/part1.py
Normal file
124
synchronize/synchronize/part1.py
Normal file
@ -0,0 +1,124 @@
|
||||
import requests
|
||||
import os
|
||||
import time
|
||||
import json
|
||||
import sys
|
||||
|
||||
#------------------------------------------------------------------------#
|
||||
|
||||
#Part Of Load All Kinds Of Global Variables From Json File.
|
||||
|
||||
configopen=open(os.path.dirname(os.path.abspath(sys.argv[0])) + "/config.json", mode='r')
|
||||
configjson=configopen.read()
|
||||
configopen.close()
|
||||
config=json.loads(configjson)
|
||||
SystemName=config['systemname']
|
||||
SavePath=os.path.dirname(os.path.abspath(sys.argv[0])) + "/" + config['savepath']
|
||||
Version=config['version']
|
||||
UserAgent={'User-Agent':config['useragent']}
|
||||
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'
|
||||
|
||||
#------------------------------------------------------------------------#
|
||||
Log=Log + '------------------------------------------------------------------------' + '\n'
|
||||
|
||||
#The Part Of All Kinds Of Functions.
|
||||
|
||||
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to load all kinds of functions.' + '\n'
|
||||
#Function Which Be Used To Save Logs.
|
||||
def log(logvar):
|
||||
global Log
|
||||
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + logvar + '\n'
|
||||
#Function Which Be Used To Synchronize Single File.
|
||||
def download(url, filepath):
|
||||
global Log
|
||||
global UserAgent
|
||||
log('[INFO]:The ' + SystemName + ' is synchronizing the file ' + SavePath + filepath + '.')
|
||||
try:
|
||||
download=requests.get(url, headers=UserAgent)
|
||||
with open(SavePath + filepath,"wb") as code:
|
||||
code.write(download.content)
|
||||
except:
|
||||
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.')
|
||||
#Function Which Be Used To Make Sure The Dir Exists.
|
||||
def make_sure_dir_exists(dirpath):
|
||||
global Log
|
||||
if os.path.exists(SavePath + dirpath):
|
||||
log('[INFO]:The dir ' + SavePath + dirpath + ' has already existed.Nothing to do.')
|
||||
else:
|
||||
log('[INFO]:The dir ' + SavePath + dirpath + ' does not exist.The ' + SystemName + ' will create one.')
|
||||
os.makedirs(SavePath + dirpath)
|
||||
#Function Which Be Used To Both Synchronize Single File And Make Sure The Dir Exists.
|
||||
def synchronize(url, filepath):
|
||||
global Log
|
||||
global UserAgent
|
||||
dirpath= filepath[::-1].split('/', 1)[-1][::-1]
|
||||
if os.path.exists(SavePath + dirpath):
|
||||
log('[INFO]:The dir ' + SavePath + dirpath + ' has already existed.Nothing to do.')
|
||||
else:
|
||||
log('[INFO]:The dir ' + SavePath + dirpath + ' does not exist.The ' + SystemName + ' will create one.')
|
||||
os.makedirs(SavePath + dirpath)
|
||||
log('[INFO]:The ' + SystemName + ' is synchronizing the file ' + SavePath + filepath + '.')
|
||||
try:
|
||||
download=requests.get(url, headers=UserAgent)
|
||||
with open(SavePath + filepath,"wb") as code:
|
||||
code.write(download.content)
|
||||
except:
|
||||
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.')
|
||||
log('[INFO]:Loading all kinds of functions successfully.')
|
||||
|
||||
#------------------------------------------------------------------------#
|
||||
Log=Log + '------------------------------------------------------------------------' + '\n'
|
||||
|
||||
#Save 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', headers=UserAgent)
|
||||
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'
|
||||
|
||||
#------------------------------------------------------------------------#
|
||||
Log=Log + '------------------------------------------------------------------------' + '\n'
|
||||
|
||||
#Synchronize Part.
|
||||
|
||||
log('[INFO]:Starting to count how many MC versions in total.')
|
||||
#Count How Many MC Versions in total.
|
||||
mcversionsjsontext=mcversionsjson.text
|
||||
mcversionsnumber=mcversionsjsontext.count('"url":')
|
||||
log('[INFO]:There has ' + str(mcversionsnumber) + ' MC versions in total .')
|
||||
log('[INFO]:Counting how many MC versions in total successfully.')
|
||||
|
||||
#Synchronizing The Minecraft Versions List File.
|
||||
log('[INFO]:Starting to synchronize MC versions files.')
|
||||
synchronize('http://launchermeta.mojang.com/mc/game/version_manifest.json', 'mojang/launchermeta/mc/game/version_manifest.json')
|
||||
log('[INFO]:Synchronizing MC versions files successfully.')
|
||||
|
||||
#Auto Synchronize Files And Dirs on https://launchermeta.mojang.com/.
|
||||
log('[INFO]:Starting to synchronize files and dirs on https://launchermeta.mojang.com/.')
|
||||
whiletimes=0#Set Var whiletimes To Avoid Error.
|
||||
while(whiletimes < mcversionsnumber):
|
||||
#Count While Times.
|
||||
whiletimes=whiletimes + 1
|
||||
#Read Json Of MC Versions List.
|
||||
downloadurlload=json.loads(mcversionsjsontext)
|
||||
whiletimesload=whiletimes - 1
|
||||
onlineurl=downloadurlload['versions'][whiletimesload]['url']
|
||||
onlineurlwithouthttps=onlineurl.replace('https://', 'http://')#Avoid Https Connetion Errors
|
||||
fileurl='mojang/launchermeta/' + onlineurl.replace('https://launchermeta.mojang.com/','')
|
||||
synchronize(onlineurlwithouthttps, fileurl)
|
||||
log('[INFO]:Synchronizing files and dirs on https://launchermeta.mojang.com/ successfully.')
|
||||
|
||||
#------------------------------------------------------------------------#
|
||||
Log=Log + '------------------------------------------------------------------------' + '\n'
|
||||
|
||||
#Starting To Save Logs.
|
||||
log('[INFO]:Starting to save logs.')
|
||||
logwrite=open(os.path.dirname(os.path.abspath(sys.argv[0])) + '/' + config['logspath'] + 'part1-' + str(time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + '.txt'),mode='w')
|
||||
logwrite.write(Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Save logs successfully.' + '\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:All tasks of synchronizing have done successfully.')
|
||||
logwrite.close()
|
200
synchronize/synchronize/part2.py
Normal file
200
synchronize/synchronize/part2.py
Normal file
@ -0,0 +1,200 @@
|
||||
import requests
|
||||
import os
|
||||
import time
|
||||
import json
|
||||
import sys
|
||||
|
||||
#------------------------------------------------------------------------#
|
||||
|
||||
#Part Of Load All Kinds Of Global Variables From Json File.
|
||||
|
||||
configopen=open(os.path.dirname(os.path.abspath(sys.argv[0])) + "/config.json", mode='r')
|
||||
configjson=configopen.read()
|
||||
configopen.close()
|
||||
config=json.loads(configjson)
|
||||
SystemName=config['systemname']
|
||||
SavePath=os.path.dirname(os.path.abspath(sys.argv[0])) + "/" + config['savepath']
|
||||
Version=config['version']
|
||||
UserAgent={'User-Agent':config['useragent']}
|
||||
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'
|
||||
|
||||
#------------------------------------------------------------------------#
|
||||
Log=Log + '------------------------------------------------------------------------' + '\n'
|
||||
|
||||
#The Part Of All Kinds Of Functions.
|
||||
|
||||
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to load all kinds of functions.' + '\n'
|
||||
#Function Which Be Used To Save Logs.
|
||||
def log(logvar):
|
||||
global Log
|
||||
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + logvar + '\n'
|
||||
#Function Which Be Used To Synchronize Single File.
|
||||
def download(url, filepath):
|
||||
global Log
|
||||
global UserAgent
|
||||
log('[INFO]:The ' + SystemName + ' is synchronizing the file ' + SavePath + filepath + '.')
|
||||
try:
|
||||
download=requests.get(url, headers=UserAgent)
|
||||
with open(SavePath + filepath,"wb") as code:
|
||||
code.write(download.content)
|
||||
except:
|
||||
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.')
|
||||
#Function Which Be Used To Make Sure The Dir Exists.
|
||||
def make_sure_dir_exists(dirpath):
|
||||
global Log
|
||||
if os.path.exists(SavePath + dirpath):
|
||||
log('[INFO]:The dir ' + SavePath + dirpath + ' has already existed.Nothing to do.')
|
||||
else:
|
||||
log('[INFO]:The dir ' + SavePath + dirpath + ' does not exist.The ' + SystemName + ' will create one.')
|
||||
os.makedirs(SavePath + dirpath)
|
||||
#Function Which Be Used To Both Synchronize Single File And Make Sure The Dir Exists.
|
||||
def synchronize(url, filepath):
|
||||
global Log
|
||||
global UserAgent
|
||||
dirpath= filepath[::-1].split('/', 1)[-1][::-1]
|
||||
if os.path.exists(SavePath + dirpath):
|
||||
log('[INFO]:The dir ' + SavePath + dirpath + ' has already existed.Nothing to do.')
|
||||
else:
|
||||
log('[INFO]:The dir ' + SavePath + dirpath + ' does not exist.The ' + SystemName + ' will create one.')
|
||||
os.makedirs(SavePath + dirpath)
|
||||
log('[INFO]:The ' + SystemName + ' is synchronizing the file ' + SavePath + filepath + '.')
|
||||
try:
|
||||
download=requests.get(url, headers=UserAgent)
|
||||
with open(SavePath + filepath,"wb") as code:
|
||||
code.write(download.content)
|
||||
except:
|
||||
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.')
|
||||
log('[INFO]:Loading all kinds of functions successfully.')
|
||||
|
||||
#------------------------------------------------------------------------#
|
||||
Log=Log + '------------------------------------------------------------------------' + '\n'
|
||||
|
||||
#Save 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', headers=UserAgent)
|
||||
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'
|
||||
|
||||
#------------------------------------------------------------------------#
|
||||
Log=Log + '------------------------------------------------------------------------' + '\n'
|
||||
|
||||
#Synchronize Part.
|
||||
|
||||
log('[INFO]:Starting to count how many MC versions in total.')
|
||||
#Count How Many MC Versions in total.
|
||||
mcversionsjsontext=mcversionsjson.text
|
||||
mcversionsnumber=mcversionsjsontext.count('"url":')
|
||||
log('[INFO]:There has ' + str(mcversionsnumber) + ' MC versions in total .')
|
||||
log('[INFO]:Counting how many MC versions in total successfully.')
|
||||
|
||||
#Auto Synchronize Files And Dirs on https://libraries.minecraft.net/.
|
||||
log('[INFO]:Starting to synchronize files and dirs on https://libraries.minecraft.net/.')
|
||||
#Part Of 'downloads'.
|
||||
whiletimes=0#Set Var whiletimes To Avoid Error.
|
||||
while(whiletimes < mcversionsnumber):
|
||||
#Count While Times.
|
||||
whiletimes=whiletimes + 1
|
||||
#Read Json Of MC Versions List.
|
||||
downloadurlload=json.loads(mcversionsjsontext)
|
||||
whiletimesload=whiletimes - 1
|
||||
onlineurl=downloadurlload['versions'][whiletimesload]['url']
|
||||
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/Https Connection Errors Making Whole Synchronize Stop.
|
||||
mclibrariesjson=requests.get(url=onlineurlwithouthttps, headers=UserAgent)
|
||||
except:
|
||||
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/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/','')
|
||||
synchronize(onlineurl2, fileurl2)
|
||||
onlineurl2=mclibrariesload['downloads']['client_mappings']['url']
|
||||
fileurl2='mojang/launcher/' + onlineurl2.replace('https://launcher.mojang.com/','')
|
||||
synchronize(onlineurl2, fileurl2)
|
||||
onlineurl2=mclibrariesload['downloads']['server']['url']
|
||||
fileurl2='mojang/launcher/' + onlineurl2.replace('https://launcher.mojang.com/','')
|
||||
synchronize(onlineurl2, fileurl2)
|
||||
onlineurl2=mclibrariesload['downloads']['server_mappings']['url']
|
||||
fileurl2='mojang/launcher/' + onlineurl2.replace('https://launcher.mojang.com/','')
|
||||
synchronize(onlineurl2, fileurl2)
|
||||
#Synchronize Files In "loggin".
|
||||
onlineurl2=mclibrariesload['loggin']['client']['file']['url']
|
||||
fileurl2='mojang/launcher/' + onlineurl2.replace('https://launcher.mojang.com/','')
|
||||
synchronize(onlineurl2, fileurl2)
|
||||
except:
|
||||
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.')
|
||||
#Count How Many MC Libraries Files in total.
|
||||
mclibrariesjsontext=mclibrariesjson.text
|
||||
mclibrariesnumber=mclibrariesjsontext.count('"url":') - 6
|
||||
log('[INFO]:There has ' + str(mclibrariesnumber) + ' MC libraries files in ' + onlineurl + ' in total.')
|
||||
log('[INFO]:Counting how many MC libraries files in ' + onlineurl + ' in total successfully.')
|
||||
whiletimes3=0#Set Var whiletimes To Avoid Error.
|
||||
while(whiletimes3 < mclibrariesnumber):
|
||||
#Count While Times.
|
||||
whiletimes3=whiletimes3 + 1
|
||||
whiletimesload3=whiletimes3 - 1
|
||||
#Synchronize Files In "libraries".
|
||||
log('[INFO]:Starting to synchronize Files In "libraries".')
|
||||
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://')
|
||||
fileurl3='mojang/libraries/' + onlineurl3.replace('https://libraries.minecraft.net/','')
|
||||
synchronize(onlineurlwithouthttps3, fileurl3)
|
||||
#Synchronize Files In "libraries/.../downloads/classifiers/javadoc".
|
||||
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['classifiers']['javadoc']['url']
|
||||
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
|
||||
fileurl3='mojang/libraries/' + onlineurl3.replace('https://libraries.minecraft.net/','')
|
||||
synchronize(onlineurlwithouthttps3, fileurl3)
|
||||
#Synchronize Files In "libraries/.../downloads/classifiers/natives-linux".
|
||||
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['classifiers']['natives-linux']['url']
|
||||
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
|
||||
fileurl3='mojang/libraries/' + onlineurl3.replace('https://libraries.minecraft.net/','')
|
||||
synchronize(onlineurlwithouthttps3, fileurl3)
|
||||
#Synchronize Files In "libraries/.../downloads/classifiers/natives-macos".
|
||||
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['classifiers']['natives-macos']['url']
|
||||
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
|
||||
fileurl3='mojang/libraries/' + onlineurl3.replace('https://libraries.minecraft.net/','')
|
||||
synchronize(onlineurlwithouthttps3, fileurl3)
|
||||
#Synchronize Files In "libraries/.../downloads/classifiers/natives-windows".
|
||||
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['classifiers']['natives-windows']['url']
|
||||
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
|
||||
fileurl3='mojang/libraries/' + onlineurl3.replace('https://libraries.minecraft.net/','')
|
||||
synchronize(onlineurlwithouthttps3, fileurl3)
|
||||
#Synchronize Files In "libraries/.../downloads/artifact/classifiers/sources".
|
||||
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['classifiers']['sources']['url']
|
||||
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
|
||||
fileurl3='mojang/libraries/' + onlineurl3.replace('https://libraries.minecraft.net/','')
|
||||
synchronize(onlineurlwithouthttps3, fileurl3)
|
||||
except:
|
||||
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=Log + '------------------------------------------------------------------------' + '\n'
|
||||
|
||||
#Starting To Save Logs.
|
||||
log('[INFO]:Starting to save logs.')
|
||||
logwrite=open(os.path.dirname(os.path.abspath(sys.argv[0])) + '/' + config['logspath'] + 'part1-' + str(time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + '.txt'),mode='w')
|
||||
logwrite.write(Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Save logs successfully.' + '\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:All tasks of synchronizing have done successfully.')
|
||||
logwrite.close()
|
166
synchronize/synchronize/part3.py
Normal file
166
synchronize/synchronize/part3.py
Normal file
@ -0,0 +1,166 @@
|
||||
import requests
|
||||
import os
|
||||
import time
|
||||
import json
|
||||
import sys
|
||||
|
||||
#------------------------------------------------------------------------#
|
||||
|
||||
#Part Of Load All Kinds Of Global Variables From Json File.
|
||||
|
||||
configopen=open(os.path.dirname(os.path.abspath(sys.argv[0])) + "/config.json", mode='r')
|
||||
configjson=configopen.read()
|
||||
configopen.close()
|
||||
config=json.loads(configjson)
|
||||
SystemName=config['systemname']
|
||||
SavePath=os.path.dirname(os.path.abspath(sys.argv[0])) + "/" + config['savepath']
|
||||
Version=config['version']
|
||||
UserAgent={'User-Agent':config['useragent']}
|
||||
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'
|
||||
|
||||
#------------------------------------------------------------------------#
|
||||
Log=Log + '------------------------------------------------------------------------' + '\n'
|
||||
|
||||
#The Part Of All Kinds Of Functions.
|
||||
|
||||
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to load all kinds of functions.' + '\n'
|
||||
#Function Which Be Used To Save Logs.
|
||||
def log(logvar):
|
||||
global Log
|
||||
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + logvar + '\n'
|
||||
#Function Which Be Used To Synchronize Single File.
|
||||
def download(url, filepath):
|
||||
global Log
|
||||
global UserAgent
|
||||
log('[INFO]:The ' + SystemName + ' is synchronizing the file ' + SavePath + filepath + '.')
|
||||
try:
|
||||
download=requests.get(url, headers=UserAgent)
|
||||
with open(SavePath + filepath,"wb") as code:
|
||||
code.write(download.content)
|
||||
except:
|
||||
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.')
|
||||
#Function Which Be Used To Make Sure The Dir Exists.
|
||||
def make_sure_dir_exists(dirpath):
|
||||
global Log
|
||||
if os.path.exists(SavePath + dirpath):
|
||||
log('[INFO]:The dir ' + SavePath + dirpath + ' has already existed.Nothing to do.')
|
||||
else:
|
||||
log('[INFO]:The dir ' + SavePath + dirpath + ' does not exist.The ' + SystemName + ' will create one.')
|
||||
os.makedirs(SavePath + dirpath)
|
||||
#Function Which Be Used To Both Synchronize Single File And Make Sure The Dir Exists.
|
||||
def synchronize(url, filepath):
|
||||
global Log
|
||||
global UserAgent
|
||||
dirpath= filepath[::-1].split('/', 1)[-1][::-1]
|
||||
if os.path.exists(SavePath + dirpath):
|
||||
log('[INFO]:The dir ' + SavePath + dirpath + ' has already existed.Nothing to do.')
|
||||
else:
|
||||
log('[INFO]:The dir ' + SavePath + dirpath + ' does not exist.The ' + SystemName + ' will create one.')
|
||||
os.makedirs(SavePath + dirpath)
|
||||
log('[INFO]:The ' + SystemName + ' is synchronizing the file ' + SavePath + filepath + '.')
|
||||
try:
|
||||
download=requests.get(url, headers=UserAgent)
|
||||
with open(SavePath + filepath,"wb") as code:
|
||||
code.write(download.content)
|
||||
except:
|
||||
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.')
|
||||
log('[INFO]:Loading all kinds of functions successfully.')
|
||||
|
||||
#------------------------------------------------------------------------#
|
||||
Log=Log + '------------------------------------------------------------------------' + '\n'
|
||||
|
||||
log('[INFO]:Starting to get forge builds list from BMCLAPI.')
|
||||
log('[INFO]:Thanks the support from bangbang93.')
|
||||
#Synchronize The Last Forge Builds.
|
||||
log('[INFO]:Starting synchronize the last forge builds.')
|
||||
synchronize('http://bmclapi2.bangbang93.com/forge/last','forge/last/index.html')
|
||||
#Synchronize The Versions List Of Minecraft Which Were Supported By Forge.
|
||||
log('[INFO]:Starting synchronize the versions list of minecraft which were supported by forfge.')
|
||||
synchronize('http://bmclapi2.bangbang93.com/forge/minecraft','forge/minecraft/index.html')
|
||||
#Synchronize The Different Number Of Builds List Of Forge.
|
||||
log('[INFO]:Starting synchronize the different number of builds list of forge.')
|
||||
count=0
|
||||
for i in range(0,500):
|
||||
count=count+1
|
||||
synchronize('http://bmclapi2.bangbang93.com/forge/list/'+str(count), 'forge/list/'+str(count)+'/index.html')
|
||||
#Synchronize The Forge Builds List With Different MC Versions.
|
||||
log('[INFO]:Starting synchronize the forge builds list with different mc versions.')
|
||||
supportlist=requests.get(url='http://bmclapi2.bangbang93.com/forge/minecraft', headers=UserAgent).text
|
||||
number=supportlist.count(',')
|
||||
supportlistjson=json.loads(supportlist)
|
||||
count=0
|
||||
for i in range(0,number):
|
||||
count=count+1
|
||||
version=supportlistjson[count]
|
||||
synchronize('http://bmclapi2.bangbang93.com/forge/minecraft/'+version, 'forge/minecraft/'+version+'/index.html')
|
||||
#Synchronize The Forge Builds With Different MC Versions With Build ID.
|
||||
log('[INFO]:Starting synchronize the forge builds with different mc versions with build ID.')
|
||||
count=0
|
||||
for i in range(0,number):
|
||||
count=count+1
|
||||
version=supportlistjson[count]
|
||||
buildswithversion=requests.get(url='http://bmclapi2.bangbang93.com/forge/minecraft/'+version, headers=UserAgent).text
|
||||
buildswithversionjson=json.loads(buildswithversion)
|
||||
number_sub=buildswithversion.count('build')
|
||||
count_sub=0
|
||||
for i in range(0,number_sub):
|
||||
count_sub=count_sub+1
|
||||
countforjson=count_sub-1
|
||||
buildid=buildswithversionjson[countforjson]['build']
|
||||
if requests.get(url='http://bmclapi2.bangbang93.com/forge/download/'+str(buildid), headers=UserAgent).text=="Not Found":
|
||||
log('[ERROR]:Can not find the file which is synchronizing on BMCLAPI.This may a bug of BMCLAPI,but in most times is not a bug and that is normal.')
|
||||
else:
|
||||
synchronize('http://bmclapi2.bangbang93.com/forge/download/'+str(buildid), 'forge/download/'+str(buildid)+'.jar')
|
||||
#Synchronize The Forge Builds With Different MC Versions.
|
||||
log('[INFO]:Starting synchronize the forge builds with different mc versions.')
|
||||
count=0
|
||||
for i in range(0,number):
|
||||
count=count+1
|
||||
version=supportlistjson[count]
|
||||
versionswithversion=requests.get(url='http://bmclapi2.bangbang93.com/forge/minecraft/'+version, headers=UserAgent).text
|
||||
versionswithversionjson=json.loads(versionswithversion)
|
||||
number_sub=versionswithversion.count('"version"')
|
||||
count_sub=0
|
||||
for i in range(0,number_sub):
|
||||
count_sub=count_sub+1
|
||||
countforjson=count_sub-1
|
||||
versionid=versionswithversionjson[countforjson]['version']
|
||||
#Installer Part.
|
||||
if requests.get(url='http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-installer.jar', headers=UserAgent).text=="Not Found":
|
||||
log('[ERROR]:Can not find the file which is synchronizing on BMCLAPI.This may a bug of BMCLAPI,but in most times is not a bug and that is normal.')
|
||||
else:
|
||||
synchronize('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-installer.jar', 'forge/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-installer.jar')
|
||||
#Launcher Part.
|
||||
if requests.get(url='http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-launcher.jar', headers=UserAgent).text=="Not Found":
|
||||
log('[ERROR]:Can not find the file which is synchronizing on BMCLAPI.This may a bug of BMCLAPI,but in most times is not a bug and that is normal.')
|
||||
else:
|
||||
synchronize('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-launcher.jar', 'forge/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-launcher.jar')
|
||||
#Sources Part.
|
||||
if requests.get(url='http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-sources.jar', headers=UserAgent).text=="Not Found":
|
||||
log('[ERROR]:Can not find the file which is synchronizing on BMCLAPI.This may a bug of BMCLAPI,but in most times is not a bug and that is normal.')
|
||||
else:
|
||||
synchronize('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-sources.jar', 'forge/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-sources.jar')
|
||||
#Universal Part.
|
||||
if requests.get(url='http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-universal.jar', headers=UserAgent).text=="Not Found":
|
||||
log('[ERROR]:Can not find the file which is synchronizing on BMCLAPI.This may a bug of BMCLAPI,but in most times is not a bug and that is normal.')
|
||||
else:
|
||||
synchronize('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-universal.jar', 'forge/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-universal.jar')
|
||||
#MDK Part.
|
||||
if requests.get(url='http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-mdk.zip', headers=UserAgent).text=="Not Found":
|
||||
log('[ERROR]:Can not find the file which is synchronizing on BMCLAPI.This may a bug of BMCLAPI,but in most times is not a bug and that is normal.')
|
||||
else:
|
||||
synchronize('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-mdk.zip', 'forge/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-mdk.zip')
|
||||
log('[INFO]:Synchronizing forge builds list from BMCLAPI successfully.')
|
||||
|
||||
#------------------------------------------------------------------------#
|
||||
Log=Log + '------------------------------------------------------------------------' + '\n'
|
||||
|
||||
#Starting To Save Logs.
|
||||
log('[INFO]:Starting to save logs.')
|
||||
logwrite=open(os.path.dirname(os.path.abspath(sys.argv[0])) + '/' + config['logspath'] + 'part3-' + str(time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + '.txt'),mode='w')
|
||||
logwrite.write(Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Save logs successfully.' + '\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:All tasks of synchronizing have done successfully.')
|
||||
logwrite.close()
|
Reference in New Issue
Block a user