<commit_before>#! /usr/bin/env python3
# coding: utf-8
"""
Jean-Pierre [Prototype]
A Raspberry Pi robot helping people to build groceries list.
<NAME> - github.com/matteocargnelutti

controllers/web.py - Web server : uses Flask
"""
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
import os
import random
import string

from flask import Flask
from flask import render_template

from utils import Database
import models

#-----------------------------------------------------------------------------
# Controller
#-----------------------------------------------------------------------------
class Web:

    @classmethod
    def secret_key(cls):
        """
        Creates / Return a secret key, stored in a file
        :rtype: str
        """
        filename = 'flask_secret_key'
        # Is there a secret key ?
        if os.path.isfile(filename):
            file = open(filename, 'r')
            secret_key = file.read()
            file.close()
            return secret_key

        # If there's none : generate a new one
        newkey = "".join([random.choice(string.printable) for _ in range(24)])
        keyfile = open(filename, 'w')
        keyfile.write(newkey)
        keyfile.close()
        return newkey

#-----------------------------------------------------------------------------
# Flask WSGI init and views
#-----------------------------------------------------------------------------
if __name__ != '__main__':

    # Flask init
    webapp = Flask(__name__)
    webapp.config['SECRET_KEY'] = Web.secret_key()
    webapp.config['STATIC_FOLDER'] = 'assets/static'
    webapp.config['TEMPLATE_FOLDER'] = 'assets/templates'

    @webapp.route("/")
    def hello():
        return render_template('index.html')
<commit_msg>Progress : Flask static file<commit_after>#! /usr/bin/env python3
# coding: utf-8
"""
Jean-Pierre [Prototype]
A Raspberry Pi robot helping people to build groceries list.
<NAME> - github.com/matteocargnelutti

controllers/web.py - Web server : uses Flask
"""
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
import os
import random
import string

from flask import Flask
from flask import render_template

from utils import Database
import models

#-----------------------------------------------------------------------------
# Controller
#-----------------------------------------------------------------------------
class Web:

    @classmethod
    def secret_key(cls):
        """
        Creates / Return a secret key, stored in a file
        :rtype: str
        """
        filename = 'flask_secret_key'
        # Is there a secret key ?
        if os.path.isfile(filename):
            file = open(filename, 'r')
            secret_key = file.read()
            file.close()
            return secret_key

        # If there's none : generate a new one
        newkey = "".join([random.choice(string.printable) for _ in range(24)])
        keyfile = open(filename, 'w')
        keyfile.write(newkey)
        keyfile.close()
        return newkey

    @classmethod
    def folders(cls):
        """
        Returns a dict of Flask folders.
        Also set them as class attributes
        :rtype: dict
        """
        path = os.path.abspath(os.path.dirname(__file__))
        path = path.replace('controllers', '')
        folders = {
            'static': path + '/assets/static',
            'templates': path + '/assets/templates'
        }
        cls.folders = folders
        return folders

#-----------------------------------------------------------------------------
# Flask WSGI init and views
#-----------------------------------------------------------------------------
if __name__ != '__main__':

    # Flask init
    Web.folders()
    webapp = Flask(__name__,
                   static_url_path='/static/',
                   static_folder=Web.folders['static'],
                   template_folder=Web.folders['template'])
    webapp.config['SECRET_KEY'] = Web.secret_key()

    @webapp.route("/")
    def hello():
        return render_template('index.html')

{'fraction_non_alphanumeric': 0.3034627983153954, 'fraction_numerical': 0.0018717828731867104, 'mean_word_length': 1.2058823529411764, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2084053', 'n_tokens_mistral': 1059, 'n_tokens_neox': 1027, 'n_words': 277}