<commit_before># coding: utf-8

# Der WSGI-Server auf PythonAnywhere verwendet diese Datei
import hashlib
import sqlite3
import os
import time

import bottle
from bottle import default_app, route, view
from bottle import request
from bottle_utils.i18n import I18NPlugin
from bottle_utils.i18n import lazy_gettext as _

import input_number as ip
from dbhelper import initialize_database

"""
ENCODING: Default ist UTF-8, ändern mit:

    response.charset = 'ISO-8859-15'
    response.content_type = 'text/html; charset=latin9'
"""

MOD_PATH = os.path.dirname(os.path.abspath(__file__))
DB_PATH = os.path.abspath(os.path.join(MOD_PATH, '..', '..', "lagesonr.db"))

if not os.path.exists(DB_PATH):
    initialize_database(DB_PATH)

lagesonrdb = sqlite3.connect(DB_PATH)

LANGS = [
    ('de_DE', 'Deutsch'),
    ('en_US', 'English'),
]
# ('ar_AR', 'Arab'),
DEFAULT_LOCALE = 'en_US'


@route('/bla')
def handler():
    """BEISPIEL: probiere im Browser: /en_US/bla und /de_DE/bla"""
    return _('TESTWORD')


@route('/')
@view('start_page')
def index():
    """1.Seite: Helfer steht am LaGeSo und gibt Nummern ein [_____] """
    return {'entered': []}


@route('/arab')
@view('start_page_arab')
def index_arab():
    return {'entered': []}


@route('/enter', method='POST')
@view('start_page')
def do_enter():
    numbers = request.forms.get('numbers')
    timestamp = time.asctime()
    numbers = [num.strip() for num in numbers.split('\n')]
    result_num = []

    usr_agent = str(request.environ.get('HTTP_USER_AGENT'))
    usr_lang = str(request.environ.get('HTTP_ACCEPT_LANGUAGE'))
    usr_ip = str(request.remote_addr)

    usr_fingerprint = usr_agent + usr_lang + usr_ip
    usr_hash = hashlib.md5(usr_fingerprint.encode("utf-8")).hexdigest()

    with lagesonrdb as con:
        cur = con.cursor()
        for num in set(numbers):
            if ip.is_valid_number(num) and ip.is_ok_with_db(
                    num) and ip.is_valid_user():
                insert = 'INSERT INTO NUMBERS(NUMBER, TIME, PLACE, USER, FINGERPRINT) VALUES ("%s", "%s", "-", "-", %s)' % (
                    num, timestamp, usr_hash)
                cur.execute(insert)
                result_num.append(num)
            else:
                result_num.append("INVALID INPUT: %s" % num)

    return {'entered': result_num, 'timestamp': timestamp}


@route('/query')
@view('query_page')
def query_number():
    """
    2. Seite: Flüchtling fragt ab: Wurde meine Nummer gezogen? [_____]
    => Antwort: X mal am LaGeSo eingetragen von (Erste Eintragung)
    DD.MM.YY hh bis DD.MM.YY hh (LetzteEintragung)
    application = default_app()
    """
    return {'result': '-', 'timestamp_first': '-', 'timestamp_last': '-',
            'n': '0'}


@route('/query', method='POST')
@view('query_page')
def do_query():
    number = request.forms.get('number')<commit_msg>fingerprint written to db<commit_after># coding: utf-8

# Der WSGI-Server auf PythonAnywhere verwendet diese Datei

import sqlite3
import os
import time

import bottle
from bottle import default_app, route, view
from bottle import request
from bottle_utils.i18n import I18NPlugin
from bottle_utils.i18n import lazy_gettext as _

import input_number as ip
from dbhelper import initialize_database
import hashlib

MOD_PATH = os.path.dirname(os.path.abspath(__file__))
DB_PATH = os.path.abspath(os.path.join(MOD_PATH, '..', '..', "lagesonr.db"))

if not os.path.exists(DB_PATH):
    initialize_database(DB_PATH)

lagesonrdb = sqlite3.connect(DB_PATH)

LANGS = [
    ('de_DE', 'Deutsch'),
    ('en_US', 'English'),
]
# ('ar_AR', 'Arab'),
DEFAULT_LOCALE = 'en_US'


<<<<<<< Temporary merge branch 1
=======
@route('/bla')
def handler():
    """BEISPIEL: probiere im Browser: /en_US/bla und /de_DE/bla"""
    return _('TESTWORD',ip.get_user_id())

@route('/user-agent')
def user_agent():
    """
    returns an identification hash based on information from the user's browser
    :return: string
    """
    usr_agent = str(request.environ.get('HTTP_USER_AGENT'))
    usr_lang = str(request.environ.get('HTTP_ACCEPT_LANGUAGE'))
    usr_ip = str(request.remote_addr)

    usr_fingerprint = usr_agent + usr_lang + usr_ip
    usr_hash = hashlib.md5(usr_fingerprint.encode("utf-8"))

    # no return
    return ()

>>>>>>> Temporary merge branch 2
@route('/')
@view('start_page')
def index():
    """1.Seite: Helfer steht am LaGeSo und gibt Nummern ein [_____] """
    return {'entered': []}

@route('/', method='POST')
@view('start_page')
def do_enter():
    import pdb
    #pdb.set_trace()
    numbers = request.forms.get('numbers')
    timestamp = time.asctime()
    numbers = [num.strip() for num in numbers.split('\n')]
    result_num = []
    with lagesonrdb as con:
        cur = con.cursor()
        for num in set(numbers):
            if ip.is_valid_number(num) and ip.is_ok_with_db(
                    num) and ip.is_valid_user():
                insert = 'INSERT INTO NUMBERS(NUMBER, TIME, PLACE, USER) VALUES ("%s", "%s", "-", "-")' % (
                    num, timestamp)
                cur.execute(insert)
                result_num.append(num)
            else:
                result_num.append("INVALID INPUT: %s" % num)

    return {'entered': result_num, 'timestamp': timestamp}


@route('/query')
@view('query_page')
def query_number():
    """
    2. Seite: Flüchtling fragt ab: Wurde meine Nummer gezogen? [_____]
    => Antwort: X mal am LaGeSo eingetragen von (Erste Eintragung)
    DD.MM.YY hh bis DD.MM.YY hh (LetzteEintragung)
    application = default_app()
    """
    return {'result': '-', 'timestamp_first': '-', 'timestamp_last': '-',
            'n': '0'}


@route('/query', method='POST')
@view('query_page')
def do_query():
    number = request.forms.get('number')
{'fraction_non_alphanumeric': 0.1519693272917393, 'fraction_numerical': 0.006622516556291391, 'mean_word_length': 3.384262796027502, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 12, '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': '202371', 'n_tokens_mistral': 2055, 'n_tokens_neox': 1976, 'n_words': 464}