<commit_before>#! /usr/bin/env python

# Python imports
import logging
import os

# Third party imports
from bottle import get, post, request, route, run, static_file, view

# Project imports
import db, editor

# Constants, and help with template lookup
root = os.path.abspath(os.path.dirname(__file__))
static = os.path.join(root, 'static')
os.chdir(root)

@route('/')
@view('index')
def homepage():
    return dict()

@route('/static/<filename>')
def htdocs(filename):
    return static_file(filename, root=static)

@post('/api/decrypt')
def decrypt():
    password = request.forms.get('password')
    uid = request.forms.get('uid')
    return db.get_content(uid, password)

@post('/api/launch_editor')
def launch_editor():
    uid = request.forms.get('uid')
    content = request.forms.get('content')
    return editor.launch(uid, content)

@get('/api/from_disk/<uid>')
def from_disk(uid=None):
    path = os.path.join('/tmp', uid)
    if os.path.exists(path):
        return open(path).read()
    else:
        return 'missing'

@get('/api/list')
def api_list():
    return db.search(request.query.get('s'))

@post('/api/persist')
def persist():
    n = db.note(actual=True)
    password = request.forms.get('password')
    form = dict((k, v) for k, v in request.forms.items() if k in n)
    if form.get('uid') == '':
        fcn = db.create_note
        form.pop('uid')
    else:
        fcn = db.update_note

    n.update(form)
    return dict(success=fcn(n, password=password))

if __name__ == '__main__':
    logging.basicConfig()
    db.prepare()<commit_msg>Launch a browser on boot<commit_after>#! /usr/bin/env python

# Python imports
import logging
import os
import threading
import time
import webbrowser

# Third party imports
from bottle import get, post, request, route, run, static_file, view

# Project imports
import db, editor

# Constants, and help with template lookup
root = os.path.abspath(os.path.dirname(__file__))
static = os.path.join(root, 'static')
os.chdir(root)

@route('/')
@view('index')
def homepage():
    return dict()

@route('/static/<filename>')
def htdocs(filename):
    return static_file(filename, root=static)

@post('/api/decrypt')
def decrypt():
    password = request.forms.get('password')
    uid = request.forms.get('uid')
    return db.get_content(uid, password)

@post('/api/launch_editor')
def launch_editor():
    uid = request.forms.get('uid')
    content = request.forms.get('content')
    return editor.launch(uid, content)

@get('/api/from_disk/<uid>')
def from_disk(uid=None):
    path = os.path.join('/tmp', uid)
    if os.path.exists(path):
        return open(path).read()
    else:
        return 'missing'

@get('/api/list')
def api_list():
    return db.search(request.query.get('s'))

@post('/api/persist')
def persist():
    n = db.note(actual=True)
    password = request.forms.get('password')
    form = dict((k, v) for k, v in request.forms.items() if k in n)
    if form.get('uid') == '':
        fcn = db.create_note
        form.pop('uid')
    else:
        fcn = db.update_note

    n.update(form)
    return dict(success=fcn(n, password=password))

def launcher():
    time.sleep(1)
    webbrowser.open_new_tab('http://localhost:8082')

if __name__ == '__main__':
    logging.basicConfig()
    db.prepare()
    threading.Thread(target=launcher).start()
{'fraction_non_alphanumeric': 0.16115453998797355, 'fraction_numerical': 0.001503307276007216, 'mean_word_length': 3.7191489361702126, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '383701', 'n_tokens_mistral': 1137, 'n_tokens_neox': 1120, 'n_words': 264}