Fixed input handling and added web_request file to simplify the code

This commit is contained in:
Neocky 2021-03-05 00:09:03 +01:00
parent 91e66792a3
commit f44f06a803
4 changed files with 58 additions and 45 deletions

View File

@ -5,16 +5,16 @@ from plugin_updatechecker import getInstalledPackages
def inputOption(inputOptionString):
if inputOptionString == "1":
ressourceID = input("SpigotMC Ressource ID: ")
return ressourceID
if inputOptionString == "2":
ressourceId = input("SpigotMC Ressource ID: ")
return ressourceId
if inputOptionString == "3":
ressourceName = input(" SpigotMC Ressource Name: ")
inputString = None
print(inputOptionString)
if inputOptionString == 1:
inputString = input("SpigotMC Ressource ID: ")
if inputOptionString == 2:
inputString = input("SpigotMC Ressource ID: ")
if inputOptionString == 3:
inputString = input(" SpigotMC Ressource Name: ")
print("ich bin ein test")
return ressourceName
return inputString
def handleInput(inputString):
@ -39,7 +39,6 @@ def inputMainMenu():
handleInput(inputSt)
def outputTest():
print("Hello world")
print("Waiting still seconds: 5", end='\r')

View File

@ -1,13 +1,13 @@
import urllib.request
import cgi
import re
import requests
from web_request import doAPIRequest
def calculateFileSize(downloadFileSize):
fileSizeDownload = int(downloadFileSize)
fileSizeMb = fileSizeDownload / 1024 / 1024
roundedFileSize = round(fileSizeMb, 2)
fileSizeKb = fileSizeDownload / 1024
roundedFileSize = round(fileSizeKb, 2)
return roundedFileSize
@ -30,7 +30,7 @@ def downloadPackageManual():
filename = params["filename"]
# creating file path
path = r"C:\\Users\USER\Desktop\\"
path = r"C:\\Users\Jan-Luca\Desktop\\"
ppath = path + filename
# download file
@ -61,18 +61,18 @@ def handleRegexPackageName(packageNameFull):
return packageNameOnly
def getlatestVersion(packageId):
response = requests.get(f"https://api.spiget.org/v2/resources/{packageId}/versions/latest")
#packageDetails = response.json()
packageVersion = response.json()["name"]
url = f"https://api.spiget.org/v2/resources/{packageId}/versions/latest"
response = doAPIRequest(url)
packageVersion = response["name"]
return packageVersion
def apiCallTest(ressourceId):
response = requests.get(f"https://api.spiget.org/v2/resources/{ressourceId}")
packageDetails = response.json()
print(packageDetails)
packageName = response.json()["name"]
packageTag = response.json()["tag"]
url = f"https://api.spiget.org/v2/resources/{ressourceId}"
response = doAPIRequest(url)
print(response)
packageName = response["name"]
packageTag = response["tag"]
print(packageName)
print(packageTag)
packageNameNew = handleRegexPackageName(packageName)
@ -87,21 +87,23 @@ def compareVersions():
def searchPackage(ressourceName):
response = requests.get(f"https://api.spiget.org/v2/search/resources/{ressourceName}?field=name")
#https://api.spiget.org/v2/search/resources/luckperms?field=name
print(f"https://api.spiget.org/v2/search/resources/{ressourceName}?field=name")
packageName = response.json()
url = f"https://api.spiget.org/v2/search/resources/{ressourceName}?field=name"
packageName = doAPIRequest(url)
print(url)
i = 1
print("Index / Name / Description / Downloads")
for ressource in packageName:
pName = ressource["name"]
print(f" [{i}] {pName}")
pTag = ressource["tag"]
pDownloads = ressource["downloads"]
print(f" [{i}] {pName} / {pTag}/ {pDownloads}")
i = i + 1
ressourceSelected = int(input(" Select your wanted Ressource: "))
ressourceSelected = ressourceSelected - 1
fileInfo = response.json()[ressourceSelected]["file"]
fileInfo = packageName[ressourceSelected]["file"]
packageUrl = fileInfo["url"]
ressourceId = response.json()[ressourceSelected]["id"]
ressourceId = packageName[ressourceSelected]["id"]
print(packageUrl)
print(ressourceId)
@ -115,15 +117,15 @@ def downloadLatestVersion(ressourceId, packageDownloadName, sourcePath):
filesizeData = calculateFileSize(filesize)
print(filesizeData)
print(filesize)
print(f" Downloadsize: {filesizeData} MB")
print(f" Downloadsize: {filesizeData} KB")
def getLatestPackageVersion(ressourceId, downloadPath):
#ressourceId = input(" SpigotMC Ressource ID: ")
response = requests.get(f"https://api.spiget.org/v2/resources/{ressourceId}")
packageDetails = response.json()
url = f"https://api.spiget.org/v2/resources/{ressourceId}"
packageDetails = doAPIRequest(url)
packageName = packageDetails["name"]
packageTag = packageDetails["tag"]
#packageTag = packageDetails["tag"]
packageNameNew = handleRegexPackageName(packageName)
packageVersion = getlatestVersion(ressourceId)
packageDownloadName = f"{packageNameNew}-{packageVersion}.jar"
@ -132,10 +134,10 @@ def getLatestPackageVersion(ressourceId, downloadPath):
def getLatestPackageVersionInteractive(downloadPath):
ressourceId = input(" SpigotMC Ressource ID: ")
response = requests.get(f"https://api.spiget.org/v2/resources/{ressourceId}")
packageDetails = response.json()
url = f"https://api.spiget.org/v2/resources/{ressourceId}"
packageDetails = doAPIRequest(url)
packageName = packageDetails["name"]
packageTag = packageDetails["tag"]
#packageTag = packageDetails["tag"]
packageNameNew = handleRegexPackageName(packageName)
packageVersion = getlatestVersion(ressourceId)
packageDownloadName = f"{packageNameNew}-{packageVersion}.jar"

