def post(self): print('get_auth_template') admin_base = self.get_admin_base() if admin_base is None: return self.send_faild(error.ERROR_NO_LOGIN) if self.is_god() is False: return self.send_faild(error.ERROR_AUTH_PERMISSION) data = self.get_post_data() try: admin_temp_name = data['admin_temp_name'] start_time = data['start_time'] end_time = data['end_time'] status = data['status'] except Exception as e: print(e) return self.send_faild(error.ERROR_PARAM) if admin_temp_name == '': admin_temp_name = "%" if start_time != '': start_time += ' 00:00:00' start_time = str_to_time(start_time) else: start_time = 0 if end_time != '': end_time += ' 00:00:00' end_time = str_to_time(end_time) else: end_time = int(time.time()) res = Data.select('admin_temp', [('name', 'like', '%{}%'.format(admin_temp_name)), ('status', '=', 0)]) admin_temp_list = [] if res: for temp in res: if start_time <= int(temp['ctime']) <= end_time: if status == temp['status']: temp['ctime'] = time_to_str(int(temp['ctime'])) admin_temp_list.append(temp) result = {'auth_temp_list': admin_temp_list} self.send_ok(result) return
def test_rent_change_bill(self): """ test body :return: """ # 给get或者post方法配置Http地址 self.localConfigHttp = configHttp_new.ConfigHttp() # 接口地址存储在excel文件里,读取出来 self.localConfigHttp.set_url(self.service_id) # set params data = json.loads(self.data) # 判断是否需要token if self.token == 1: f = open(token_fiel_path, 'r') token_tmp = f.readline() data['access_token'] = token_tmp print '获取到的最新token:', data['access_token'] # 判断是否需要获取验证码 if 'sms_code' in data: sql = localReadConfig.get_sql('sql_yzm') yzm = configDB.MyDB().zhiyu_yzm(sql) data['sms_code'] = yzm # 获取house_id,如果excel表格里house_id为空,则取ini文件里的house_id,否则取excel里的house_id if 'house_id' in data: if data['house_id'] == '': house_id = localReadConfig.get_ini('PARAMS', 'house_id') data['house_id'] = house_id # 获取时间戳 time_now = common.get_time_now() data['timestamp'] = time_now # 退房日期相关 time_now_date = common.str_to_time(time_now) data['change_date'] = time_now_date # AES加密 params_miwen = encryptLib.zhiyu_aes_encode(data) # 真正的入参 params = { 'param': params_miwen } self.localConfigHttp.set_params(params) # 获取响应结果信息 if self.method.lower() == 'get': self.response = self.localConfigHttp.get() print 'get' elif self.method.lower() == 'post': self.response = self.localConfigHttp.post() print 'post' # 显示响应结果信息 common.show_return_msg(self.response) self.info = self.response.text # Json响应信息转成字典格式 self.info = json.loads(self.info) # 断言返回状态码 self.assertEqual(self.info['err_no'], self.expect_state) # 断言返回message mes_reponse = self.info['err_msg'].encode('utf-8') self.assertEqual(mes_reponse, self.expect_msg)
def machine_start(imei, pulse=12, high=100, low=100): # res = dev_v2.get_dev_status(imei) # if res != None: rep = Data.find('CWS_APP.latestreport', [('imei', '=', imei)]) if int(time.time()) - common.str_to_time(str( rep['time'])) < config.dev_heart_beat: v2 = dev_v2.get_dev_start(imei) if v2 != None: if v2 == 0: print(v2) return True if v2 == -1: print(v2) return False # 先走v2信号 if rep['status'] == 'heart': return False print('V2信号没有走通') imei = imei pulse = 12 money = pulse device_type = 1 duration = 5 high = high low = low topic = 'deveventreq' data = bytearray([0x54, device_type]) data += money.to_bytes(4, 'big') data += duration.to_bytes(4, 'big') data += high.to_bytes(4, 'big') data += low.to_bytes(4, 'big') data += pulse.to_bytes(4, 'big') dbg('发送的信号', data) mongodata = { 'imei': imei, 'datagram_type': 1, 'device_type': device_type, 'duration': duration, 'high': high, 'low': low, 'pulse': pulse } result = MQ.send_data(imei, topic, data) if result and result['result']: mongodata['result'] = 0 # 成功 dbapi.insert_datagram(mongodata) # device = dbapi.get_device(imei=imei) return True else: mongodata['result'] = 1 # 设备正在运行 dbapi.insert_datagram(mongodata) return False
def post(self): print('get_player_list') admin_base = self.get_admin_base() if admin_base is None: return self.send_faild(error.ERROR_NO_LOGIN) if not self.is_god(): return self.send_faild(error.ERROR_AUTH_PERMISSION) try: data = self.get_post_data() player_name = data['player_name'] player_phone = data['player_phone'] start_time = data['start_time'] end_time = data['end_time'] status = data['status'] # 0代表用户账户正常,1代表冻结 except Exception as e: print(e) return self.send_faild(error.ERROR_PARAM) if player_phone == '': player_phone = "%" if start_time != '': start_time += ' 00:00:00' start_time = str_to_time(start_time) else: start_time = 0 if end_time != '': end_time += ' 00:00:00' end_time = str_to_time(end_time) else: end_time = int(time.time()) players = [] player_list = Data.select( 'player', [('phone', 'like', '%{}%'.format(player_phone))], order=('join_time', 'desc')) if player_list: for player in player_list: if start_time <= int(player['join_time']) <= end_time: players.append(player) res_list = list(map(admin_tools.get_player_list, players)) else: res_list = [] res = [] for i in res_list: if i == None: continue if player_name != '': if player_name in i['name']: res.append(i) else: res.append(i) res1 = [] for i in res: if int(status) == i['status']: res1.append(i) result = {'player_info_list': res1} self.send_ok(result) write_admin_record(operate_id=admin_base['id'], operate_desc='会员管理首页') return
def post(self): print('get_devices_list') admin_base = self.get_admin_base() if admin_base is None: return self.send_faild(error.ERROR_NO_LOGIN) if self.is_god() is False: return self.send_faild(error.ERROR_AUTH_PERMISSION) try: data = self.get_post_data() imei = data['imei'] player_name = data['player_name'] phone = data['phone'] start_time = data['start_time'] end_time = data['end_time'] status = data['status'] except Exception as e: print(e) return self.send_faild(error.ERROR_PARAM) if start_time != '': start_time += ' 00:00:00' start_time = str_to_time(start_time) else: start_time = 0 if end_time != '': end_time += ' 00:00:00' end_time = str_to_time(end_time) else: end_time = int(time.time()) devices = Data.select('devices', [('id', '!=', 0)]) devices_list = [] if devices: for device in devices: user_id = device['user_id'] user_info = Data.find('player', [('id', '=', user_id)]) if user_info is None: continue dev_info = Data.find('dev_main', [('id', '=', device['id'])]) if dev_info is None: continue params = {} params['id'] = device['id'] params['player_name'] = user_info['nickname'] params['phone'] = user_info['phone'] params['imei'] = device['imei'] params['ctime'] = device['ctime'] params['status'] = device['status'] devices_list.append(params) # 筛选 res = [] res1 = [] res2 = [] res3 = [] res4 = [] if len(devices_list) > 0: for i in devices_list: if start_time <= str_to_time(i['ctime']) <= end_time: res.append(i) for i in res: if imei in i['imei']: res1.append(i) for i in res1: if player_name in i['player_name']: res2.append(i) for i in res2: if phone in i['phone']: res3.append(i) for i in res3: if status == i['status']: res4.append(i) result = {'devices_list': res4} self.send_ok(result) write_admin_record(operate_id=admin_base['id'], operate_desc='获取设备列表') return
def __normalize(self, session_log): ''' Normalize and fill missing fields in a session log :param session_log: climbing session object :type session_log: dict :return: normalized session object :rtype: dict ''' try: available_fields = session_log.keys() location = get_location(session_log['location']) if not location: raise Exception( f"No location found for {session_log['location']}. Current supported locations include: {get_location_names()}") # Split the style field by commas and turn it into a list instead # This is because style could be multiple fields ie. indoor bouldering, indoor lead session_log['style'] = session_log['style'].split(',') # Compare the counter list with the location's grading scale # If any counters are missing, add to it and just defult to 0 for all categories counted_grades = [] for counter in session_log['counter']: counted_grades.append(counter['grade']) missing_counters = list( set(location.grading) - set(counted_grades)) for counter in missing_counters: default_counter = {'grade': counter, 'flash': 0, 'redpoint': 0, 'repeat': 0, 'attempts': 0} if location.is_outdoor: default_counter['onsight'] = 0 session_log['counter'].append(default_counter) session_log['counter'] = reformat_counter( session_log['counter']) # Look at the optional fields and add filler values if 'climbers' not in available_fields: session_log['climbers'] = None if 'injury' not in available_fields: session_log['injury'] = {'isTrue': False, 'description': None} elif session_log['injury']['isTrue'] == False and session_log['injury']['description'] == 'Add a description of injury here': session_log['injury'] = {'isTrue': False, 'description': None} if 'media' not in available_fields: session_log['media'] = None if 'projects' not in available_fields: session_log['projects'] = None else: for climb in session_log['projects']: if 'notes' not in climb.keys(): climb['notes'] = None if 'media' not in climb.keys(): climb['media'] = None session_log['projects'] = reformat_projects( session_log['projects']) # Initializing Timezone info tf = TimezoneFinder() location = get_location(session_log['location']) location_tz = pytz.timezone(tf.timezone_at( lng=location.lon, lat=location.lat)) # Add time zone to start and end times local_start = location_tz.normalize(location_tz.localize(datetime.datetime.combine( session_log['date'], common.str_to_time(session_log['time']['start']).time()))) local_end = location_tz.normalize(location_tz.localize(datetime.datetime.combine( session_log['date'], common.str_to_time(session_log['time']['end']).time()))) # Convert to UTC session_log['date'] = datetime.datetime.combine( session_log['date'], common.str_to_time(session_log['time']['start']).time()) session_log['time']['start'] = local_start session_log['time']['end'] = local_end return session_log except Exception as ex: raise ex
def post(self): print('get_adv_list') admin_base = self.get_admin_base() if admin_base is None: return self.send_faild(error.ERROR_NO_LOGIN) if not self.is_god(): return self.send_faild(error.ERROR_AUTH_PERMISSION) try: data = self.get_post_data() adv_name = data['adv_name'] postion = data['postion'] start_time = data['start_time'] end_time = data['end_time'] status = data['status'] except Exception as e: print(e) return self.send_faild(error.ERROR_PARAM) if adv_name == '': adv_name = "%" if start_time != '': start_time += ' 00:00:00' start_time = str_to_time(start_time) else: start_time = 0 if end_time != '': end_time += ' 00:00:00' end_time = str_to_time(end_time) else: end_time = int(time.time()) adv = [] adv_list = Data.select('adv', [('adv_name', 'like', '%{}%'.format(adv_name))], order=('add_time', 'desc')) if adv_list: for ad in adv_list: if start_time <= int(ad['add_time']) <= end_time: params = {} params['adv_name'] = ad['adv_name'] params['postion'] = ad['postion'] params['img'] = ad['img'] params['url'] = ad['url'] params['ctime'] = ad['ctime'] params['comment'] = ad['comment'] params['status'] = ad['status'] adv.append(params) res = [] if adv: for i in adv: if i == None: continue if postion != '': if postion in i['postion']: res.append(i) else: res.append(i) res1 = [] for i in res: if int(status) == i['status']: res1.append(i) result = {'adv_info_list': res1} self.send_ok(result) write_admin_record(operate_id=admin_base['id'], operate_desc='广告列表') return
def get_bookings(driver, location, capacity, url, zone=None): ''' Gathering the booking information based on the location :param driver: Selenium driver :param location: The location of the climbing gym :param capacity: The max capacity of a climbing gym :param url: Rockgympro booking url :param zone: Optional zone/subsection of gym :type driver: driver :type location: str :type capacity: int :type url: str :return: Booking infomation :rtype: dict ''' try: # Getting the current time current_time = str(datetime.now().isoformat()) current_year = str(datetime.now().year) current_day = datetime.now().day current_day_of_week = datetime.now().strftime('%A') driver.get(url) # Click on the current date, find the selected date and verify driver.find_element_by_xpath( "//td[contains(@class,'ui-datepicker-today')]").click() selected_day = int( driver.find_element_by_xpath( "//a[contains(@class,'ui-state-active')]").text) if selected_day != current_day: raise Exception( f"[{current_time}] Unable to select the current date... Selected {selected_day} instead" ) sleep(5) # Find the first time slot and it's availability time_slot = driver.find_element_by_class_name( 'offering-page-schedule-list-time-column').text availability = driver.find_element_by_xpath( "//td[@class='offering-page-schedule-list-time-column']/following-sibling::td" ).text # Checking availability if 'Full' in availability: availability = 0 # For Gatineau location, this means 50-75 available spots. Since leaving it NULL will skew, and there is no way to calculate the spots # Choosing to set availability 1/2 way between 50 and 75 (max) elif 'Available' in availability: availability = 57.5 else: try: availability = int( availability.replace('Availability', '').replace( 'spaces', '').replace('space', '').strip('\n').strip()) except ValueError as ex: print( f"[{current_time}] Warning: Unpredicted format, `{availability}`, ignoring conversion to integer" ) # Parsing data __, date, time = time_slot.split(',') month, day = date.strip().split() # # If dates don't match up, then manually set the next session time, assuming the availability is 0 # if int(day) != current_day: # # Get the last session time from JSON and set the time to the next session time # last_booking = common.get_last_document(OUTPUT_FILE) # last_session = last_booking['time_slot'] # next_session = time_slots[time_slots.index(last_session)+1] # # Overwrite the time slot # time = next_session # availability = 0 # print( # f"[{current_time}] WARNING: Unable to select the current date. Assuming session is full, and continuing...") # Parse time slot to start and end times start = time.split('to')[0].strip() end = time.split('to')[1].strip() # Converting to HH:MM AM/PM format start = common.convert_to_hhmm(start) end = common.convert_to_hhmm(end) booking = { 'location': location, 'month': month.strip(), 'day_of_week': current_day_of_week, 'day': day.strip(), 'year': current_year, 'time_slot': time.strip(), 'start_time': start, 'start_hour': int(common.str_to_time(start).hour), 'start_minute': int(common.str_to_time(start).minute), 'end_time': end, 'availability': availability, 'reserved_spots': capacity - availability if availability is not None else None, 'capacity': capacity, 'zone': zone, 'retrieved_at': current_time } return booking except Exception as ex: driver.quit() raise ex
def post(self): print('get_admin_list') admin_base = self.get_admin_base() if admin_base is None: return self.send_faild(error.ERROR_NO_LOGIN) if self.is_god() is False: return self.send_faild(error.ERROR_AUTH_PERMISSION) try: data = self.get_post_data() username = data['username'] start_time = data['start_time'] end_time = data['end_time'] status = data['status'] except Exception as e: print(e) return self.send_faild(error.ERROR_PARAM) if username == '': username = "******" if start_time != '': start_time += ' 00:00:00' start_time = str_to_time(start_time) else: start_time = 0 if end_time != '': end_time += ' 00:00:00' end_time = str_to_time(end_time) else: end_time = int(time.time()) god_info = Data.select('admin', [('username', 'like', '%{}%'.format(username))]) admins = [] for item in god_info: params = {} admin_data = Data.find('admin_auth', [('god_id', '=', item['id'])]) if admin_data: if start_time <= str_to_time(item['ctime']) <= end_time: if status == item['status']: params['admin_id'] = item['admin_id'] params['username'] = item['username'] params['ctime'] = str(item['ctime']) params['status'] = item['status'] params['temp_id'] = admin_data['auth_id'] temp_data = Data.find('admin_temp', [('id', '=', admin_data['auth_id']), ('status', '=', 0)]) if temp_data: params['temp_name'] = temp_data['name'] else: params['temp_name'] = '无权限' admins.append(params) result = { 'admin_list': admins } self.send_ok(result) write_admin_record(operate_id=admin_base['id'], operate_desc='获取管理员列表') return
def get_last_connect_time(imei): res = Data.find('CWS_APP.latestreport', [('imei', '=', imei)]) if res == None: return 0 return common.str_to_time(str(res['time']))
def post(self): player_base = self.get_player_base() if player_base is None: return self.send_faild(error.ERROR_NO_USER) try: data = self.get_post_data() name = data['name'] group_name = data['group_name'] comment = data['comment'] start_time = data['start_time'] end_time = data['end_time'] except Exception as e: print(e) return self.send_faild(error.ERROR_PARAM) if start_time != '': start_time += ' 00:00:00' start_time = str_to_time(start_time) else: start_time = 0 if end_time != '': end_time += ' 00:00:00' end_time = str_to_time(end_time) else: end_time = int(time.time()) report_list = [] # 关联的手机号 user = Data.find('player', [('id', '=', player_base['id'])]) phone = user['phone'] # 所有用户列表 player_list = Data.select('player_member', [('id', '=', 0)]) # 要查的使用记录的id列表 player_id_list = [] # 通过组查id group_id = [] group_info = Data.select('player_group', [('player_id', '=', player_base['id'])]) if group_info != None: for row in group_info: group_id.append(row['id']) for player in player_list: if len(group_id) > 0: if player['group_id'] in group_id: player_id_list.append(player['id']) elif player['phone'] == phone: player_id_list.append(player['id']) if len(player_id_list) > 0: for id in player_id_list: # 一个人可能多条记录 player_info = Data.find('player_member', [('id', '=', id)]) if player_info == None: continue group = Data.find('player_group', [('id', '=', player_info['group_id'])]) if group == None: continue test_report_list = Data.select('user_test_result', [('user_id', '=', id)]) if test_report_list == None: continue for test_report in test_report_list: params = {} params['name'] = player_info['name'] params['group'] = group['name'] params['group_id'] = group['group_id'] params['imei'] = test_report['imei'] params['test_time'] = test_report['test_time'] params['left_eye'] = test_report['left_eye'] params['astigmatism_left'] = test_report[ 'astigmatism_left'] params['right_eye'] = test_report['right_eye'] params['astigmatism_right'] = test_report[ 'astigmatism_right'] params['comment'] = test_report['comment'] report_list.append(params) res1 = [] res2 = [] res3 = [] res4 = [] if len(report_list) > 0: for i in report_list: if name != '': if name in i['name']: res1.append(i) else: res1.append(i) for i in res1: if group_name != '': if group_name in i['group']: res2.append(i) else: res2.append(i) for i in res2: if comment != '': if comment in i['group']: res3.append(i) else: res3.append(i) for i in res3: if start_time <= str_to_time(i['test_time']) <= end_time: res4.append(i) else: res4.append(i) reply = {'report_list': res4} self.send_ok(reply) return