Added handle_input.py & query for plugin id

This commit is contained in:
Neocky 2021-03-03 17:13:43 +01:00
parent ba4aa69173
commit a713a63264
3 changed files with 128 additions and 68 deletions

51
pluGET/handle_input.py Normal file
View File

@ -0,0 +1,51 @@
import time
from consoleoutput import consoleTitle, clearConsole, printMainMenu
from plugin_downloader import downloadPackageManual, apiCallTest, searchPackage, getLatestPackageVersion
from plugin_updatechecker import getInstalledPackages
def handleInput(inputString):
if inputString == "1":
downloadPackageManual()
if inputString == "2":
apiCallTest()
if inputString == "3":
searchPackage()
if inputString == "4":
ressourceID = inputOption(inputString)
getLatestPackageVersion(ressourceID, r"C:\\Users\USER\Desktop\\")
if inputString == "5":
getInstalledPackages('C:\\Users\\USER\\Desktop\\plugins')
def inputMainMenu():
clearConsole()
printMainMenu()
inputSt = input(" pluGET >> ")
handleInput(inputSt)
def inputOption(inputOption):
if inputOption == "1":
ressourceID = input("SpigotMC Ressource ID: ")
return ressourceID
def outputTest():
print("Hello world")
print("Waiting still seconds: 5", end='\r')
time.sleep(1)
print("Waiting still seconds: 4", end='\r')
time.sleep(1)
print("Waiting still seconds: 3", end='\r')
time.sleep(1)
print("Waiting still seconds: 2", end='\r')
time.sleep(1)
print("Waiting still seconds: 1", end='\r')
time.sleep(1)
print("Done ✅☑✔ ")
input("Press key to end program...")
consoleTitle()
inputMainMenu()
outputTest()

View File

@ -1,10 +1,8 @@
import urllib.request import urllib.request
import cgi import cgi
import time
import re import re
import requests import requests
from consoleoutput import consoleTitle, clearConsole, printMainMenu
from plugin_updatechecker import getInstalledPackages
def calculateFileSize(downloadFileSize): def calculateFileSize(downloadFileSize):
@ -14,43 +12,6 @@ def calculateFileSize(downloadFileSize):
return roundedFileSize return roundedFileSize
def handleInput(inputString):
if inputString == "1":
downloadPackageManual()
if inputString == "2":
apiCallTest()
if inputString == "3":
searchPackage()
if inputString == "4":
getLatestPackageVersion()
if inputString == "5":
getInstalledPackages('C:\\Users\\Jan-Luca\\Desktop\\plugins')
def inputMainMenu():
clearConsole()
printMainMenu()
inputSt = input(" pluGET >> ")
handleInput(inputSt)
def outputTest():
print("Hello world")
print("Waiting still seconds: 5", end='\r')
time.sleep(1)
print("Waiting still seconds: 4", end='\r')
time.sleep(1)
print("Waiting still seconds: 3", end='\r')
time.sleep(1)
print("Waiting still seconds: 2", end='\r')
time.sleep(1)
print("Waiting still seconds: 1", end='\r')
time.sleep(1)
print("Done ✅☑✔ ")
input("Press key to end program...")
# 28140 for Luckperms (Testing only) # 28140 for Luckperms (Testing only)
def downloadPackageManual(): def downloadPackageManual():
ressourceId = input("SpigotMC Ressource ID: ") ressourceId = input("SpigotMC Ressource ID: ")
@ -70,7 +31,7 @@ def downloadPackageManual():
filename = params["filename"] filename = params["filename"]
# creating file path # creating file path
path = r"C:\\Users\Jan-Luca\Desktop\\" path = r"C:\\Users\USER\Desktop\\"
ppath = path + filename ppath = path + filename
# download file # download file
@ -101,7 +62,7 @@ def handleRegexPackageName(packageNameFull):
return packageNameOnly return packageNameOnly
def getlatestVersion(packageId): def getlatestVersion(packageId):
response = requests.get("https://api.spiget.org/v2/resources/" + packageId + "/versions/latest") response = requests.get(f"https://api.spiget.org/v2/resources/{packageId}/versions/latest")
#packageDetails = response.json() #packageDetails = response.json()
packageVersion = response.json()["name"] packageVersion = response.json()["name"]
return packageVersion return packageVersion
@ -149,7 +110,7 @@ def searchPackage():
def downloadLatestVersion(ressourceId, packageDownloadName, sourcePath): def downloadLatestVersion(ressourceId, packageDownloadName, sourcePath):
url = "https://api.spiget.org/v2/resources/" + ressourceId + "/download" url = f"https://api.spiget.org/v2/resources/{ressourceId}/download"
remotefile = urllib.request.urlopen(url) remotefile = urllib.request.urlopen(url)
filesize = remotefile.info()['Content-Length'] filesize = remotefile.info()['Content-Length']
downloadPath = sourcePath + packageDownloadName downloadPath = sourcePath + packageDownloadName
@ -160,24 +121,18 @@ def downloadLatestVersion(ressourceId, packageDownloadName, sourcePath):
print(f" Downloadsize: {filesizeData} MB") print(f" Downloadsize: {filesizeData} MB")
def getLatestPackageVersion(): def getLatestPackageVersion(ressourceId, downloadPath):
ressourceId = input(" SpigotMC Ressource ID: ") #ressourceId = input(" SpigotMC Ressource ID: ")
response = requests.get("https://api.spiget.org/v2/resources/" + ressourceId) response = requests.get(f"https://api.spiget.org/v2/resources/{ressourceId}")
packageDetails = response.json() packageDetails = response.json()
packageName = response.json()["name"] packageName = response.json()["name"]
packageTag = response.json()["tag"] packageTag = response.json()["tag"]
packageNameNew = handleRegexPackageName(packageName) packageNameNew = handleRegexPackageName(packageName)
packageVersion = getlatestVersion(ressourceId) packageVersion = getlatestVersion(ressourceId)
packageDownloadName = f"{packageNameNew}-{packageVersion}.jar" packageDownloadName = f"{packageNameNew}-{packageVersion}.jar"
downloadPath = r"C:\\Users\Jan-Luca\Desktop\\"
downloadLatestVersion(ressourceId, packageDownloadName, downloadPath) downloadLatestVersion(ressourceId, packageDownloadName, downloadPath)
consoleTitle()
inputMainMenu()
outputTest()
# get latest update > https://api.spiget.org/v2/resources/28140/updates/latest # get latest update > https://api.spiget.org/v2/resources/28140/updates/latest
# this also > https://api.spiget.org/v2/resources/28140/versions/latest # this also > https://api.spiget.org/v2/resources/28140/versions/latest
# get latest download with correct name > https://api.spiget.org/v2/resources/28140/versions/latest/download cloudflare protected # get latest download with correct name > https://api.spiget.org/v2/resources/28140/versions/latest/download cloudflare protected

