Exemplo n.º 1
0
def rt_home(request):
    try:
        one = DBSession.query(User).filter(User.user_id == 'bob').first()
    except DBAPIError:
        return Response(conn_err_msg, content_type='text/plain', status_int=500)

    message = ""
    favorites = []
    logged_in = authenticated_userid(request)

    if 'userid' in request.POST:
        user_id = request.params['userid']
        if DBSession.query(User).filter(User.user_id == user_id).first() is None:
            message = 'Gah! The user name ' + user_id + ' is not known. =['
        else:
            headers = remember(request,user_id)
            return HTTPFound(
                location=request.route_url('home',
                                           username=user_id),
                headers=headers)

    if 'logout' in request.POST:
        headers=forget(request)
        return HTTPFound(
            location=request.route_url('home'), headers=headers)

    if logged_in:
        user = DBSession.query(User).filter(User.user_id == logged_in).first()
        favorites = map(lambda et : { 'code':et.eid, 'description':et.description},
                        user.favorites);
        
    return {'logged_in': logged_in,
            'message' : message,
            'favorites' : favorites}
Exemplo n.º 2
0
def sentimental_hodnota_textu(obsah, request):
    vety = list(obsah.split('.'))  #TODO rozdelovat inteligetne na vety
    #print(vety)
    pocet_ohodnotenych_slov_celkove = 0   
    hodnota_celkove = 0
    for veta in vety:

        pocet_ohodnotenych_slov_vo_vete = 0
        slova = re.split(r"[\s\.,\!\?]+", veta)
        hodnota = 0
        hodnota_vety = 0
        priemer_celkove = 0      
        for slovo in slova:    
            if len(slovo) >= 2:
                slovo=slovo.strip('";:„')
                slovo=remove_diacritic(slovo)                
                slovo=slovo.lower()
                hodnota = wordValue(request,slovo)
                hodnota_vety = hodnota_vety + hodnota
                hodnota_celkove = hodnota_celkove + hodnota
                #print(hodnota_celkove)
                if hodnota != 0:
                    pocet_ohodnotenych_slov_vo_vete += 1
                    pocet_ohodnotenych_slov_celkove += 1
        #priemer_vety = hodnota_vety / pocet_ohodnotenych_slov_vo_vete
    if pocet_ohodnotenych_slov_celkove != 0:  
        priemer_celkove = hodnota_celkove / pocet_ohodnotenych_slov_celkove
        print(priemer_celkove)
    clanok = Article(titulok, obsah, priemer_celkove, date.today())
    DBSession.add(clanok)

    return{'text': text, 'vysledok' : priemer_celkove}
Exemplo n.º 3
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    
    herokuDb = os.environ.get('DATABASE_URL')
    if herokuDb is not None:
        engine = create_engine(herokuDb)
    else:
        engine = engine_from_config(settings, 'sqlalchemy.')

    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    config = Configurator(settings=settings)


    authn_policy = AuthTktAuthenticationPolicy(secret='sosecret',
                                               callback=lambda userid, request: [])
    authz_policy = ACLAuthorizationPolicy()
    config.set_authentication_policy(authn_policy)
    config.set_authorization_policy(authz_policy)

    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_route('home', '/')
    config.add_route('user_created', '/user-created', request_method='POST')
    config.add_route('create_user', '/create-user')
    config.add_route('event_type_created', '/event-type-created', request_method='POST')
    config.add_route('create_event_type', '/create-event-type')
    config.add_route('event_type', '/event-types/{eventid:\d+}')
    config.add_route('add_occurance', '/add-occurance')
    config.scan()
    return config.make_wsgi_app()
Exemplo n.º 4
0
def change_event(request):
    event = request.db_session.query(Event).filter(Event.id == event_id).first()
    event.description = str(request.matchdict['description'])
    event.nazov = str(request.matchdict['name_of_event'])
    event.goal = str(request.matchdict['goal'])
    event.workplace = str(request.matchdict['workplace'])
    DBSession.flush()
