I am trying to display a website using Flask, but am running into a LookupError. It seems as if my index.html file is being treated as a module which cannot be imported. The goal is to retrieve weather information from an xml url, display on a webpage, and get new data every 10 seconds. I have a project folder containing a static folder, templates folder, and my init.py, main.py, and schedulerservice.py files. Outside of that folder is my app.py. The code I have so far is as follows:
app.py
from project.init import app
app.run(host='127.0.0.1', port=5000, debug=True)
init.py
from flask import Flask
app = Flask(__name__)
from .main import main as main_blueprint
app.register_blueprint(main_blueprint)
main.py
from flask import Blueprint, render_template
from project.scheduler service import scheduler
import urllib3
import xmltodict
main = Blueprint('main', __name__)
@main.route('/')
def get_weather():
scheduler.add_job(func=get_weather(), trigger='interval', seconds=10, timezone='US/Eastern') # breaks if you do not specify timezone
def get_weather():
http = urllib3.PoolManager()
url = str(open('url.txt', 'r').read())
headers = urllib3.make_headers(basic_auth=str(open('userpass.txt', 'r').read())
response = http.request('GET', url, headers=headers)
data = xmltodict.parse(response.data)
temperature = data['logger']['TH']['@temp']
return render_template('index.html', temperature=temperature)
schedulerservice.py
from apscheduler.schedulers.background import BackgroundScheduler
scheduler = BackgroundScheduler(daemon=True)
scheduler.start()
Error message (skipping middle chunk of html):