123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- import datetime as datetime
- from emailtool.emailer import Emailer
- from flask import Flask, render_template, request, redirect, url_for
- import configparser
- from gevent.pywsgi import WSGIServer
- import socket
- config = configparser.ConfigParser()
- config.read('settings.ini')
- smtp_settings = config['smtp']
- http_settings = config['http']
- def send_email(to, subject, body):
- # Get settings from smtp_settings
- host = smtp_settings['host']
- port = smtp_settings['port']
- username = smtp_settings['username']
- password = smtp_settings['password']
- # Create an instance of the Emailer class
- emailer = Emailer(host, port, username, password)
- # Call the send_email method
- emailer.send_email(to, subject, body)
- app = Flask(__name__)
- # Create a route for the home page
- @app.route('/')
- def index():
- # send_email('aday@twinfallspubliclibrary.org', 'TEST', 'This is a test email')
- return render_template('index.html')
- # on exit of the program make sure the http server is stopped
- #@app.teardown_appcontext
- def shutdown_session(exception=None):
- print('Stopping HTTP Service...')
- http_server.stop()
- # Get the systems hostname
- def get_hostname():
- return socket.gethostname()
- # Get systems IP address
- def get_ip_address():
- return socket.gethostbyname(socket.gethostname())
- if __name__ == "__main__":
- print("Starting HTTP Service on port %s..." % http_settings['port'])
- http_server = WSGIServer(('0.0.0.0', int(http_settings['port'])), app)
- print("HTTP Service Started!")
- print("Access the Dashboard on http://%s:%s" % (get_hostname(), http_settings['port']))
- http_server.serve_forever()
|