Exemplo n.º 5
0
def add_task(request):
    id_event = request.matchdict['id_event']
    name_of_employee = request.matchdict['name_of_employee']
    name = name_of_employee.split(' ')[0]
    surname = name_of_employee.split(' ')[1]
    print(name, len(surname))   
    employee = request.db_session.query(Employee).filter(Employee.name == name, Employee.surname == surname).first()
    print(employee)
    event = request.db_session.query(Event).filter(Event.id == id_event).first()
    print('*' * 250)
    print(employee)
    if employee is None:
        # ked ide do eventu do ktoreho nema pristup redirect..
        return{'status': 'you have not acces to do with this employee'} 
    if event.by_user_id != get_verified_user_id(request):
        # ked ide do eventu do ktoreho nema pristup redirect..
        return{'status': 'you have not acces to wotk with this event'} 
    print(events)

    exist_task = request.db_session.query(Task).filter(Task.event_id == id_event, Task.employee_id == employee.id).first()
    print(exist_task)
    if exist_task is not None:
        return{'status': 'employee is in this task already'}  
    task = Task(employee, event)
    DBSession.add(task)
    DBSession.add(event)
    return{'name': name, 'surname': surname, 'status': 'ok'} 
Exemplo n.º 6
0
def add_hash_event(request):
    id_event = request.matchdict['id_employee']
    id_hash = int(request.matchdict['id_hash'])

    hash_tag = request.db_session.query(Hash_employee).filter(Hash_employee.by_user_id == get_verified_user_id(request), Hash_employee.id == id_hash).first()
    print(hash_tag.name)
    event = request.db_session.query(Event).filter(Event.id == id_event).\
            filter(or_(Employee.hash1 == id_hash, Employee.hash2 == id_hash)).\
            first()

    if event is not None:
        return{'status': 'user have this hash tag already!!'} 
    if hash_tag == None:
        return{'status': 'hash tag dont exist'} 
    else:
        event = request.db_session.query(Event).filter(Event.id == id_event).first()
        if event == None:
            return{'status': 'employee dont exist'}
        if event.hash1 == None:
            event.hash1 = id_hash
            DBSession.flush()
            return{'status': 'ok'}
        elif event.hash2 == None:
            event.hash2 = id_hash
            DBSession.flush()
            return{'status': 'ok'}
        else:
            return{'status': 'You can have maximum 2 hash tags for one employee'}
Exemplo n.º 7
0
def rt_event_type_created(request):
    params = request.params
    description = params['description']

    et = EventType(description)


    session = DBSession()
    session.add(et)
    session.flush()

    user_id = authenticated_userid(request)

    user = DBSession.query(User).filter(User.user_id == user_id).first()

    if user is not None:
        user.favorites.append(et)
        session.flush()

    session.flush()
    event_code = et.eid

    return {'description': description,
            'success': True,
            'message': "",
            'event_code': event_code}
Exemplo n.º 8
0
def spracuj_data_do_db(article, request):
    #pridane OBJEKTU article do db

    if is_article_morbid(article):
    	article.sentiment = -3

    DBSession.add(article)
    return article
Exemplo n.º 9
0
def skuska2(request):

    # a = request.db_session.query(User.meno).first()
    # print(a)
    
    prichod = Arrival(25, 'aa', datetime.datetime.now())
    DBSession.add(prichod)
    print(has_permission('edit', request.context, request))
    return {'logged_in' : authenticated_userid(request)}
Exemplo n.º 10
0
def main(argv=sys.argv):
    if len(argv) != 2:
        usage(argv)
    config_uri = argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.create_all(engine)
Exemplo n.º 11
0
def register_employee(employee, request):
    DBSession.add(employee)
    DBSession.flush()
    #vytvorim QR code,,, 
    print(str(employee.id) * 30)
    qr = QRCode(version=8, error_correction=ERROR_CORRECT_L)
    qr.add_data(str(employee.id))
    qr.make()
    im = qr.make_image()
    im.save('qr_images/'  + str(employee.surname) + '.png')
Exemplo n.º 12
0
def rt_user_created(request):
    params = request.params
    user_id = params['userid']

    try:
        one = DBSession.query(User).filter(User.user_id == 'bob').first()
    except DBAPIError:
        return Response(conn_err_msg, content_type='text/plain', status_int=500)

    user = User(user_id)
    DBSession.add(user)

    return {'userid': user_id, 'success': True, 'message': ""}
