115 lines
2.5 KiB
Python
115 lines
2.5 KiB
Python
import requests
|
|
import json
|
|
import socket
|
|
import netifaces
|
|
|
|
## https://www.nylas.com/blog/use-python-requests-module-rest-apis/#how-to-use-python-requests
|
|
## https://www.abstractapi.com/guides/ip-geolocation/get-ip-address-python
|
|
|
|
def ip():
|
|
|
|
try:
|
|
|
|
public_ip = requests.get('https://api.ipify.org').text
|
|
|
|
print(f"Public IP Address: {public_ip}")
|
|
|
|
return public_ip
|
|
|
|
except requests.RequestException as e:
|
|
|
|
print(f"Error retrieving public IP address: {e}")
|
|
|
|
return None
|
|
|
|
def hostname():
|
|
|
|
try:
|
|
|
|
return socket.gethostname()
|
|
|
|
except Exception as e:
|
|
|
|
print(f"Error getting hostname: {e}")
|
|
|
|
return "unknown_host"
|
|
|
|
def addDownloadSuccess(url):
|
|
|
|
print("enter -> addDownloadSuccess()")
|
|
|
|
print("param / url / ",url)
|
|
|
|
data = {"url": url, "hostIP": ip(),"ip": ip(),"hostName":hostname()}
|
|
|
|
json_data = json.dumps(data)
|
|
|
|
print("param / data / ",data)
|
|
|
|
print("param / data / ",json_data)
|
|
|
|
headers = {"Content-Type": "application/json"}
|
|
|
|
response = requests.post("https://apis.yankee.embanet.online/channel/monthly/games/success/add", data=json_data, headers=headers)
|
|
|
|
print(response.text)
|
|
|
|
|
|
def addDownloadFailure(url, error):
|
|
|
|
print("enter -> addDownloadFailure()")
|
|
|
|
print("param / url / ",url)
|
|
|
|
print("param / error / ",error)
|
|
|
|
data = {"url": url, "hostIP": ip(),"ip": ip(),"hostName":hostname(), "reason":error}
|
|
|
|
json_data = json.dumps(data)
|
|
|
|
print("param / data / ",data)
|
|
|
|
print("param / data / ",json_data)
|
|
|
|
headers = {"Content-Type": "application/json"}
|
|
|
|
response = requests.post("https://apis.yankee.embanet.online/channel/monthly/games/failure/add", data=json_data, headers=headers)
|
|
|
|
print(response.text)
|
|
|
|
def searchURLSuccesses(url):
|
|
|
|
## print("enter -> callGET()")
|
|
|
|
## print("param / url / ",url)
|
|
|
|
data = { "url": url }
|
|
|
|
headers = {"Content-Type": "application/json"}
|
|
|
|
json_data = json.dumps(data)
|
|
|
|
response = requests.post("https://apis.yankee.embanet.online/channel/monthly/games/success/exists", data=json_data, headers=headers)
|
|
|
|
## print(response.text)
|
|
|
|
return response.text
|
|
|
|
def searchURLFailures(url):
|
|
|
|
## print("enter -> callGET()")
|
|
|
|
## print("param / url / ",url)
|
|
|
|
data = { "url": url }
|
|
|
|
headers = {"Content-Type": "application/json"}
|
|
|
|
json_data = json.dumps(data)
|
|
|
|
response = requests.post("https://apis.yankee.embanet.online/channel/monthly/games/failure/exists", data=json_data, headers=headers)
|
|
|
|
## print(response.text)
|
|
|
|
return response.text
|