refractoring
This commit is contained in:
13
app.py
13
app.py
@@ -1,3 +1,4 @@
|
||||
import calendar_interface
|
||||
import sqlite3
|
||||
|
||||
from flask import Flask, render_template, request, url_for, flash, redirect
|
||||
@@ -24,15 +25,17 @@ app = Flask(__name__)
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
conn = get_db_connection()
|
||||
posts = conn.execute('SELECT * FROM posts').fetchall()
|
||||
conn.close()
|
||||
|
||||
return render_template('index.html', posts=posts)
|
||||
events = calendar_interface.get_all_calendar_events()
|
||||
|
||||
if post is None:
|
||||
abort(404)
|
||||
else:
|
||||
return render_template('index.html', events=events)
|
||||
|
||||
@app.route('/<int:event_id>')
|
||||
def post(post_id):
|
||||
post = get_post(post_id)
|
||||
return render_template('calendar.html', post=post)
|
||||
return render_template('show_event.html', post=post)
|
||||
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ logging.basicConfig(format='%(asctime)s,%(msecs)d %(levelname)-4s [%(filename)s:
|
||||
level=logging.INFO)
|
||||
# logging.getLogger("msal").setLevel(logging.INFO) # Optionally disable MSAL DEBUG logs
|
||||
|
||||
|
||||
def get_access_token():
|
||||
#with open("auth_config.json") as f:
|
||||
# config = json.load(f)
|
||||
@@ -65,6 +66,10 @@ def execute_request(token: dict, endpoint:str):
|
||||
def execute_user_request(token, endpoint, user_id=USER_ID):
|
||||
return execute_request(token, "https://graph.microsoft.com/v1.0/users/" + user_id + f"/{endpoint}")
|
||||
|
||||
def get_all_calendar_events():
|
||||
token = get_access_token()
|
||||
|
||||
return execute_user_request(token, f"calendars/{CALENDAR_ID}/events").get("value")
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Calling graph using the access token
|
||||
@@ -75,8 +80,3 @@ if __name__ == "__main__":
|
||||
|
||||
print("Available calendars are:")
|
||||
print(json.dumps(cal_name_id, indent=2))
|
||||
|
||||
print("Events in selected calendar are:")
|
||||
events = execute_user_request(token, f"calendars/{CALENDAR_ID}/events").get("value")
|
||||
print(json.dumps(events, indent=2))
|
||||
|
||||
|
||||
2
run_dev_server.sh
Normal file
2
run_dev_server.sh
Normal file
@@ -0,0 +1,2 @@
|
||||
export FLASK_ENV=development
|
||||
flask run #--host=0.0.0.0
|
||||
Reference in New Issue
Block a user