Permet de donner un conseil chaque jour.. Pour améliorer notre quotidien, Ou pas.
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

40 рядки
1.0 KiB

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