|
|
|
@@ -1,27 +1,37 @@ |
|
|
|
import requests
|
|
|
|
from config import advice_api
|
|
|
|
import os
|
|
|
|
|
|
|
|
def fetch_advice():
|
|
|
|
print("Getting new advice...")
|
|
|
|
request = requests.get(advice_api)
|
|
|
|
if str(request) != '<Response [200]>' :
|
|
|
|
print("Mauvaise réponse de l'api !(Check_Latest) ")
|
|
|
|
return False
|
|
|
|
print(u"réponse correcte !")
|
|
|
|
advice = request.json()['slip']['advice']
|
|
|
|
return advice
|
|
|
|
|
|
|
|
def create_file(message):
|
|
|
|
with open('cache_advice', "a") as write_file:
|
|
|
|
write_file.write('\n')
|
|
|
|
write_file.write(message)
|
|
|
|
|
|
|
|
def main():
|
|
|
|
print("Nothing to do here")
|
|
|
|
advice = fetch_advice()
|
|
|
|
print(advice)
|
|
|
|
create_file(advice)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main() |
|
|
|
import requests |
|
|
|
from config import advice_api |
|
|
|
import time |
|
|
|
|
|
|
|
def fetch_advice(): |
|
|
|
print("Getting new advice...") |
|
|
|
request = requests.get(advice_api) |
|
|
|
if str(request) != '<Response [200]>' : |
|
|
|
print("Mauvaise réponse de l'api !(Check_Latest) ") |
|
|
|
return False |
|
|
|
advice = request.json()['slip']['advice'] |
|
|
|
return advice |
|
|
|
|
|
|
|
def create_file(message): |
|
|
|
with open('cache_advice', "a") as write_file: |
|
|
|
write_file.write('\n') |
|
|
|
write_file.write(message) |
|
|
|
|
|
|
|
def main(): |
|
|
|
t = time.localtime() |
|
|
|
current_time = int(time.strftime("%H", t)) |
|
|
|
print("it's : ",current_time) |
|
|
|
while current_time != 23 : |
|
|
|
current_time = int(time.strftime("%H", t)) |
|
|
|
time.sleep(3600) |
|
|
|
advice = fetch_advice() |
|
|
|
print(advice) |
|
|
|
create_file(advice) |
|
|
|
t = time.localtime() |
|
|
|
current_time = time.strftime("%H", t) |
|
|
|
time.sleep(3600) |
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
try : |
|
|
|
main() |
|
|
|
except : |
|
|
|
main() |