Advertisement
arthurcluet

Untitled

Apr 6th, 2022
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. import json
  2. import requests
  3. from datetime import datetime
  4. import matplotlib.pyplot as plt
  5. import time
  6. import tkinter
  7. from tkinter import *
  8.  
  9. url = "http://www.infoclimat.fr/public-api/gfs/json?_ll=48.85341,2.3488&_auth=ABpWQQB%2BASNSfwM0B3EBKFA4AjcKfAkuC3dSMVw5B3oAa18%2BVTVcOlE%2FVyoPIFJkBCkHZAswAzMGbVYuAHJQMQBqVjoAawFmUj0DZgcoASpQfgJjCioJLgtgUjdcLwdlAGFfP1UoXDxRPFc8DyFSZAQzB2ULKwMkBmRWNwBpUDoAYVY3AGoBalI8A2AHKAEqUGUCYAoxCWULOlIwXDkHYwAwXz9VM1w3UTlXNw8hUm4EMwdiCz0DOQZkVjcAaFAsAHxWSwAQAX5SfQMjB2IBc1B%2BAjcKawll&_c=1a829a71b0d073a24733b872449b9bbd"
  10.  
  11. try:
  12. api_request = requests.get(url)
  13. data = json.loads(api_request.content)
  14. except Exception as e:
  15. data = "erreur"
  16.  
  17. if(type(data) == dict):
  18. keys = ["request_state", "request_key", "message", "model_run", "source"]
  19. if(all([key in data for key in keys]) and data["request_state"] == 200):
  20. for key in keys:
  21. del data[key]
  22. # print(type(data["2022-04-09 23:00:00"]))
  23. print(data["2022-04-09 23:00:00"]["temperature"]["2m"])
  24. print(data["2022-04-09 23:00:00"]["temperature"]["sol"])
  25. print(data["2022-04-09 23:00:00"]["humidite"]["2m"])
  26. dt = datetime.strptime("2022-04-09 23:00:00", "%Y-%m-%d %H:%M:%S")
  27.  
  28. lesDates, lesTempA2m, lesTempAuSol, lesHumiditesA2m = [], [], [], []
  29.  
  30. for key, value in data.items():
  31. lesDates.append(datetime.strptime(key, "%Y-%m-%d %H:%M:%S"))
  32. lesTempA2m.append(value["temperature"]["2m"] - 273.15)
  33. lesTempAuSol.append(value["temperature"]["sol"] - 273.15)
  34. lesHumiditesA2m.append(value["humidite"]["2m"])
  35.  
  36. fig, (ax1, ax2) = plt.subplots(2)
  37. ax1.plot(lesDates, lesTempA2m)
  38. ax1.plot(lesDates, lesTempAuSol)
  39. ax2.plot(lesDates, lesHumiditesA2m)
  40. # plt.show()
  41.  
  42. else:
  43. print("Clรฉs manquantes")
  44. else:
  45. print("erreur")
  46.  
  47.  
  48. def mon_decorateur(fonction):
  49. def inner(*param, **param2):
  50. print("Action avant .............. ")
  51. fonction(*param, **param2)
  52. print("Action aprรจs ..............")
  53. return inner
  54.  
  55.  
  56. def profiler(fonction):
  57. def inner(*param, **param2):
  58. start = time.time()
  59. fonction(*param, **param2)
  60. end = time.time()
  61. print(str((end - start) * 1000) + "ms")
  62. return inner
  63.  
  64.  
  65. @profiler
  66. def Affichage(v):
  67. print("Execution des instructions", v)
  68.  
  69.  
  70. liste = [1, 2, 3, 4]
  71. Affichage(liste)
  72.  
  73. fenetre = Tk()
  74. monlabel = Label(fenetre, text="premier code tkinter")
  75. monlabel.pack()
  76. fenetre.mainloop()
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement