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.

27 lines
697 B

  1. import requests
  2. from config import advice_api
  3. import os
  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. print(u"réponse correcte !")
  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. print("Nothing to do here")
  19. advice = fetch_advice()
  20. print(advice)
  21. create_file(advice)
  22. if __name__ == '__main__':
  23. main()