View File

@ -3,40 +3,94 @@ import re
import requests import requests
#from consoleoutput import consoleTitle, clearConsole #from consoleoutput import consoleTitle, clearConsole
#from plugin_downloader import handleInput from plugin_downloader import getLatestPackageVersion #handleInput
def getInstalledPackages(pluginFolderPath): # as seen on https://pythonguides.com/create-list-in-python/
pluginList = os.listdir(pluginFolderPath) class installedPlugin:
print(pluginList) def __init__(self, pluginId, plugin_is_outdated):
for plugin in pluginList: self.pluginId = pluginId
print(plugin) self.plugin_is_outdated = plugin_is_outdated
getInstalledPluginVersion(plugin)
def getInstalledPluginVersion(pluginName):
def getFileName(pluginName):
pluginNameFull = pluginName
pluginVersion = re.search(r'([\d.]+[.jar]+)', pluginNameFull)
pluginVersionFull = pluginVersion.group()
pluginNameOnly = pluginNameFull.replace(pluginVersionFull, '')
pluginNameOnly = pluginNameOnly[:-1]
return pluginNameOnly
def getFileVersion(pluginName):
pluginNameFull = pluginName pluginNameFull = pluginName
pluginVersion = re.search(r'([\d.]+[.jar]+)', pluginNameFull) pluginVersion = re.search(r'([\d.]+[.jar]+)', pluginNameFull)
pluginVersionFull = pluginVersion.group() pluginVersionFull = pluginVersion.group()
pluginVersionString = pluginVersionFull.replace('.jar', '') pluginVersionString = pluginVersionFull.replace('.jar', '')
pluginNameOnly = pluginNameFull.replace(pluginVersionFull, '') return pluginVersionString
pluginNameOnly = pluginNameOnly[:-1]
print(pluginNameOnly) # not yet implemented
print(pluginVersionString) def compareVersions(pluginVersion, pluginId, updateId):
response = requests.get("https://api.spiget.org/v2/search/resources/" + pluginNameOnly + "?field=name") latestUpdateSearch = requests.get(f"https://api.spiget.org/v2/resources/{pluginId}/versions/{updateId}")
versionLatestUpdate = latestUpdateSearch["name"]
if pluginVersion != versionLatestUpdate:
plugin_is_outdated = True
else:
plugin_is_outdated = False
return plugin_is_outdated
def getInstalledPackages(pluginFolderPath):
list = []
pluginList = os.listdir(pluginFolderPath)
print(pluginList)
for plugin in pluginList:
print(plugin)
fileName = getFileName(plugin)
fileVersion = getFileVersion(plugin)
pluginId = getInstalledPluginVersion(fileName, fileVersion)
list.append( installedPlugin(pluginId, plugin_is_outdated))
if pluginId == None:
print("Couldn't find plugin id. Sorry :(")
continue
#getLatestPackageVersion(pluginID, r"C:\\Users\USER\Desktop\\plugins\\")
def getInstalledPluginVersion(localFileName, localFileVersion):
response = requests.get("https://api.spiget.org/v2/search/resources/" + localFileName + "?field=name")
#https://api.spiget.org/v2/search/resources/luckperms?field=name #https://api.spiget.org/v2/search/resources/luckperms?field=name
print("https://api.spiget.org/v2/search/resources/" + pluginNameOnly + "?field=name") print("https://api.spiget.org/v2/search/resources/" + localFileName + "?field=name")
packageName = response.json() packageName = response.json()
i = 1 i = 1
plugin_match_found = False
pluginID = None
for ressource in packageName: for ressource in packageName:
if plugin_match_found == True:
break
pName = ressource["name"] pName = ressource["name"]
pID = ressource["id"] pID = ressource["id"]
print(f" [{i}] {pName}") print(f" [{i}] {pName} - {pID}")
response2 = requests.get(f"https://api.spiget.org/v2/resources/{pID}/versions?size=100&sort=-name")
packageVersions = response2.json()
for updates in packageVersions:
updateVersion = updates["name"]
if localFileVersion == updateVersion:
plugin_match_found = True
pluginID = pID
print(updates["id"])
print("Found match")
print(pID)
break
i = i + 1 i = i + 1
return pluginID
# start query # start query
# get id # get id
# search with id for all version upaates # search with id for all version upates
# get version that matches installed version # get version that matches installed version
# if match then download latest update # if match then download latest update
# else get second query # else get second query