def test_db_upsert(db): history = [ History(datetime.datetime(2016, 12, 31, 23, 59, 59), "mozillo1"), History(datetime.datetime(2015, 11, 30, 22, 58, 59), "mozillo2") ] session = [ Session(datetime.datetime(2016, 12, 31, 23, 59, 59), "mozillo1", "192.0.0.1", "msk") ] user = User(1, "test_user", history, session) db.upsert_user(user) return
def history_add_multiple(): user_id = get_jwt_identity() parking_id = [1,2,3,4,5,6,7,8] for parking in parking_id: history_inst = History(user_id = user_id, parking_id = parking) history_inst.save()
def add_history(): auth_header = request.headers.get('Authorization') if auth_header: auth_token = auth_header.split(" ")[1] else: responseObject = { 'status': 'failed', 'message': 'No authorization header found' } return make_response(jsonify(responseObject)), 401 user_id = User.decode_auth_token(auth_token) user = User.get_by_id(user_id) # save link that has been clicked on clicked_link = request.get_json('link') history = History(link=clicked_link, user_id=user.id) history.save() # sendgrid send email to user.email send_email(email)
def post(self): """새로운 댓글 분석 요청 :return: {'status': 'success', 'unknown error'} """ parser = reqparse.RequestParser() parser.add_argument('userId', required=True, type=str) parser.add_argument('keyword', required=True, type=bool) parser.add_argument('sentiment', required=True, type=bool) parser.add_argument('url', required=True, type=str) parser.add_argument('slang', required=True, type=bool) args = parser.parse_args(strict=True) try: history = History(userId=args['userId'], keyword=args['keyword'], sentiment=args['sentiment'], url=args['url'], slang=args['slang']) db.session.add(history) db.session.commit() return {'status': 'success'} except: return {'status': 'unknown error'}
def handle(self): self.possible_responses = { 'login': self.login, 'logout': self.logout, 'msg': self.msg, 'names': self.names, 'help': self.help, 'history': self.history } self.logged_in = False self.name = None self.history_mod = History("messages.json") self.names_mod = Names('db.json') self.ip = self.client_address[0] self.port = self.client_address[1] self.connection = self.request threads.append(self) # Loop that listens for messages from the client while True: received_string = self.connection.recv(4096) payload = json.loads(received_string.decode()) if payload['request'] in self.possible_responses: self.possible_responses[payload['request']](payload) else: self.error("Illegal request {}".format(payload['request']))
def post(self): json_data = request.get_json() current_user = get_jwt_identity() try: data = history_schema.load(data=json_data) except ValidationError as errors: return {'message': 'Validation errors', 'errors': errors.messages}, HTTPStatus.BAD_REQUEST history = History(**data) history.user_id = current_user history.save() return history_schema.dump(history), HTTPStatus.CREATED
def testHistoryLengthOnlyOneData(self): history = History(2) history.add_log(['1']) # if only one entry you can do more or less nothing.. self.assertEqual(['1'], history.get_log()) history.increase_cursor() self.assertEquals(['1'], history.get_log()) history.decrease_cursor() self.assertEquals(['1'], history.get_log()) history.increase_cursor() self.assertEquals(['1'], history.get_log()) history.go_to_the_top() self.assertEquals(['1'], history.get_log())
def xpath_user_history(self, content): tree = html.fromstring(content) logging.debug("DOM created...") tmp = ' '.join( str(x) for x in tree.xpath( '//div[contains(@class, "light_blue")]/text()')) if "Здесь вы сможете проверить, не заходил ли кто-то чужой под вашим ником!" in tmp: logging.error("History protection (admin?)") return [] hist_raw_list = tree.xpath( '//div[contains(@class,"list_item")]/span/following-sibling::text()[1]' ) hist_list = [] logging.debug("List items: " + str(len(hist_raw_list))) l = len(hist_raw_list) for i in range(0, l, 2): device = "" logging.debug(str(i) + " // Date raw: " + hist_raw_list[i]) date = self.spac_date.get_python_time(hist_raw_list[i]) logging.debug("RawTime: " + str(date)) logging.debug(str(i + 1) + " // UA raw: " + hist_raw_list[i + 1]) ua = hist_raw_list[i + 1].strip() logging.debug("UA: " + ua) if l == i + 3 and l % 2 == 1: device = hist_raw_list[i + 2] logging.debug("Device: " + device) hist_list.append(History(date, ua, device)) return hist_list hist_list.append(History(date, ua, device)) return hist_list
def testHistoryLengthAndMovement(self): history = History(2) history.add_log(['1', '2', '3', '4']) # we only the last 2 one self.assertEqual(['3', '4'], history.get_log()) history.increase_cursor() # if we want to the next line do nothing self.assertEquals(['3', '4'], history.get_log()) history.decrease_cursor() self.assertEquals(['2', '3'], history.get_log()) # the increase work history.increase_cursor() self.assertEquals(['3', '4'], history.get_log()) history.go_to_the_top() self.assertEquals(['1', '2'], history.get_log())
def main(): args = get_args() history = History(calc_ops) if args.history_file_path: with open(args.history_file_path) as history_file: history.from_json(history_file.read()) command = "noop" while command: log_command(command) command_fn = app_commands.get(command, command_unknown) command_fn(history) command = get_command()
def add_history(): clicked_link = request.get_json() auth_header = request.headers.get('Authorization') if not auth_header: responseObject = { 'status': 'failed', 'message': 'No JWT in Authorization Header' } return make_response(jsonify(responseObject)), 401 # decode the auth_token to get the user_id auth_token = auth_header.split(" ")[1] user_id = User.decode_auth_token(auth_token) current_user = User.get_by_id(user_id) # save link that has been clicked on if current_user and clicked_link: email = current_user.email name = current_user.name # sendgrid send email to user.email send_email(email) history = History( link=clicked_link['link'], user_id=current_user.id) if history.save(): responseObject = { 'status': 'success' } return make_response(jsonify(responseObject)), 201 else: responseObject = { 'status': 'failed', 'message': 'History not saved' } return make_response(jsonify(responseObject)), 401 else: responseObject = { 'status': 'failed', 'message': 'No authorization header found' } return make_response(jsonify(responseObject)), 401
def history_db(): with open('histories.csv', mode='r') as his_file: hist_reader = csv.reader(his_file) line_count = 0 for row in hist_reader: if line_count == 0: line_count += 1 else: his = History(car_id=row[0], lat=row[1], long=row[2], fuel_level=row[3], dtc=row[4], timestamp=datetime.strptime( row[5], '%d-%m-%y %H:%M:%S'), engine_temp=row[6], oil_temp=row[7], odometer=row[8]) db.session.add(his)
def upload_files(): if request.method == 'POST': file = request.files['data'] # history_id = request.form['id'] if file and allowed_file(file.filename): history = History(request.form.to_dict(), file.filename) history.insert() user = User(request.form.to_dict()) user.insert() filename = secure_filename(file.filename) print(os.path.join(UPLOAD_FOLDER, filename)) file.save(os.path.join(UPLOAD_FOLDER, filename)) print(jsonify(filename=filename)) return jsonify(filename=filename) return jsonify(status='error'), 500 # show upload page. return render_template('upload.html', get_histories=get_histories)
def history_add(): user_id = get_jwt_identity() user_inst = User.get_by_id(user_id) parking_id = request.json.get('parking_id') parking_inst = Parking.get_by_id(parking_id) floor_inst = Floor.get_by_id(parking_inst.floor_id) mall_inst = Mall.get_by_id(floor_inst.mall_id) history_inst = History(user_id = user_id, parking_id = parking_id) if history_inst.save(): responseData = client.send_message({ 'from': 'Nexmo', 'to': user_inst.hp_number, 'text': 'RM0.00 EzPark: Your car is parked in Mall: [' + mall_inst.outlet + '], at Floor: [' + floor_inst.floor + '], in Parking Bay: [' + parking_inst.parking_num + ']///' }) # if responseData["messages"][0]["status"] == "0": responseObj = { 'status': 'success', 'message': 'Successfully saved your parking!' } return jsonify(responseObj), 200 # else: # responseObj = { # 'status': 'failed', # 'message': 'Message sent failed' # } # return jsonify(responseObj), 400 else: responseObj = { 'status': 'failed', 'message': 'Parking failed to save!' } return jsonify(responseObj), 400
def __init__(self, state): self._state = state self._history = History()
def testConstructor(self): history = History(5) self.assertEquals([], history.get_log()) history.add_log(['1', '2', '3', '4', '5']) self.assertEquals(['1', '2', '3', '4', '5'], history.get_log())