I am creating a flask app that pulls json from an api and displays the data. I have set it up so the python script that fetchs the json data runs and then sleeps for 20 seconds
jsondata.py:
import json
import requests
import time
def rti():
while True:
r = requests.get('api-link')
jsond = json.loads(r.text)
with open('static/json/rti.json', 'w') as f:
json.dump(jsond, f)
time.sleep(20)
here is my main file that imports this function
main.py:
from flask import Flask, render_template
import jsondata
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
if __name__ == "__main__":
app.run(debug=True)
jsondata.rti()
my problem is, when i run jsondata.py separately through the terminal it fetches and loads the new data every 20 seconds as expected, but when its called through main.py, it will only fetch the data once.
Aucun commentaire:
Enregistrer un commentaire