Exemplo n.º 13
0
def add_event(request):
    post=request.POST
    id_leader =  post['id_leader']
    time_begin =  post['time_begin'].split(':')
    time_begin = [int(x) for x in time_begin]
    time_end =  post['time_end'].split(':')
    time_end = [int(x) for x in time_end]
    date_begin = post['date_begin'].split('/')
    date_begin = [int(x) for x in date_begin]
    date_end = post['date_end'].split('/')
    date_end = [int(x) for x in date_end]

    
    leader = request.db_session.query(Employee).filter(Employee.by_user_id == get_verified_user_id(request), Employee.id == id_leader).first()
    print(time_end)
    zaciatok_eventu = datetime.datetime(date_begin[2], date_begin[0], date_begin[1], time_begin[0], time_begin[1], 0, 0)
    koniec_eventu = datetime.datetime(date_end[2], date_end[0], date_end[1], time_end[0], time_end[1], 0, 0)
    event = Event(get_user(request),  leader, post['name'], zaciatok_eventu, koniec_eventu)
    DBSession.add(event)
    DBSession.flush()
    DBSession.refresh(event)
    #leader bude ako task
    task = Task(event.leader, event, 0, 0, event.length())
    DBSession.add(task)

    return HTTPFound(location = request.route_url('events'))
Exemplo n.º 14
0
def change_task(request):
    id_task = int(request.matchdict['id'])
    performance = request.matchdict['performance']
    delay = request.matchdict['delay']
    print(id_task)
    tasks = request.db_session.query(Task).all()
    for t in tasks:
        print(t.id)
    print(tasks)
    task = request.db_session.query(Task).filter(Task.id == id_task).first()
    task.delay = delay
    task.performance = performance
    DBSession.flush() 
    return{'status' : 'ok'}
Exemplo n.º 15
0
def add_employee(request):
    post=request.POST
    # if post['position'] == "Undefined":
    if post['position'] == '':
        employee_position = None
    else:
        employee_position = request.db_session.query(Employees_type).filter(Employees_type.by_user_id == get_verified_user_id(request), Employees_type.name == post['position']).first()
    

    employee = Employee(get_user(request), post['name'], post['surname'], employee_position, post['age'], post['merital_status'], post['sex'], post['addresse'])
    DBSession.add(employee)
    
    #import pyqrcode
    #big_code = pyqrcode.create(employee.id, error='L', version=27, mode='binary')
    #big_code.png(employee.surname, scale=6, module_color=[0, 0, 0, 128], background=[0xff, 0xff, 0xcc])
    # im = Image.open(request.params['code2.png'].file)
    return HTTPFound(location = request.route_url('employees'))
Exemplo n.º 16
0
def rt_event_type(request):
    eid = request.matchdict['eventid']

    et = DBSession.query(EventType).get(eid)

    user_id = authenticated_userid(request)
    if user_id is not None:
        observer = DBSession.query(User).filter(User.user_id==user_id).first()
        occurance = Occurance(observer, et)
        DBSession.add(occurance)

    count = len(et.occurances)

    return {'event_type_description': et.description,
            'event_type_code': et.eid,
            'count':count,
            'logged_in': user_id}
Exemplo n.º 17
0
def checkin(request):
    employee_id = request.matchdict['employee_id']
    employee = request.db_session.query(Employee).filter(Employee.id == employee_id).first()
    print('**' * 250)
    print(get_verified_user_id(request))
    print(get_verified_user_id(request))
    print(get_verified_user_id(request))
    print(employee.by_user_id)
    if employee.by_user_id != get_verified_user_id(request):
        return {'chyba' : 'nemas prava na manipulaciu s tymto employee!'}

    users_departure = request.db_session.query(Arrival.departure).filter(Arrival.employee_id ==employee_id).all()
    for departure in users_departure:
        if departure[0] == None:
            return {'chyba' : 'employee je v robote, nemozno ho ceknut'}
    prichod = Arrival(employee, 'ziadna', datetime.datetime.now())
    DBSession.add(prichod)
    departure = request.db_session.query(Arrival.departure).first()[0] ## NONE
    return {'logged_in' : authenticated_userid(request), 'employee_id' : employee_id}
Exemplo n.º 18
0
def checkout(request):
    employee_id = request.matchdict['employee_id']
    performance = request.matchdict['performance']
    if performance == -1:
        performance == 100
    employee = request.db_session.query(Employee).filter(Employee.id == employee_id).first()
    if employee.by_user_id != get_verified_user_id(request):
        return {'chyba' : 'nemas prava na manipulaciu s tymto employee!'}
    # employee = request.db_session.query(Employee).filter(Employee.id == employee_id).first()
    arrivals = request.db_session.query(Arrival).filter(Arrival.employee_id == employee_id, Arrival.departure == None).all()
    # for i in arrivals:
    #     print(i.id)
    print(arrivals)
    if len(arrivals) == 1:
        arrival = arrivals[0]
        arrival.departure = datetime.datetime.now();
        arrival.performance = performance
        DBSession.flush() 
        return {'arrivaldeparture': arrival.departure}
    else:
        return{'chyba': 'chyba pri check oute kontaltujet admina'}
Exemplo n.º 19
0
def delete_hash_employee(request):
    id_employee = request.matchdict['id_employee']
    id_hash = request.matchdict['id_hash']
    hash_tag = request.db_session.query(Hash_employee).filter(Hash_employee.by_user_id == get_verified_user_id(request), Hash_employee.id == id_hash).first()
    if hash_tag == None:
        return{'status': 'hash tag dont exist'} 
    else:
        employee = request.db_session.query(Employee).filter(Employee.by_user_id == get_verified_user_id(request), Employee.id == id_employee).\
        filter(or_(Employee.hash1 == id_hash, Employee.hash2 == id_hash)).first()
        print(type(employee.hash2))
        # print(type(id_hash))
        if employee == None:
            return{'status': 'No employee require condition'} 
        if employee.hash1 == int(id_hash):
            employee.hash1 = None
            DBSession.flush()
            return{'status': 'hash was deleted'} 

        if employee.hash2 == int(id_hash):
            employee.hash2 = None
            DBSession.flush() 
            return{'status': 'hash was deleted'} 
Exemplo n.º 20
0
def parsuj_diskusiu(zdroj, request, clanok = 0,start = 1):
    # try:
        print('citam diskuiu!!')
        if start == 1:
            aktualna_stranka = 1
        else:
            aktualna_stranka = zdroj.split('/')[5]


        kam_dalej = -1
        zaciatok_url = zdroj.split('.sk/')[0] + '.sk'
        html = req.urlopen(zdroj)
        soup = BeautifulSoup(html)
        stranka = int(aktualna_stranka)
        if stranka == 1:
            clanok_ku_ktoremu_diskusia_patri = soup.find("a", {"id": "back_to_article"})['href']
            overovanie_adresy = clanok_ku_ktoremu_diskusia_patri.split('.') 
            # clanok = nacitaj_clanok_nad_diskusiou(clanok_ku_ktoremu_diskusia_patri, request)  

        obsah = soup.find("div", {"id": "dxse_mainw_diskus"})
        nazvy = soup.findAll('span', id=re.compile('^subject_user_reaction_\d+'))
        texty = soup.findAll('span', id=re.compile('^text_user_reaction_\d+')) 
        for i in range(len(texty)):
            text_diskusie = nazvy[i].text + texty[i].text
            # print(text_diskusie)
            sentimental_hodnota_prispevku = sentiment.hodnota_textu(text_diskusie, request)
            diskusny_prispevok = Feedback(clanok, text_diskusie, sentimental_hodnota_prispevku, datetime.date.today())
            if DBSession.add(diskusny_prispevok):
                print('pradny prispevok')

    
        strankovanie = soup.find("div", {"class" : "dxse_commpages"})
        
        pages = strankovanie.findAll("a")
        for page in pages:
            if page.text == '>':
                kam_dalej = zaciatok_url + page['href']
        #print(kam_dalej)
        print(aktualna_stranka)
        if kam_dalej != -1:
            # print('--------------------------------------------------------------------------------------------------------')
            parsuj_diskusiu(kam_dalej, request, clanok, 0)  
            print('koniec citania diskusie')
Exemplo n.º 21
0
def add_user(request):
    post=request.POST

    new_user = User(post['name'], post['password'], 'admin')
    DBSession.add(new_user)
    return HTTPFound(location = request.route_url('employees'))
Exemplo n.º 22
0
def add_comparison(request):
    type = request.matchdict['type']
    hash1_name = request.matchdict['hash1']
    hash2_name = request.matchdict['hash2']

    if type == "employee":
        hash1 = request.db_session.query(Hash_employee).filter(Hash_employee.name == hash1_name, Hash_employee.user == get_user(request)).first()
        hash2 = request.db_session.query(Hash_employee).filter(Hash_employee.name == hash2_name, Hash_employee.user == get_user(request)).first()
        print(hash1)
        print(hash2)
        porovnavacka = Comparison(get_user(request), hash1, hash2, 1)
        DBSession.add(porovnavacka)
        DBSession.flush()
        DBSession.refresh(porovnavacka)
        return{'status' : 'ok', 'id' : porovnavacka.id}
    elif type == "event":
        hash1 = request.db_session.query(Hash_employee).filter(Hash_employee.name == hash1_name, Hash_employee.user == get_user(request)).first()
        hash2 = request.db_session.query(Hash_employee).filter(Hash_employee.name == hash2_name, Hash_employee.user == get_user(request)).first()
        print(hash1)
        print(hash2)
        porovnavacka = Comparison(get_user(request), hash1, hash2, 0)
        DBSession.add(porovnavacka)
        DBSession.flush()
        DBSession.refresh(porovnavacka)
        return{'status' : 'ok', 'id' : porovnavacka.id}
    else:
        return{'status' : 'This ype of comparison is not in our system'}
