Exemple #1
0
def init_db():
    print 'sync db...'
    with closing(connect_db()) as db:
        with app.open_resource('schema.sql') as f:
            db.cursor().executescript(f.read())
        db.commit()
    print 'done !'
def input_info(request):
    template = loader.get_template(r'get_info.html')
    # if this is a POST request we need to process the form data
    if request.method == 'POST':
        formData = { 
        'name' : request.POST.get('name',''),
        'age' : request.POST.get('age',''),
        'phone' : request.POST.get('phone',''),
        'email' : request.POST.get('email','') }
        
        import models
        models.connect_db()
        new_user = models.User(request.POST.get('name',''), request.POST.get('age',''), request.POST.get('phone',''), request.POST.get('email',''))
        models.add_record(new_user)
        models.update_db()
        
    # if a GET (or any other method) we'll create a blank form
    else:
        formData = None
    context = RequestContext(request, {
        'header_text':"Provide Information",
        'formData' : formData
        })
    return HttpResponse(template.render(context))
Exemple #3
0
def before_request():
    g.db = models.connect_db()
Exemple #4
0
def before_request():
    g.db = connect_db()
Exemple #5
0
    def __init__(self):
        global message_queue
        self.config = config
        self.messages = message_queue
        self.logger = logging.getLogger(__name__)
        self.logger.setLevel(logging.DEBUG)
        fh = logging.FileHandler(config.get("system")["logfile"])
        if config.get("debug"):
            ch = logging.StreamHandler()
            ch.setLevel(logging.DEBUG)
            self.logger.addHandler(ch)
            fh.setLevel(logging.DEBUG)
        else:
            fh.setLevel(logging.INFO)

        self.logger.addHandler(fh)

        self.usr_bin_path = config.get("system")["usr_bin"]
        self.default_path = config.get("system")["default_path"]
        self.data_path = os.path.join(
            self.default_path,
            config.get("system")["data_dir"])

        self.inet_check_attempts = 0
        self.is_mic_down = False
        self.ready = False
        self.sleeping = False
        self.exit_now = False

        self.nickname = config.get("computer_nickname")
        self.user_nickname = config.get("user_nickname")
        self.user = config.get("user")
        self.my_email = config.get("email")

        self.screen_on = config.get("system")["screen"]
        self.audio_in_device = str(config.get("audio")["in_device"])

        self.min_volume = config.get("audio")["min_volume"]
        self.sample_rate = config.get("audio")["sample_rate"]
        self.idle_duration = config.get("audio")["idle_duration"]
        self.take_order_duration = config.get("audio")["take_order_duration"]
        self.flac_file = "/tmp/noise%d.flac"
        self.vol_samples = 5
        self.vol_total = 5
        self.vol_average = 0.5
        self.prev_idle_vol = 1.0
        self.sound_proc = None

        self.links = []
        self.periodic_tasks = {}

        connect_db()

        self.clean_files()

        self.addressbook = AddressBook(
            user=self.user,
            file=config.get("addressbook")["file"])

        self.listener = Listener(user=self.user, sample_rate=self.sample_rate)
        self.speech2text = Speech2Text(
            user=self.user,
            sample_rate=self.sample_rate)

        # Voice command to event dispatch singnal table
        self.signals_at_sleep = []
        self.command2signal = {}
        self.core = CoreCommands(self)
        self.core.register_commands()
        self._import_plugins()

        all_commands = ""
        for key in self.command2signal.keys():
            all_commands += self.nickname + " " + key + "\n"
        all_commands += self.nickname + " stop\n"
        all_commands += "yes\n"
        all_commands += "no\n"
        for name in self.addressbook.book.keys():
            all_commands += name + "\n"
        corpus_file = os.path.join(self.data_path, "keyword_corpus.txt")
        with open(corpus_file, "w") as f:
            f.write(all_commands)

        self.listener_thread = None

        self.sphinx_timeout = config.get("sphinx")["timeout_sec"]
        self.listening_since = None
        self._sphinx = None
        self.kill_sphinx()
        self.sphinx_mode = SPHINX_COMMAND

        if config.get("system")["have_gps"]:
            self.gps = gps(mode=WATCH_ENABLE)
        else:
            self.gps = None
Exemple #6
0
from flask import Flask, jsonify, request, render_template

from flask_debugtoolbar import DebugToolbarExtension

from models import db, connect_db, Cupcake

from forms import AddCupcakeForm

app = Flask(__name__)

app.config['SECRET_KEY'] = "secret"

app.config['SQLALCHEMY_DATABASE_URI'] = "postgresql:///cupcakes"
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

connect_db(app)
db.create_all()

app.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = False

toolbar = DebugToolbarExtension(app)

########################################################
# Homepage Route


@app.route("/")
def show_homepage():
    """ Show the homepage to show and add cupcakes """

    form = AddCupcakeForm()