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)
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()
def create_wallet(): session = session_factory() walletA = Wallet("0x12345", 1000, "") walletB = Wallet("0x12345", 2000, "") session.add(walletA) session.add(walletB) session.commit() session.close()
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"})
def get_people(): session = session_factory() people_query = session.query(Person) session.close() return people_query.all()