mirror of
https://gitlab.com/MisterBiggs/multi-bot-tutorial.git
synced 2025-06-16 07:06:51 +00:00
41 lines
1019 B
Python
41 lines
1019 B
Python
import requests
|
|
from datetime import datetime
|
|
|
|
|
|
def nextLaunch():
|
|
"""Uses the launchlibrary.net api to get the next rocket launch and returns
|
|
a dictionary with all the important information.
|
|
|
|
Example Output:
|
|
{
|
|
"rocket": "Proton-M/Blok DM-03 ",
|
|
"mission": " Spektr-RG",
|
|
"date": "July 12, 2019 12:31:00 UTC",
|
|
"countdown": "15:00:03.884469",
|
|
"video": "https://www.youtube.com/watch?v=Dy1nkGghEVk",
|
|
}
|
|
"""
|
|
|
|
url = "https://launchlibrary.net/1.4/launch/next/1?mode=list"
|
|
response = requests.get(url)
|
|
|
|
if response.status_code is 200:
|
|
data = response.json()["launches"][0]
|
|
|
|
rocket, mission = data["name"].split("|")
|
|
date = data["net"]
|
|
countdown = datetime.strptime(date, "%B %d, %Y %H:%M:%S %Z") - datetime.today()
|
|
|
|
else:
|
|
print("error")
|
|
|
|
launch = {
|
|
"rocket": rocket,
|
|
"mission": mission,
|
|
"date": date,
|
|
"countdown": str(countdown),
|
|
"video": data["vidURLs"][0],
|
|
}
|
|
return launch
|
|
|