Created
April 21, 2023 13:45
-
-
Save MaxClerkwell/1100d5ece92b3507690ff7574f870b53 to your computer and use it in GitHub Desktop.
Zechen fetch and sort
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import sys | |
def fetch_data(api_url): | |
response = requests.get(api_url) | |
data = response.json() | |
return data | |
def sort_data(data, column): | |
try: | |
sorted_data = sorted(data, key=lambda x: x[column]) | |
return sorted_data | |
except KeyError: | |
print(f"Ungültige Spaltenüberschrift: {column}") | |
sys.exit(1) | |
def print_data(sorted_data): | |
for entry in sorted_data: | |
print(entry) | |
if __name__ == "__main__": | |
if len(sys.argv) != 2: | |
print("Bitte geben Sie eine Spaltenüberschrift als Kommandozeilenparameter an.") | |
sys.exit(1) | |
column = sys.argv[1] | |
api_url = "http://172.105.71.49/get_data/" # Ersetzen Sie dies durch die URL Ihrer FastAPI-Anwendung | |
data = fetch_data(api_url) | |
sorted_data = sort_data(data, column) | |
print_data(sorted_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment