def auth_google(): token = cfg.get_setting(path, 'Google', 'Token') if token == "": token = input("Enter Google token:") cfg.update_setting(path, 'Google', 'Token', token) cred = { "token": token } with requests.Session() as s: r = s.get(url + '/login/google', params = cred)
def choose_resume_id(): print("Choose one from the list:") list = { } for res in get_resume(): print("ID: " + str(res['id']) + " NAME: " + str(res['name'])) list[res['id']] = res['name'] print (list) resume_id = input("Paste resume ID: ") cfg.update_setting(path, 'Resume', 'id', resume_id) cfg.update_setting(path, 'Resume', 'name', list[int(resume_id)]) return resume_id
def auth_fb(): token = cfg.get_setting(path, 'Facebook', 'Token') if token == "": token = input("Enter Facebook token:") cfg.update_setting(path, 'Facebook', 'Token', token) cred = { "token": token } with requests.Session() as s: r = s.get(url + '/login/facebook/token', params=cred) if r.status_code == 200: print("Success. Session created...") return s else: print(r.json()['message']) cfg.update_setting(path, 'Facebook', 'Token', '') auth_fb()
def switcher(): choice = cfg.get_setting(path, 'Authentication', 'default') if choice == "": print ("Press 1 - to login as user, 2 - to login via fb, 3 - to login via google") choice = input("Choose: ") cfg.update_setting(path, 'Authentication', 'default', choice) if choice == "1": print("Login using email/pass") return auth() if choice == "2": print("Login using auth via fb") return auth_fb() if choice == "3": print("Login using auth via google") return auth_google() else: print("Not correct option. Try again...") switcher()
def auth(): login = cfg.get_setting(path, 'Authentication', 'Login') if login == "": login = input("Enter username:"******"": password = input("Enter password:"******"username": login, "password": password, "remember": "true" } with requests.Session() as s: p = s.post(url + "/account/login", data=cred) r = s.get(url + "/account/login") if p.status_code == 204: print("Success. Session created...") # print(p.json()['message']) wlcm_msg = "Hi! " + str(r.json()['firstName']) + " " + str(r.json()['lastName']) print(wlcm_msg) return s else: print(p.status_code) if p.status_code == 400: print("Username/password incorrect. Try again") print(p.json()['message']) login = cfg.update_setting(path, 'Authentication', 'Login', "") password = cfg.update_setting(path, 'Authentication', 'Password', "") auth()
def use_code(code): token_response = client.exchange_code_for_token( client_id=client_id, client_secret=client_secret, code=code) access_token = token_response['access_token'] refresh_token = token_response['refresh_token'] expires_at = token_response['expires_at'] c.update_setting(c.SECTION_SETTINGS, c.ACCESS_TOKEN, access_token) c.update_setting(c.SECTION_SETTINGS, c.REFRESH_TOKEN, refresh_token) c.update_setting(c.SECTION_SETTINGS, c.EXPIRES_AT, str(expires_at)) return client
def check_token(self): if time.time() > self.expires_at: self.access_token = self.sc.refresh_access_token( self.client_id, self.client_secret, self.refresh_token) c.update_setting(c.SECTION_SETTINGS, c.ACCESS_TOKEN, str(self.access_token))
def main(): config.update_setting() if config.b_play_audio: audios_manager.play_audio(audio_index=audios_manager.AudioType.start) # 数据处理对象 data_manager_obj = data_manager.DataManager() # 查询改船是否注册 若未注册直接退出 try: binding_data = data_manager_obj.send( method='http', data="", url=config.http_binding, http_type='GET') if int(binding_data['flag']) != 1: if config.b_play_audio: audios_manager.play_audio('register.mp3') logger.error({'binding status': binding_data['flag']}) logger.info({'binding status': binding_data['flag']}) except Exception as e1: logger.error({'binding_data error': e1}) # 启动串口数据收发和mqtt数据收发 树莓派对象数据处理 if config.current_platform == config.CurrentPlatform.pi: change_pwm_thread = threading.Thread(target=data_manager_obj.pi_main_obj.loop_change_pwm) if os.path.exists(config.stc_port): get_com_data_thread = threading.Thread(target=data_manager_obj.get_com_data) if config.b_pin_gps: soft_gps_thread = threading.Thread(target=data_manager_obj.pi_main_obj.get_gps_data) if config.b_pin_compass: soft_compass_thread = threading.Thread(target=data_manager_obj.pi_main_obj.get_compass_data) if config.b_laser: get_distance_thread = threading.Thread(target=data_manager_obj.pi_main_obj.get_distance_dict) elif config.b_millimeter_wave: get_distance_thread = threading.Thread(target=data_manager_obj.pi_main_obj.get_distance_dict_millimeter) if config.b_laser or config.b_millimeter_wave: send_distacne_thread = threading.Thread(target=data_manager_obj.send_distacne) if config.b_laser or config.b_pin_stc: stc_data_thread = threading.Thread(target=data_manager_obj.pi_main_obj.get_stc_data) move_control_thread = threading.Thread(target=data_manager_obj.move_control) check_status_thread = threading.Thread(target=data_manager_obj.check_status) send_mqtt_data_thread = threading.Thread(target=data_manager_obj.send_mqtt_data) update_ship_gaode_thread = threading.Thread(target=data_manager_obj.update_ship_gaode_lng_lat) update_lng_lat_thread = threading.Thread(target=data_manager_obj.update_lng_lat) update_config_thread = threading.Thread(target=data_manager_obj.update_config) check_ping_delay_thread = threading.Thread(target=data_manager_obj.check_ping_delay) # check_status_thread.setDaemon(True) # move_control_thread.setDaemon(True) # send_mqtt_data_thread.setDaemon(True) # update_ship_gaode_thread.setDaemon(True) # update_lng_lat_thread.setDaemon(True) # update_config_thread.setDaemon(True) # check_ping_delay_thread.setDaemon(True) # send_distacne_thread.setDaemon(True) # if config.current_platform == config.CurrentPlatform.pi: # change_pwm_thread.setDaemon(True) # if os.path.exists(config.stc_port): # get_com_data_thread.setDaemon(True) # if os.path.exists(config.compass_port): # compass_thread.setDaemon(True) # if os.path.exists(config.compass_port1): # compass_thread1.setDaemon(True) # if os.path.exists(config.gps_port): # gps_thread.setDaemon(True) # if config.b_use_ultrasonic: # left_distance_thread.setDaemon(True) # right_distance_thread.setDaemon(True) # if config.b_pin_gps: # soft_compass_thread.setDaemon(True) # soft_gps_thread.setDaemon(True) # if config.b_laser: # get_distance_thread.setDaemon(True) check_status_thread.start() send_mqtt_data_thread.start() move_control_thread.start() update_ship_gaode_thread.start() update_lng_lat_thread.start() update_config_thread.start() check_ping_delay_thread.start() if config.current_platform == config.CurrentPlatform.pi: change_pwm_thread.start() if os.path.exists(config.stc_port): get_com_data_thread.start() if config.b_pin_gps: soft_compass_thread.start() soft_gps_thread.start() if config.b_laser or config.b_millimeter_wave: get_distance_thread.start() if config.b_millimeter_wave: send_distacne_thread.start() if config.b_pin_stc: stc_data_thread.start() print('home_debug', config.home_debug) thread_restart_time = 1 while True: # 判断线程是否死亡并重启线程 if config.current_platform == config.CurrentPlatform.pi: if not change_pwm_thread.is_alive(): logger.error('restart get_com_data_thread') change_pwm_thread = threading.Thread(target=data_manager_obj.pi_main_obj.loop_change_pwm) change_pwm_thread.setDaemon(True) change_pwm_thread.start() if os.path.exists(config.stc_port) and not get_com_data_thread.is_alive(): logger.error('restart get_com_data_thread') try: if data_manager_obj.com_data_obj.uart.is_open(): data_manager_obj.com_data_obj.uart.close() data_manager_obj.com_data_obj = data_manager_obj.pi_main_obj.get_com_obj(port=config.stc_port, baud=config.stc_baud, logger_=None) except Exception as e1: logger.error({'串口关闭失败': 111, 'error': e1}) get_com_data_thread = threading.Thread(target=data_manager_obj.get_com_data) get_com_data_thread.setDaemon(True) get_com_data_thread.start() time.sleep(thread_restart_time) if config.b_pin_gps and not soft_gps_thread.is_alive(): logger.error('restart soft_gps_thread') try: data_manager_obj.pi_main_obj.gps_obj = data_manager_obj.pi_main_obj.get_gps_obj() except Exception as e: logger.error({'restart soft_gps_thread': 111, 'error': e}) soft_gps_thread = threading.Thread(target=data_manager_obj.pi_main_obj.get_gps_data) soft_gps_thread.setDaemon(True) soft_gps_thread.start() time.sleep(thread_restart_time) if config.b_pin_compass and not soft_compass_thread.is_alive(): logger.error('restart soft_compass_thread') try: data_manager_obj.pi_main_obj.compass_obj = data_manager_obj.pi_main_obj.get_gps_obj() except Exception as e: logger.error({'restart soft_compass_thread': 111, 'error': e}) soft_compass_thread = threading.Thread(target=data_manager_obj.pi_main_obj.get_compass_data) soft_compass_thread.setDaemon(True) soft_compass_thread.start() time.sleep(thread_restart_time) if config.b_pin_stc and not stc_data_thread.is_alive(): logger.error('restart stc_data_thread') try: data_manager_obj.pi_main_obj.stc_obj = data_manager_obj.pi_main_obj.get_stc_obj() except Exception as e: logger.error({'restart stc_data_thread': 111, 'error': e}) stc_data_thread = threading.Thread(target=data_manager_obj.pi_main_obj.get_stc_data) stc_data_thread.start() time.sleep(thread_restart_time) if not get_distance_thread.is_alive(): logger.error('restart get_distance_thread') try: data_manager_obj.pi_main_obj.laser_obj = data_manager_obj.pi_main_obj.get_laser_obj() except Exception as e: logger.error({'restart get_distance_thread': 111, 'error': e}) if config.b_laser: get_distance_thread = threading.Thread(target=data_manager_obj.pi_main_obj.get_distance_dict) elif config.b_millimeter_wave: get_distance_thread = threading.Thread( target=data_manager_obj.pi_main_obj.get_distance_dict_millimeter) get_distance_thread.setDaemon(True) get_distance_thread.start() time.sleep(thread_restart_time) if not send_distacne_thread.is_alive(): logger.error('restart send_distacne_thread') send_distacne_thread = threading.Thread( target=data_manager_obj.send_distacne) send_distacne_thread.setDaemon(True) send_distacne_thread.start() if not send_mqtt_data_thread.is_alive(): logger.error('restart send_mqtt_data_thread') send_mqtt_data_thread = threading.Thread( target=data_manager_obj.send_mqtt_data) send_mqtt_data_thread.setDaemon(True) send_mqtt_data_thread.start() time.sleep(thread_restart_time) if not check_status_thread.is_alive(): logger.error('restart check_status_thread') check_status_thread = threading.Thread( target=data_manager_obj.check_status) check_status_thread.setDaemon(True) check_status_thread.start() time.sleep(thread_restart_time) if not move_control_thread.is_alive(): logger.error('restart move_control_thread') move_control_thread = threading.Thread( target=data_manager_obj.move_control) move_control_thread.setDaemon(True) move_control_thread.start() time.sleep(thread_restart_time) if not update_ship_gaode_thread.is_alive(): logger.error('restart update_ship_gaode_thread') update_ship_gaode_thread = threading.Thread( target=data_manager_obj.update_ship_gaode_lng_lat) update_ship_gaode_thread.setDaemon(True) update_ship_gaode_thread.start() if not update_lng_lat_thread.is_alive(): logger.error('restart update_lng_lat_thread') update_lng_lat_thread = threading.Thread( target=data_manager_obj.update_lng_lat) update_lng_lat_thread.setDaemon(True) update_lng_lat_thread.start() if not update_config_thread.is_alive(): logger.error('restart update_config_thread') update_config_thread = threading.Thread( target=data_manager_obj.update_config) update_config_thread.setDaemon(True) update_config_thread.start() if not check_ping_delay_thread.is_alive(): logger.error('restart check_ping_delay_thread') check_ping_delay_thread = threading.Thread( target=data_manager_obj.check_ping_delay) check_ping_delay_thread.setDaemon(True) check_ping_delay_thread.start() else: time.sleep(thread_restart_time)
def main(): config.update_setting() if config.b_play_audio: audios_manager.play_audio(audio_index=audios_manager.AudioType.start) # 数据处理对象 data_manager_obj = data_manager.DataManager() # 查询改船是否注册 若未注册直接退出 """ try: binding_data = data_manager_obj.send( method='http', data="", url=config.http_binding, http_type='GET') if int(binding_data['flag']) != 1: if config.b_play_audio: audios_manager.play_audio('register.mp3') logger.error({'binding status': binding_data['flag']}) logger.info({'binding status': binding_data['flag']}) except Exception as e1: logger.error({'binding_data error': e1}) """ # 通用调用函数 common_func_list = [data_manager_obj.move_control, data_manager_obj.check_status, data_manager_obj.send_mqtt_status_data, data_manager_obj.send_mqtt_detect_data, data_manager_obj.update_ship_gaode_lng_lat, data_manager_obj.update_lng_lat, data_manager_obj.update_config, data_manager_obj.check_ping_delay, data_manager_obj.control_peripherals, data_manager_obj.change_status, data_manager_obj.check_switch, data_manager_obj.connect_mqtt_server, data_manager_obj.start_once_func, data_manager_obj.control_draw_thread, ] common_thread_list = [] # 树莓派对象数据处理 pi_func_list = [] pi_func_flag = [] pi_thread_list = [] if config.current_platform == config.CurrentPlatform.pi: pi_func_list = [data_manager_obj.pi_main_obj.loop_change_pwm, data_manager_obj.pi_main_obj.get_gps_data, data_manager_obj.pi_main_obj.get_compass_data, data_manager_obj.pi_main_obj.get_com_data, data_manager_obj.pi_main_obj.get_distance_dict, data_manager_obj.pi_main_obj.get_distance_dict_millimeter, data_manager_obj.send_distacne, data_manager_obj.pi_main_obj.get_stc_data, data_manager_obj.pi_main_obj.get_remote_control_data, data_manager_obj.pi_main_obj.loop_change_draw_steer, ] pi_func_flag.append(True) pi_func_flag.append(True) pi_func_flag.append(True) pi_func_flag.append(True if os.path.exists(config.stc_port) else False) pi_func_flag.append(True if config.b_laser else False) pi_func_flag.append(True if config.b_millimeter_wave else False) pi_func_flag.append(True if config.b_laser or config.b_millimeter_wave else False) pi_func_flag.append(True if config.b_pin_stc else False) pi_func_flag.append(True if config.b_lora_remote_control else False) pi_func_flag.append(True if config.b_control_deep else False) for common_func in common_func_list: common_thread_list.append(threading.Thread(target=common_func)) if config.current_platform == config.CurrentPlatform.pi: for index, pi_func in enumerate(pi_func_list): if pi_func_flag[index]: pi_thread_list.append(threading.Thread(target=pi_func)) else: pi_thread_list.append(None) for common_thread in common_thread_list: common_thread.start() if config.current_platform == config.CurrentPlatform.pi: for pi_thread in pi_thread_list: if pi_thread: pi_thread.start() print('home_debug', config.home_debug) thread_restart_time = 1 # 判断线程是否死亡并重启线程 while True: if config.current_platform == config.CurrentPlatform.pi: for index_common_thread, common_thread in enumerate(common_thread_list): if common_thread is not None and not common_thread.is_alive(): logger.error({'restart common_thread': index_common_thread}) print(index_common_thread, common_func_list[index_common_thread]) common_thread_list[index_common_thread] = threading.Thread( target=common_func_list[index_common_thread]) common_thread_list[index_common_thread].start() for index_pi_thread, pi_thread in enumerate(pi_thread_list): if pi_thread and not pi_thread.is_alive(): logger.error({'restart pi_thread': index_pi_thread}) print(index_pi_thread, pi_func_list[index_pi_thread]) pi_thread_list[index_pi_thread] = threading.Thread(target=pi_func_list[index_pi_thread]) pi_thread_list[index_pi_thread].start() time.sleep(thread_restart_time)
clientID = clientID() print("Your client id:" + str(clientID)) resume_name = cfg.get_setting(path, 'Resume', 'name') resume_id = cfg.get_setting(path, 'Resume', 'id') if resume_id == "": choose_resume_id() else: choice = input("Do you want to use ID: " + resume_id + " Name: " + resume_name + " (YES/no) ? ") if choice == "no": choose_resume_id() cityName = cfg.get_setting(path, 'Resume', 'city') if cityName == "": cityName = input("City name (leave blank for all cities): ") cfg.update_setting(path, 'Resume', 'city', cityName) keyWords = cfg.get_setting(path, 'Resume', 'key') if keyWords == "": keyWords = input("Key words (leave blank to search all): ") cfg.update_setting(path, 'Resume', 'key', keyWords) vac_ids = search(cityName, keyWords) print("New vacancies count : " + str(len(vac_ids))) save_ids(ids_path, vac_ids) ready = input("Do you want to send ?(YES/no): ") if ready == "no": print("Lol") quit() for vac in vac_ids: apply(resume_id, vac, clientID)