Permet de donner un conseil chaque jour.. Pour améliorer notre quotidien, Ou pas.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

37 lines
951 B

  1. import requests
  2. from config import advice_api
  3. import time
  4. def fetch_advice():
  5. print("Getting new advice...")
  6. request = requests.get(advice_api)
  7. if str(request) != '<Response [200]>' :
  8. print("Mauvaise réponse de l'api !(Check_Latest) ")
  9. return False
  10. advice = request.json()['slip']['advice']
  11. return advice
  12. def create_file(message):
  13. with open('cache_advice', "a") as write_file:
  14. write_file.write('\n')
  15. write_file.write(message)
  16. def main():
  17. t = time.localtime()
  18. current_time = int(time.strftime("%H", t))
  19. print("it's : ",current_time)
  20. while current_time != 23 :
  21. current_time = int(time.strftime("%H", t))
  22. time.sleep(3600)
  23. advice = fetch_advice()
  24. print(advice)
  25. create_file(advice)
  26. t = time.localtime()
  27. current_time = time.strftime("%H", t)
  28. time.sleep(3600)
  29. if __name__ == '__main__':
  30. try :
  31. main()
  32. except :
  33. main()