Fix IPv6 weirdness?
This commit is contained in:
parent
e350811b05
commit
b6fd956cc3
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[submodule "request_wrapper"]
|
||||||
|
path = request_wrapper
|
||||||
|
url = https://gitlab.com/snippets/1900824.git
|
2
mcUp.py
2
mcUp.py
@ -1,6 +1,8 @@
|
|||||||
#!/bin/python
|
#!/bin/python
|
||||||
# Setup Parser
|
# Setup Parser
|
||||||
import requests
|
import requests
|
||||||
|
#import socket
|
||||||
|
#from request_wrapper import requests_wrapper as requests
|
||||||
from re import sub
|
from re import sub
|
||||||
import parsers.paperMC
|
import parsers.paperMC
|
||||||
import parsers.modrinth
|
import parsers.modrinth
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
from os import error
|
from os import error
|
||||||
|
from types import WrapperDescriptorType
|
||||||
from pytz.tzinfo import memorized_timedelta
|
from pytz.tzinfo import memorized_timedelta
|
||||||
import requests
|
#import requests
|
||||||
|
import socket
|
||||||
|
from request_wrapper import requests_wrapper as requests
|
||||||
import datetime
|
import datetime
|
||||||
import iso8601
|
import iso8601
|
||||||
import pytz
|
import pytz
|
||||||
debug = False
|
debug = True
|
||||||
if debug == True:
|
if debug == True:
|
||||||
import logging
|
import logging
|
||||||
from requests import api
|
from requests import api
|
||||||
@ -14,7 +17,7 @@ if debug == True:
|
|||||||
requests_log.setLevel(logging.DEBUG)
|
requests_log.setLevel(logging.DEBUG)
|
||||||
requests_log.propagate = True
|
requests_log.propagate = True
|
||||||
timeoutTime = 1
|
timeoutTime = 1
|
||||||
base_api_url = "https://api.modrinth.com/api/v1"
|
base_api_url = "https://api.modrinth.com:443/api/v1"
|
||||||
def failCheck(response):
|
def failCheck(response):
|
||||||
print("Status Code is: "+str(response.status_code))
|
print("Status Code is: "+str(response.status_code))
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
@ -24,12 +27,14 @@ dataCache = {}
|
|||||||
def cacheData(function_name, cached_data):
|
def cacheData(function_name, cached_data):
|
||||||
print("Caching data!")
|
print("Caching data!")
|
||||||
dataCache[function_name] = cached_data
|
dataCache[function_name] = cached_data
|
||||||
|
print("Stored "+function_name+"'s data to cache")
|
||||||
#
|
#
|
||||||
def modInfo(project):
|
def modInfo(project):
|
||||||
print("Calling modInfo()...")
|
print("Calling modInfo()...")
|
||||||
if "modInfo" in dataCache:
|
if "modInfo" in dataCache:
|
||||||
|
print("Returning cached data!")
|
||||||
return dataCache["modInfo"]
|
return dataCache["modInfo"]
|
||||||
response = requests.get(base_api_url+"/mod/"+project)
|
response = requests.get(base_api_url+"/mod/"+project, family=socket.AF_INET)
|
||||||
failCheck(response)
|
failCheck(response)
|
||||||
api_response = response.json()
|
api_response = response.json()
|
||||||
cacheData("modInfo", api_response)
|
cacheData("modInfo", api_response)
|
||||||
@ -38,6 +43,7 @@ def modInfo(project):
|
|||||||
def getVersions(project):
|
def getVersions(project):
|
||||||
print("Calling getVersions()...")
|
print("Calling getVersions()...")
|
||||||
if "getVersions" in dataCache:
|
if "getVersions" in dataCache:
|
||||||
|
print("Returning cached data!")
|
||||||
return dataCache["getVersions"]
|
return dataCache["getVersions"]
|
||||||
workingDict = modInfo(project)
|
workingDict = modInfo(project)
|
||||||
versions = workingDict["versions"]
|
versions = workingDict["versions"]
|
||||||
@ -47,18 +53,21 @@ def getVersions(project):
|
|||||||
def getAllModVersionInfo(project):
|
def getAllModVersionInfo(project):
|
||||||
print("Calling getAllModVersionInfo()...")
|
print("Calling getAllModVersionInfo()...")
|
||||||
if "getAllModVersionInfo" in dataCache:
|
if "getAllModVersionInfo" in dataCache:
|
||||||
|
print("Returning cached data!")
|
||||||
return dataCache["getAllMinecraftVersionInfo"]
|
return dataCache["getAllMinecraftVersionInfo"]
|
||||||
versions = getVersions(project)
|
versions = getVersions(project)
|
||||||
responseList = []
|
responseList = []
|
||||||
numberOfVersions = len(versions)
|
numberOfVersions = len(versions)
|
||||||
for item in range(numberOfVersions):
|
for item in range(numberOfVersions):
|
||||||
response = requests.get(base_api_url+"/version/"+versions[item])
|
response = requests.get(base_api_url+"/version/"+versions[item], family=socket.AF_INET)
|
||||||
|
failCheck(response)
|
||||||
api_response = response.json()
|
api_response = response.json()
|
||||||
responseList.append(api_response)
|
responseList.append(api_response)
|
||||||
cacheData("getAllMinecraftVersionInfo", responseList)
|
cacheData("getAllMinecraftVersionInfo", responseList)
|
||||||
return responseList
|
return responseList
|
||||||
|
|
||||||
def determine(project, whatToDetermine):
|
def determine(project, whatToDetermine):
|
||||||
|
print("Calling determine()...")
|
||||||
modInfo = getAllModVersionInfo(project)
|
modInfo = getAllModVersionInfo(project)
|
||||||
numberOfVersions = len(modInfo)
|
numberOfVersions = len(modInfo)
|
||||||
determine = []
|
determine = []
|
||||||
@ -69,6 +78,7 @@ def determine(project, whatToDetermine):
|
|||||||
return determine
|
return determine
|
||||||
|
|
||||||
def getLatestVersion(project):
|
def getLatestVersion(project):
|
||||||
|
print("Calling getLatestVersion()...")
|
||||||
versions = getVersions(project)
|
versions = getVersions(project)
|
||||||
publishDates = determine(project, "date_published")
|
publishDates = determine(project, "date_published")
|
||||||
#print(publishDates)
|
#print(publishDates)
|
||||||
@ -89,6 +99,7 @@ def getLatestVersion(project):
|
|||||||
return list(latest.keys())[0]
|
return list(latest.keys())[0]
|
||||||
|
|
||||||
def getDownloadURL(project, versionID):
|
def getDownloadURL(project, versionID):
|
||||||
|
print("Calling getDownloadURL()...")
|
||||||
versions = getVersions(project)
|
versions = getVersions(project)
|
||||||
versionInfo = getAllModVersionInfo(project)
|
versionInfo = getAllModVersionInfo(project)
|
||||||
downloadURLs = {}
|
downloadURLs = {}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
from os import error
|
from os import error
|
||||||
import requests
|
#import requests
|
||||||
debug = False
|
import socket
|
||||||
|
from request_wrapper import requests_wrapper as requests
|
||||||
|
debug = True
|
||||||
if debug == True:
|
if debug == True:
|
||||||
import logging
|
import logging
|
||||||
from requests import api
|
from requests import api
|
||||||
@ -10,7 +12,7 @@ if debug == True:
|
|||||||
requests_log.setLevel(logging.DEBUG)
|
requests_log.setLevel(logging.DEBUG)
|
||||||
requests_log.propagate = True
|
requests_log.propagate = True
|
||||||
timeoutTime = 1
|
timeoutTime = 1
|
||||||
base_api_url = "https://papermc.io/api/v2"
|
base_api_url = "https://papermc.io:443/api/v2"
|
||||||
def failCheck(response):
|
def failCheck(response):
|
||||||
print("Status Code is: "+str(response.status_code))
|
print("Status Code is: "+str(response.status_code))
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
@ -20,12 +22,13 @@ dataCache = {}
|
|||||||
def cacheData(function_name, cached_data):
|
def cacheData(function_name, cached_data):
|
||||||
print("Caching data!")
|
print("Caching data!")
|
||||||
dataCache[function_name] = cached_data
|
dataCache[function_name] = cached_data
|
||||||
|
print("Stored "+function_name+"'s data to cache")
|
||||||
# This function returns the versions from a project from the Paper API.
|
# This function returns the versions from a project from the Paper API.
|
||||||
def getVersions(project):
|
def getVersions(project):
|
||||||
print("Calling getVersions()...")
|
print("Calling getVersions()...")
|
||||||
if "getVersions" in dataCache:
|
if "getVersions" in dataCache:
|
||||||
return dataCache["getVersions"]
|
return dataCache["getVersions"]
|
||||||
response = requests.get(base_api_url+"/projects/"+project, timeout=timeoutTime)
|
response = requests.get(base_api_url+"/projects/"+project, family=socket.AF_INET, timeout=timeoutTime)
|
||||||
failCheck(response)
|
failCheck(response)
|
||||||
api_response = response.json()
|
api_response = response.json()
|
||||||
cacheData("getVersions", api_response['versions'])
|
cacheData("getVersions", api_response['versions'])
|
||||||
@ -40,7 +43,7 @@ def getBuildNumber(project, version):
|
|||||||
print("Calling getBuildNumber()...")
|
print("Calling getBuildNumber()...")
|
||||||
if "getBuildNumber" in dataCache:
|
if "getBuildNumber" in dataCache:
|
||||||
return dataCache["getBuildNumber"]
|
return dataCache["getBuildNumber"]
|
||||||
response = requests.get(base_api_url+"/projects/"+project+"/versions/"+version, timeout=timeoutTime)
|
response = requests.get(base_api_url+"/projects/"+project+"/versions/"+version, family=socket.AF_INET, timeout=timeoutTime)
|
||||||
failCheck(response)
|
failCheck(response)
|
||||||
api_response = response.json()
|
api_response = response.json()
|
||||||
cacheData("getBuildNumber", api_response['builds'])
|
cacheData("getBuildNumber", api_response['builds'])
|
||||||
@ -52,7 +55,7 @@ def getBuildInfo(project, version):
|
|||||||
return dataCache["getBuildInfo"]
|
return dataCache["getBuildInfo"]
|
||||||
buildID1 = getBuildNumber(project, version)
|
buildID1 = getBuildNumber(project, version)
|
||||||
buildID = str(buildID1[-1])
|
buildID = str(buildID1[-1])
|
||||||
response = requests.get(base_api_url+"/projects/"+project+"/versions/"+version+"/builds/"+buildID, timeout=timeoutTime)
|
response = requests.get(base_api_url+"/projects/"+project+"/versions/"+version+"/builds/"+buildID, family=socket.AF_INET, timeout=timeoutTime)
|
||||||
failCheck(response)
|
failCheck(response)
|
||||||
api_response = response.json()
|
api_response = response.json()
|
||||||
cacheData("getBuildInfo", api_response)
|
cacheData("getBuildInfo", api_response)
|
||||||
@ -70,7 +73,7 @@ def downloadVersion(project, version):
|
|||||||
jarName = getJarInfo(project, version)
|
jarName = getJarInfo(project, version)
|
||||||
buildID1 = getBuildNumber(project, version)
|
buildID1 = getBuildNumber(project, version)
|
||||||
buildID = str(buildID1[-1])
|
buildID = str(buildID1[-1])
|
||||||
response = requests.get(base_api_url+"/projects/"+project+"/versions/"+version+"/builds/"+buildID+"/downloads/"+jarName["name"], stream=True, timeout=timeoutTime)
|
response = requests.get(base_api_url+"/projects/"+project+"/versions/"+version+"/builds/"+buildID+"/downloads/"+jarName["name"], family=socket.AF_INET, stream=True, timeout=timeoutTime)
|
||||||
failCheck(response)
|
failCheck(response)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
1
request-wrapper
Submodule
1
request-wrapper
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit f2811c5ce989753e7a926f2849489941f21bb2c2
|
1
request_wrapper
Submodule
1
request_wrapper
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit f2811c5ce989753e7a926f2849489941f21bb2c2
|
Loading…
Reference in New Issue
Block a user