ABS Python 26.04.2023

Podrzucam kod z dzisiejszych zaj臋膰:

import requests

response = requests.get("https://api.spacexdata.com/v5/launches")

launches = response.json()

data = {}

for launch in launches[::5]:
    date = launch['date_utc']
    payload_ids = launch['payloads']

    for _id in payload_ids:
        response2 = requests.get(f"https://api.spacexdata.com/v4/payloads/{_id}")
        payload = response2.json()
        mass_kg = payload['mass_kg']
        # print(date, _id, mass_kg)
        if mass_kg is None:
            mass_kg = 0
        if date in data:
            data[date] = mass_kg + data[date]
        else:
            data[date] = mass_kg

import matplotlib.pyplot as plt

# Create a dictionary
# data = {date:mass_kg}

# Extract keys and values
years = list(data.keys())
values = list(data.values())

# Create a bar plot
plt.bar(years, values)

# Set the x-axis label
plt.xlabel('Date')

# Set the y-axis label
plt.ylabel('Mass in kg')

# Set the title of the plot
plt.title('My Plot')

# Show the plot
plt.show()

Reactions: pink_heart 脳2 (AleksandraDzSz, Asia_Lena) 路 pepelove 脳1 (AleksandraDzSz)