Exemple #1
0
def create_app():
    """
    Initialize Flask and setup database

    """
    project_dir = os.path.dirname(os.path.abspath(__file__))
    app = CustomFlask(__name__)
    app.config.from_mapping(
        SECRET_KEY=os.urandom(16),
        CACHED_TIME=time.time(),
        THEME_DIR="./data/theme.json",
        REAL_MARKDOWN_DIR=os.path.join(project_dir, "./data/topaz_docs"),
        MARKDOWN_DIR="./data/docs",
        FILE_MANAGER=FileManager(
            file_src_dir=os.path.join(project_dir, "./data/topaz_docs") + "/",
            symbolic_link_dst="./data/topaz_docs"))

    CORS(app, supports_credentials=True)

    # Init database
    import db
    db.init_db()

    # Init github cache
    from utils.github import update_public_repos
    db_conn = db.get_db()
    update_public_repos(db_conn)

    # Init meidum cache
    db_conn = db.get_db()
    with open(app.config["THEME_DIR"], "r") as f:
        data = json.load(f)
        medium_url = data["nav_bar_footer"]["medium"]["link"]
    from utils.medium import update_articles
    update_articles(db_conn, medium_url)

    # Register blueprints
    import home
    app.register_blueprint(home.bp)

    import auth
    app.register_blueprint(auth.bp)

    # Initialize login manager
    login_manager = LoginManager()
    login_manager.init_app(app)

    @login_manager.user_loader
    def user_loader(username):
        db_conn = db.get_db()
        return get_user(db_conn, username)

    return app
Exemple #2
0
def create_app():
    """
    Initialize Flask and setup database

    """
    app = CustomFlask(__name__)
    app.config.from_mapping(SECRET_KEY=os.urandom(16),
                            CACHED_TIME=time.time(),
                            THEME_DIR="./data/theme.json")

    # Init database
    import db
    db.init_db()

    # Init github cache
    from utils.github import update_public_repos
    db_conn = db.get_db()
    update_public_repos(db_conn)

    # Init meidum cache
    db_conn = db.get_db()
    with open(app.config["THEME_DIR"], "r") as f:
        data = json.load(f)
        medium_url = data["medium_url"]
    from utils.medium import update_articles
    update_articles(db_conn, medium_url)

    # Register blueprints
    import home
    app.register_blueprint(home.bp)

    import auth
    app.register_blueprint(auth.bp)

    # Initialize login manager
    login_manager = LoginManager()
    login_manager.init_app(app)

    @login_manager.user_loader
    def user_loader(username):
        db_conn = db.get_db()
        return get_user(db_conn, username)

    return app
Exemple #3
0
def get_public_repos(db_conn):
    """
    Returns a list of public repos from github
    Args:
        db_conn: sqlite3 db connection object

    Returns (repos, update_time): a list of repos and the last updated time

    """
    c = db_conn.cursor()
    start_time = current_app.config["CACHED_TIME"]
    if time.time() - start_time > cache_rate:
        current_app.config.from_mapping(CACHED_TIME=time.time())
        update_public_repos(db_conn)

    updated_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))
    c.execute("SELECT * FROM public_repos")
    all_rows = c.fetchall()
    repos = [dict(row) for row in all_rows[::-1]]
    return repos, updated_time