mirror of
https://github.com/projecthorus/sondehub-infra.git
synced 2025-02-21 17:26:37 +00:00
Add files via upload
This commit is contained in:
parent
693e5f064e
commit
112e21f701
@ -9,8 +9,12 @@ params = "?token={}&period=2".format(apiKey)
|
|||||||
url = "https://radiosondy.info/api/v1/sonde-logs{}".format(params)
|
url = "https://radiosondy.info/api/v1/sonde-logs{}".format(params)
|
||||||
recoveryUrl = "https://api.v2.sondehub.org/recovered"
|
recoveryUrl = "https://api.v2.sondehub.org/recovered"
|
||||||
searchUrl = "https://api.v2.sondehub.org/sondes"
|
searchUrl = "https://api.v2.sondehub.org/sondes"
|
||||||
response = urllib.request.urlopen(url)
|
|
||||||
data = json.load(response)
|
# Main function
|
||||||
|
def handler(event,context):
|
||||||
|
response = urllib.request.urlopen(url)
|
||||||
|
data = json.load(response)
|
||||||
|
processReports()
|
||||||
|
|
||||||
# Check exisiting SondeHub recovery reports
|
# Check exisiting SondeHub recovery reports
|
||||||
def checkExisting(serial, recovered):
|
def checkExisting(serial, recovered):
|
||||||
@ -58,57 +62,58 @@ def findSonde(recovery, lat, lon):
|
|||||||
return serial
|
return serial
|
||||||
|
|
||||||
# Process each recovery report from Radiosondy.info
|
# Process each recovery report from Radiosondy.info
|
||||||
for recovery in data["results"]:
|
def processReports():
|
||||||
|
for recovery in data["results"]:
|
||||||
|
|
||||||
# Get recovery status
|
# Get recovery status
|
||||||
if recovery["status"] == "FOUND":
|
if recovery["status"] == "FOUND":
|
||||||
recovered = True
|
recovered = True
|
||||||
elif recovery["status"] == "NEED ATTENTION":
|
elif recovery["status"] == "NEED ATTENTION":
|
||||||
recovered = False
|
recovered = False
|
||||||
else:
|
else:
|
||||||
continue
|
|
||||||
|
|
||||||
# Get finder if available
|
|
||||||
if recovery["log_info"]["finder"] is not None:
|
|
||||||
recovered_by = recovery["log_info"]["finder"]
|
|
||||||
else:
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Import time
|
|
||||||
recovered_time = datetime.strptime(recovery["log_info"]["log_added"], "%Y-%m-%d %H:%M:%S")
|
|
||||||
|
|
||||||
# Get comment and add attribution
|
|
||||||
description = recovery["log_info"]["comment"]
|
|
||||||
description += " [via Radiosondy.info]"
|
|
||||||
description = description.lstrip()
|
|
||||||
|
|
||||||
if recovery["log_info"]["found_coordinates"]["latitude"] != "0" and recovery["log_info"]["found_coordinates"]["longitude"] != "0":
|
|
||||||
lat = float(recovery["log_info"]["found_coordinates"]["latitude"])
|
|
||||||
lon = float(recovery["log_info"]["found_coordinates"]["longitude"])
|
|
||||||
else:
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Use the reported serial number for RS41/RS92
|
|
||||||
if "RS41" in recovery["type"] or "RS92" in recovery["type"]:
|
|
||||||
serial = recovery["sonde_number"]
|
|
||||||
# Try to find serial in SondeHub database for others
|
|
||||||
else:
|
|
||||||
serial = findSonde(recovery, lat, lon)
|
|
||||||
if serial is None:
|
|
||||||
print("{}: could not match to SondeHub serial".format(recovery["sonde_number"]))
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Check if a valid recovery already exists
|
# Get finder if available
|
||||||
if checkExisting(serial, recovered) == False:
|
if recovery["log_info"]["finder"] is not None:
|
||||||
print("{}: recovery already exists".format(serial))
|
recovered_by = recovery["log_info"]["finder"]
|
||||||
continue
|
else:
|
||||||
|
continue
|
||||||
|
|
||||||
# Format data for upload
|
# Import time
|
||||||
recoveryPutData = {"datetime": recovered_time.isoformat(), "serial": serial, "lat": lat, "lon": lon, "recovered": recovered, "recovered_by": recovered_by, "description": description}
|
recovered_time = datetime.strptime(recovery["log_info"]["log_added"], "%Y-%m-%d %H:%M:%S")
|
||||||
recoveryPutData = str(json.dumps(recoveryPutData)).encode('utf-8')
|
|
||||||
print("{}: {}".format(serial, recoveryPutData))
|
# Get comment and add attribution
|
||||||
|
description = recovery["log_info"]["comment"]
|
||||||
# Upload data
|
description += " [via Radiosondy.info]"
|
||||||
recoveryPutRequest = urllib.request.Request(recoveryUrl, data=recoveryPutData, method="PUT")
|
description = description.lstrip()
|
||||||
print("{}: {}".format(serial, urllib.request.urlopen(recoveryPutRequest).read().decode('utf-8')))
|
|
||||||
|
if recovery["log_info"]["found_coordinates"]["latitude"] != "0" and recovery["log_info"]["found_coordinates"]["longitude"] != "0":
|
||||||
|
lat = float(recovery["log_info"]["found_coordinates"]["latitude"])
|
||||||
|
lon = float(recovery["log_info"]["found_coordinates"]["longitude"])
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Use the reported serial number for RS41/RS92
|
||||||
|
if "RS41" in recovery["type"] or "RS92" in recovery["type"]:
|
||||||
|
serial = recovery["sonde_number"]
|
||||||
|
# Try to find serial in SondeHub database for others
|
||||||
|
else:
|
||||||
|
serial = findSonde(recovery, lat, lon)
|
||||||
|
if serial is None:
|
||||||
|
print("{}: could not match to SondeHub serial".format(recovery["sonde_number"]))
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Check if a valid recovery already exists
|
||||||
|
if checkExisting(serial, recovered) == False:
|
||||||
|
print("{}: recovery already exists".format(serial))
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Format data for upload
|
||||||
|
recoveryPutData = {"datetime": recovered_time.isoformat(), "serial": serial, "lat": lat, "lon": lon, "recovered": recovered, "recovered_by": recovered_by, "description": description}
|
||||||
|
recoveryPutData = str(json.dumps(recoveryPutData)).encode('utf-8')
|
||||||
|
print("{}: {}".format(serial, recoveryPutData))
|
||||||
|
|
||||||
|
# Upload data
|
||||||
|
recoveryPutRequest = urllib.request.Request(recoveryUrl, data=recoveryPutData, method="PUT")
|
||||||
|
print("{}: {}".format(serial, urllib.request.urlopen(recoveryPutRequest).read().decode('utf-8')))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user