Created
June 6, 2020 08:06
-
-
Save namieluss/12422b694b35806f57b299d517c00743 to your computer and use it in GitHub Desktop.
This is a simple app written in Python Flask with MongoDB mongodb database. Celery is used to manage task queue.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = "Suleiman" | |
from celery import Celery | |
from flask import Flask, render_template | |
from pymongo import MongoClient | |
from .constants import * | |
app = Flask(__name__, template_folder="templates") | |
app.config['CELERY_BROKER_URL'] = MONGODB_CON_STR | |
app.config['CELERY_RESULT_BACKEND'] = MONGODB_CON_STR | |
db = MongoClient(MONGODB_URL)[DB_NAME] | |
celery = Celery(app.name, broker=app.config['CELERY_BROKER_URL']) | |
celery.conf.update(app.config) | |
from .task import check_who_and_where | |
@app.route('/') | |
def index_page(): | |
check_who_and_where(page='index') | |
return render_template('index.html') | |
@app.route('/about') | |
def about_page(): | |
check_who_and_where(page='about') | |
return render_template('about.html') | |
@app.route('/contact') | |
def contact_page(): | |
return render_template('contact.html') | |
def view_logs(): | |
from pprint import pprint | |
# fetch all logs and show them | |
data = list(db.page_access_log.find({})) | |
pprint(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment