Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import requests
- from datetime import datetime
- import matplotlib.pyplot as plt
- import time
- import tkinter
- from tkinter import *
- url = "http://www.infoclimat.fr/public-api/gfs/json?_ll=48.85341,2.3488&_auth=ABpWQQB%2BASNSfwM0B3EBKFA4AjcKfAkuC3dSMVw5B3oAa18%2BVTVcOlE%2FVyoPIFJkBCkHZAswAzMGbVYuAHJQMQBqVjoAawFmUj0DZgcoASpQfgJjCioJLgtgUjdcLwdlAGFfP1UoXDxRPFc8DyFSZAQzB2ULKwMkBmRWNwBpUDoAYVY3AGoBalI8A2AHKAEqUGUCYAoxCWULOlIwXDkHYwAwXz9VM1w3UTlXNw8hUm4EMwdiCz0DOQZkVjcAaFAsAHxWSwAQAX5SfQMjB2IBc1B%2BAjcKawll&_c=1a829a71b0d073a24733b872449b9bbd"
- try:
- api_request = requests.get(url)
- data = json.loads(api_request.content)
- except Exception as e:
- data = "erreur"
- if(type(data) == dict):
- keys = ["request_state", "request_key", "message", "model_run", "source"]
- if(all([key in data for key in keys]) and data["request_state"] == 200):
- for key in keys:
- del data[key]
- # print(type(data["2022-04-09 23:00:00"]))
- print(data["2022-04-09 23:00:00"]["temperature"]["2m"])
- print(data["2022-04-09 23:00:00"]["temperature"]["sol"])
- print(data["2022-04-09 23:00:00"]["humidite"]["2m"])
- dt = datetime.strptime("2022-04-09 23:00:00", "%Y-%m-%d %H:%M:%S")
- lesDates, lesTempA2m, lesTempAuSol, lesHumiditesA2m = [], [], [], []
- for key, value in data.items():
- lesDates.append(datetime.strptime(key, "%Y-%m-%d %H:%M:%S"))
- lesTempA2m.append(value["temperature"]["2m"] - 273.15)
- lesTempAuSol.append(value["temperature"]["sol"] - 273.15)
- lesHumiditesA2m.append(value["humidite"]["2m"])
- fig, (ax1, ax2) = plt.subplots(2)
- ax1.plot(lesDates, lesTempA2m)
- ax1.plot(lesDates, lesTempAuSol)
- ax2.plot(lesDates, lesHumiditesA2m)
- # plt.show()
- else:
- print("Clรฉs manquantes")
- else:
- print("erreur")
- def mon_decorateur(fonction):
- def inner(*param, **param2):
- print("Action avant .............. ")
- fonction(*param, **param2)
- print("Action aprรจs ..............")
- return inner
- def profiler(fonction):
- def inner(*param, **param2):
- start = time.time()
- fonction(*param, **param2)
- end = time.time()
- print(str((end - start) * 1000) + "ms")
- return inner
- @profiler
- def Affichage(v):
- print("Execution des instructions", v)
- liste = [1, 2, 3, 4]
- Affichage(liste)
- fenetre = Tk()
- monlabel = Label(fenetre, text="premier code tkinter")
- monlabel.pack()
- fenetre.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement