Beispiel #1
0
def readlog():
    req_data = flask.request.get_json(force=True)
    str1 = str(req_data).replace("\'", "\"")
    input_dict = json.loads(str1)
    flag = input_dict["flag"]
    searchkeyword = input_dict["searchkeyword"]
    searchresult = []

    if flag == '1':
        session = session_factory()
        logs = session.query(log).filter(log.log_description.like('%' + searchkeyword + '%')).all()
        session.close()

    # x = logs.all()
        for x1 in logs:
            searchresult.append({x1.log_description + ' ' + str(x1.log_date) + '  ' + x1.ip_address})

    if flag == '2':
        filePath = os.path.abspath("log.txt")
        with open(filePath, 'r') as searchfile:
            for line in searchfile:
                if searchkeyword in line:
                    searchresult.append(line)

    return str(searchresult)
Beispiel #2
0
def create_people():
    session = session_factory()
    bruno = Person("Bruno Krebs", date(1984, 10, 20), 182, 84.5)
    john = Person("John Doe", date(1990, 5, 17), 173, 90)
    session.add(bruno)
    session.add(john)
    session.commit()
    session.close()
Beispiel #3
0
def create_wallet():
    session = session_factory()
    walletA = Wallet("0x12345", 1000, "")
    walletB = Wallet("0x12345", 2000, "")
    session.add(walletA)
    session.add(walletB)
    session.commit()
    session.close()
Beispiel #4
0
def writelog():
    req_data = flask.request.get_json(force=True)
    str1 = str(req_data).replace("\'", "\"")
    input_dict = json.loads(str1)
    flag = input_dict[0]["flag"]
    if flag == '1':
        session = session_factory()
        # insert record in database
        for i in input_dict:
            logMsgBody = log(i["logMsg"], date.today(), i["ipAddress"])
            session.add(logMsgBody)
            session.commit()
        session.close()
    else:
        filePath = os.path.abspath("log.txt")
        file1 = open(filePath, "a+")
        for i in input_dict:
            file1.write(i["logMsg"] + '   ' + str(datetime.datetime.now()) + '   ' + i["ipAddress"] + "\n")
        file1.close()

    return flask.jsonify({"msg": "log successfully inserted"})
Beispiel #5
0
def get_people():
    session = session_factory()
    people_query = session.query(Person)
    session.close()
    return people_query.all()