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 cgi
import time
import re
import requests
from consoleoutput import consoleTitle, clearConsole, printMainMenu
from plugin_updatechecker import getInstalledPackages
def calculateFileSize(downloadFileSize):
@ -14,43 +12,6 @@ def calculateFileSize(downloadFileSize):
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)
def downloadPackageManual():
ressourceId = input("SpigotMC Ressource ID: ")
@ -70,7 +31,7 @@ def downloadPackageManual():
filename = params["filename"]
# creating file path
path = r"C:\\Users\Jan-Luca\Desktop\\"
path = r"C:\\Users\USER\Desktop\\"
ppath = path + filename
# download file
@ -101,7 +62,7 @@ def handleRegexPackageName(packageNameFull):
return packageNameOnly
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()
packageVersion = response.json()["name"]
return packageVersion
@ -149,7 +110,7 @@ def searchPackage():
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)
filesize = remotefile.info()['Content-Length']
downloadPath = sourcePath + packageDownloadName
@ -160,24 +121,18 @@ def downloadLatestVersion(ressourceId, packageDownloadName, sourcePath):
print(f" Downloadsize: {filesizeData} MB")
def getLatestPackageVersion():
ressourceId = input(" SpigotMC Ressource ID: ")
response = requests.get("https://api.spiget.org/v2/resources/" + ressourceId)
def getLatestPackageVersion(ressourceId, downloadPath):
#ressourceId = input(" SpigotMC Ressource ID: ")
response = requests.get(f"https://api.spiget.org/v2/resources/{ressourceId}")
packageDetails = response.json()
packageName = response.json()["name"]
packageTag = response.json()["tag"]
packageNameNew = handleRegexPackageName(packageName)
packageVersion = getlatestVersion(ressourceId)
packageDownloadName = f"{packageNameNew}-{packageVersion}.jar"
downloadPath = r"C:\\Users\Jan-Luca\Desktop\\"
downloadLatestVersion(ressourceId, packageDownloadName, downloadPath)
consoleTitle()
inputMainMenu()
outputTest()
# get latest update > https://api.spiget.org/v2/resources/28140/updates/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

View File

@ -3,40 +3,94 @@ import re
import requests
#from consoleoutput import consoleTitle, clearConsole
#from plugin_downloader import handleInput
from plugin_downloader import getLatestPackageVersion #handleInput
def getInstalledPackages(pluginFolderPath):
pluginList = os.listdir(pluginFolderPath)
print(pluginList)
for plugin in pluginList:
print(plugin)
getInstalledPluginVersion(plugin)
# as seen on https://pythonguides.com/create-list-in-python/
class installedPlugin:
def __init__(self, pluginId, plugin_is_outdated):
self.pluginId = pluginId
self.plugin_is_outdated = plugin_is_outdated
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
pluginVersion = re.search(r'([\d.]+[.jar]+)', pluginNameFull)
pluginVersionFull = pluginVersion.group()
pluginVersionString = pluginVersionFull.replace('.jar', '')
pluginNameOnly = pluginNameFull.replace(pluginVersionFull, '')
pluginNameOnly = pluginNameOnly[:-1]
print(pluginNameOnly)
print(pluginVersionString)
response = requests.get("https://api.spiget.org/v2/search/resources/" + pluginNameOnly + "?field=name")
return pluginVersionString
# not yet implemented
def compareVersions(pluginVersion, pluginId, updateId):
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
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()
i = 1
plugin_match_found = False
pluginID = None
for ressource in packageName:
if plugin_match_found == True:
break
pName = ressource["name"]
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
return pluginID
# start query
# get id
# search with id for all version upaates
# search with id for all version upates
# get version that matches installed version
# if match then download latest update
# else get second query