View File

@ -1,9 +1,9 @@
import os
import re
import requests
from consoleoutput import oColors #consoleTitle, clearConsole
from plugin_downloader import getLatestPackageVersion #handleInput
from web_request import doAPIRequest
def createPluginList():
@ -35,8 +35,8 @@ def getFileVersion(pluginName):
def compareVersions(pluginId, pluginVersion):
responseUpdateSearch = requests.get(f"https://api.spiget.org/v2/resources/{pluginId}/versions/latest")
latestUpdateSearch = responseUpdateSearch.json()
url = f"https://api.spiget.org/v2/resources/{pluginId}/versions/latest"
latestUpdateSearch = doAPIRequest(url)
versionLatestUpdate = latestUpdateSearch["name"]
print(pluginVersion)
print(versionLatestUpdate)
@ -67,17 +67,20 @@ def getInstalledPackages(pluginFolderPath):
print(oColors.brightRed + "Couldn't find plugin id. Sorry :(" + oColors.standardWhite)
continue
if INSTALLEDPLUGINLIST[i][2] == True:
os.remove(f"C:\\Users\\USER\\Desktop\\plugins\\{plugin}")
getLatestPackageVersion(pluginId, r"C:\\Users\\USER\\Desktop\\plugins\\")
os.remove(f"C:\\Users\USER\\Desktop\\plugins\\{plugin}")
i = i + 1
print(INSTALLEDPLUGINLIST[1][0])
#getLatestPackageVersion(pluginID, r"C:\\Users\USER\Desktop\\plugins\\")
def getInstalledPlugin(localFileName, localFileVersion):
response = requests.get("https://api.spiget.org/v2/search/resources/" + localFileName + "?field=name")
#response = requests.get("https://api.spiget.org/v2/search/resources/" + localFileName + "?field=name")
url = "https://api.spiget.org/v2/search/resources/" + localFileName + "?field=name"
packageName = doAPIRequest(url)
#https://api.spiget.org/v2/search/resources/luckperms?field=name
print("https://api.spiget.org/v2/search/resources/" + localFileName + "?field=name")
packageName = response.json()
#packageName = response.json()
i = 1
plugin_match_found = False
pluginID = None
@ -87,8 +90,8 @@ def getInstalledPlugin(localFileName, localFileVersion):
pName = ressource["name"]
pID = ressource["id"]
print(f" [{i}] {pName} - {pID}")
response2 = requests.get(f"https://api.spiget.org/v2/resources/{pID}/versions?size=100&sort=-name")
packageVersions = response2.json()
url2 = f"https://api.spiget.org/v2/resources/{pID}/versions?size=100&sort=-name"
packageVersions = doAPIRequest(url2)
for updates in packageVersions:
updateVersion = updates["name"]
if localFileVersion == updateVersion:
@ -105,7 +108,7 @@ def getInstalledPlugin(localFileName, localFileVersion):
return pluginID
# start query
# start query
# get id
# search with id for all version upates
# get version that matches installed version

9
pluGET/web_request.py Normal file
View File

@ -0,0 +1,9 @@
import requests
#import urllib.request
def doAPIRequest(url):
headers = {'user-agent': 'pluGET'}
response = requests.get(url, headers=headers)
packageDetails = response.json()
return packageDetails