Exemplo n.º 23
0
def add(request):
    type_to_add = request.matchdict['type_to_delete']
    name = request.matchdict['name']
    if type_to_add == "workposition":
        if request.db_session.query(Employees_type).filter(Employees_type.name == name, Employees_type.by_user_id ==  get_verified_user_id(request)).first() == None:
            new_workposition =  Employees_type(get_user(request), name)
            DBSession.add(new_workposition)
            DBSession.flush()
            DBSession.refresh(new_workposition)
            return{'status': 'ok' ,'name':  name, 'id' : new_workposition.id} 
        else:
            return{'status': 'workposition with name '+name+' is in databse already'}
    elif type_to_add == "workplace":
        print('*' * 500)
        print(name)
        city = name.split('!')[0]
        address = name.split('!')[1]
        if request.db_session.query(Workplace).filter(Workplace.address == address).first() == None:
            new_workplace =  Workplace(get_user(request), city, address)
            DBSession.add(new_workplace)
            DBSession.flush()
            DBSession.refresh(new_workplace)
            return{'status': 'ok' ,'name':  name, 'id' : new_workplace.id} 
        else:
            return{'status': 'workposition with name '+name+' is in databse already'}
    if type_to_add == "hash_employee":
        if request.db_session.query(Hash_employee).filter(Hash_employee.name == name, Hash_employee.type == 1, Hash_employee.by_user_id == get_verified_user_id(request)).first() == None:
            hash_zamestnanec = Hash_employee(get_user(request), name, 1)
            DBSession.add(hash_zamestnanec)
            DBSession.flush()
            DBSession.refresh(hash_zamestnanec)
            return{'status': 'ok' ,'name':  name, 'id' : hash_zamestnanec.id} 
        else:
            return{'status': 'employee hashtag with name '+name+' is in databse already'}
    if type_to_add == "hash_event":
        if request.db_session.query(Hash_employee).filter(Hash_employee.name == name, Hash_employee.type == 0, Hash_employee.by_user_id == get_verified_user_id(request)).first() == None:
            hash_zamestnanec = Hash_employee(get_user(request), name, 0)
            DBSession.add(hash_zamestnanec)
            DBSession.flush()
            DBSession.refresh(hash_zamestnanec)
            return{'status': 'ok' ,'name':  name, 'id' : hash_zamestnanec.id} 
        else:
            return{'status': 'event hashtag with name '+name+' is in databse already'}
Exemplo n.º 24
0
def spracuj_data_do_db(titulok, obsah, request):
    text = obsah + titulok
    priemer_celkove = sentimental_hodnota_textu(text, request)
    clanok = Article(titulok, obsah, priemer_celkove, datetime.date.today())
    DBSession.add(clanok)
    return clanok
Exemplo n.º 25
0
def home(request):
    u = User('mathes', 'mathes', 'admin')
    DBSession.add(u)
    user =  request.db_session.query(User).first()
    typ =  Employees_type(user, 'picker')
    typ2 =  Employees_type(user, 'manager')
    DBSession.add(typ)
    DBSession.add(typ2)

    employee = Employee(user, 'Ladislav', 'Jakab', typ, 21)
    DBSession.add(employee)
    
    miesto = Workplace(user, 'Bratislava', 'Kadnarová 20')
    miesto2 = Workplace(user, 'Senec', 'Letna 12')
    DBSession.add(miesto2)
    DBSession.add(miesto)
    hash_zamestnanec = Hash_employee(user, 'junior')
    DBSession.add(hash_zamestnanec)
    hash_zamestnanec2 = Hash_employee(user, 'senior')
    DBSession.add(hash_zamestnanec2)
    porovnavacka = Comparison(user, hash_zamestnanec, hash_zamestnanec2)
    DBSession.add(porovnavacka)
    zaciatok_eventu = datetime.datetime(2007, 12, 6, 15, 30, 0, 0)
    koniec_eventu = datetime.datetime(2007, 12, 6, 18, 30, 0, 0)
    event = Event(user, employee, 'druhy event', zaciatok_eventu, koniec_eventu)
    task = Task(employee, event)
    DBSession.add(task)
    DBSession.add(event)
    print(event)
    
    return{}