def __init__(self): if not self.conf: Config.__init__(self) # if self.script: # logging.Logger(basename(self.script), logging.INFO) # if "log" in self.conf and "format" in self.conf["log"]: # self._format = self.conf["log"]["format"] # else: # self._format = "%(asctime)-15s %(name) %(levelname)s %(message)s" here_logs = "./logs" # filename = re.sub(r"py$", "log", basename(self.script), 1) self._file = here_logs + "/broker-signal.log" self._bad_file = here_logs + "/broker-signal.err" # Inicializacao do manipulador do log # logging.basicConfig( # filename=self._file, # format=self._format, # level=logging.INFO # ) formatter = logging.Formatter(self._format) fileHandler = logging.FileHandler(self._bad_file) streamHandler = logging.StreamHandler() streamHandler.setFormatter(formatter) # self._bad_logger = logging.getLogger(self.script + "ERROR") self._bad_logger = logging.getLogger(self._file) self._bad_logger.setLevel(logging.ERROR) self._bad_logger.addHandler(fileHandler) self._bad_logger.addHandler(streamHandler)
def open_browser(self): file_path = os.path.dirname( os.path.abspath('.')) + '\\config2\\conf\\config.ini' # 加载自己的配置文件类 config = Config(file_path) browser = config.get_value(file_path, "Browser", "browserName") url = config.get_value(file_path, "Server", "url") if browser == "Firefox": self.driver = webdriver.Firefox(self.firefox_driver_path) logger.info('打开了Firefox浏览器') elif browser == "Chrome": self.driver = webdriver.Chrome(self.chrome_driver_path) logger.info('打开了Chrome浏览器') elif browser == "IE": self.driver = webdriver.Ie(self.ie_driver_path) logger.info('打开了IE浏览器') else: logger.info("找不到 %s 浏览器,你应该从这里面选取一个 'Firefox', 'Chrome', 'IE'" % self.driver) raise NameError( "找不到 %s 浏览器,你应该从这里面选取一个 'Firefox', 'Chrome', 'IE'" % self.driver) self.driver.get(url) logger.info('浏览器地址为:' + url) self.driver.maximize_window() logger.info('最大化浏览器') return self.driver
def init_config(): config = Config(file) configs = { 'url': config.get_value(file, 'base', 'url'), 'port': config.get_value(file, 'base', 'port'), 'project_name': config.get_value(file, 'base', 'project_name'), } return configs
def __init__(self, translator): self.log = Log('TranslatorAction') self.translator = translator self.data_sso = Config('sso').data self.data_trade = Config('trade').data self.data_sms = Config('sms').data self.data_base = DataBaseOperate() self.request = Request() self.tool = Tool()
def __init__(self, seller_agent): self.log = Log('sellerAgent') self.sellerAgent = seller_agent self.data_sso = Config('sso').data self.data_trade = Config('trade').data self.data_sms = Config('sms').data self.request = Request() self.tool = Tool() self.ps = 10
def __init__(self, promoter): self.log = Log('PromoterAction') self.promoter = promoter self.data_sso = Config('sso').data self.data_trade = Config('trade').data self.data_sms = Config('sms').data self.request = Request() self.tool = Tool() self.ps = 10
def get_db(): config = Config(file) my = MySQLHelper() my.host = config.get_value(file, 'mysql', 'host') my.user = config.get_value(file, 'mysql', 'user') my.password = config.get_value(file, 'mysql', 'password') my.database = config.get_value(file, 'mysql', 'database') my.port = int(config.get_value(file, 'mysql', 'port')) return my
def __init__(self): self.config = Config() self.config.from_ini('../Application/conf') # self.data = pd.read_csv('../Data/ml-1m/newtransaction.csv') self.data = pd.read_csv('../Data/bbg/newtransaction.csv') self.samples = [[int(i[0]), int(i[1])] for i in self.data.values[:,0:2]] self.labels = [int(i[0]) for i in self.data.values[:,0:2]] # self.targets = [int(i[2]) for i in self.data.values] self.targets = [1 for i in self.samples] self.Lock = Lock() m = Manager() self.result = m.list()
def __init__(self, buyer): """ 初始化方法的一个常用数据 :param buyer: 传的是一个用户对象 """ self.log = Log('buyer') self.buyer = buyer self.data_sso = Config('sso').data self.data_trade = Config('trade').data self.data_sms = Config('sms').data self.request = Request() self.tool = Tool() self.ps = 10
class Employee(object): hosts = Config('config').data['hosts'][Config('config').data['run']] def __init__(self, account, password, Etype=1): self.log = Log('Employee') self.tool = Tool() self.request = Request() emp = EmployeeSession(account, password) self.password = emp.password self.token, self.deviceId = emp.token, emp.deviceId if Etype == 1: self.employee_info = self.tool.miaoshu_query_user_info_by_mobile( account, 2) # self.log.logger.debug("员工信息:%s" % self.employee_info) elif Etype == 2: self.employee_info = self.tool.miaoshu_query_user_info_by_email( account, 2) else: return if self.employee_info != (): self.employee_info = self.employee_info[0] self.employee_id = self.employee_info["id"] self.employee_real_name = self.employee_info["real_name"] self.employee_nickname = self.employee_info["nickname"] self.employee_sex = self.employee_info["sex"] self.employee_mobile = self.employee_info["mobile"] self.employee_email = self.employee_info["email"] self.employee_account_status = self.employee_info["account_status"] self.employee_account_type = self.employee_info["account_type"] self.employee_head_img = self.employee_info["head_img"] self.employee_register_time = self.employee_info["create_time"] self.employee_edit_time = self.employee_info["edit_time"] self.employee_channel_shop_id = None def employee_logout(self): """ 员工退出登录 :return: """ data = {"token": self.token} response = Request().post(url=self.hosts['MS_PASSPORT'] + "/admin/service/logout", data=data) json_response = json.loads(response) if json_response["status"] == "OK": pass elif json_response["status"] == "ERROR": raise Exception("status返回ERROR") else: raise Exception("status未返回OK或ERROR")
def __init__(self, real_name, mobile, email, region, *roles): self.log = Log('User') self.log.logger.debug(type(roles)) self.tool = Tool() self.request = Request() self.mobile = mobile self.user_info = self.tool.query_user_info_by_mobile(self.mobile) self.role_list = self.tool.get_role_code(*roles) self.real_name = real_name self.email = email self.region = region data_uc = Config('uc').data employee_data = data_uc['http://dev.uc.worldfarm.com'][ '/admin/emp/add'] employee_data["mobile"] = self.mobile employee_data["realName"] = self.real_name employee_data["email"] = self.email employee_data["mobileRegion"] = self.region employee_data["roles"] = self.role_list admin = EmployeeSession('007', '123456') employee_data["_tk_"] = admin.token employee_data["_deviceId_"] = admin.deviceId add_employee = self.request.post( url="http://dev.uc.worldfarm.com/admin/emp/add", data=employee_data) self.log.logger.debug(add_employee)
def web_seller_agency_close_farm(self, farmId, type, language): # 卖家中介关闭农场 data = Config('trade').data['http://dev.trade.worldfarm.com'][ '/web/seller-agency/farm/close'] data['_language_'] = language data['_tk_'] = self.sellerAgent.token data['_deviceId_'] = self.sellerAgent.device_id data['farmId'] = farmId data['type'] = type # 30已售出50暂不销售 r = Request().post( url='http://dev.trade.worldfarm.com/web/seller-agency/farm/close', data=data) r_close = json.loads(r) query_close_farm = self.tool.query_close_farm_by_farm_id( self.sellerAgent.user_id) if r_close == { 'errorCode': '00030003', 'errorMsg': '农场已售出或者已关闭', 'status': 'ERROR' }: assert r_close['errorMsg'] == str('农场已售出或者已关闭') assert r_close['status'] == 'ERROR' else: assert r_close.get['farm_id'] == query_close_farm['id'] assert r_close['status'] == query_close_farm['status']
def __init__(self): self.config = Config() self.all_data = dataset_helper.get_dataset(True) self.my_tokenizer, self.my_data = self.get_tokenizer( [x[1] for x in self.all_data]) self.their_tokenizer, self.their_data = self.get_tokenizer( [x[0] for x in self.all_data]) self.input_vocab_size = len(self.their_tokenizer.word_index) + 1 self.output_vocab_size = len(self.my_tokenizer.word_index) + 1 self.their_tensor_len = self.max_len(self.their_data) self.my_tensor_len = self.max_len(self.my_data) # x_tensor_len = max_len(their_data) # y_tensor_len = max_len(my_data) self.optimizer = tf.keras.optimizers.Adam() self.encoderNetwork = self.EncoderNetwork(self.input_vocab_size, self.config) self.decoderNetwork = self.DecoderNetwork(self.output_vocab_size, self.their_tensor_len, self.config) self.checkpoint = tf.train.Checkpoint(optimizer=self.optimizer, encoder=self.encoderNetwork, decoder=self.decoderNetwork)
def openJson(self): try: config = Config.readConfig() lastOpenDir = config['lastOpenDir'] except: lastOpenDir = './' file, type = QFileDialog.getOpenFileName(self, 'Open JSon file', lastOpenDir) if not file: return else: dir = os.path.dirname(file) Config.writeConfig({'lastOpenDir': dir}) file = open(file, 'r', encoding='utf-8') content = file.read() if content: self.textEdit.setText(content)
def create_action(self, filename): """ :param filename: 文件名不能全为数字 :return: """ try: int(filename.split(".")[0]) except Exception: file_data = Config(filename.split(".")[0]).data for key, value in file_data.items(): url = key data = value if data is not None and isinstance(data, dict): with open("../actions/" + filename.split(".")[0].capitalize()+"Action.py", "w", encoding='utf-8') as f: f.writelines("# encoding: utf-8\n\nfrom utils.Config import Config\n" "from utils.Util import Request\nfrom backend.Tool import Tool\n" "from utils.Log import Log\nimport json\n\n") f.write("class "+filename.split(".")[0]+"Action(object):\n\n") f.write(" def __init__(self, %s):\n" % filename.split(".")[0]) f.write(" self.log = Log('%s')\n" % filename.split(".")[0]) f.write(" self.request = Request()\n") f.write(" self.%s = %s\n" % (filename.split(".")[0], filename.split(".")[0])) for key, value in data.items(): fun_name = key.replace("/", "_").replace("-", "_") fun_data = "\n def %s(self" % fun_name if value is not None: paramlist = list(value.keys()) for param in paramlist: fun_data += ", " + param fun_data += "):\n" fun_data += " data = self.%s.get('%s').get('%s')\n" % (filename.split(".")[0], url, key) fun_data += " data['_tk_'] = None\n" fun_data += " data['_deviceId_'] = None\n" if value is not None: paramlist = list(value.keys()) for param in paramlist: fun_data += " data['%s'] = %s\n" % (param, param) fun_data += " response = self.request.post(url='%s', data=data)\n" % (url+key) fun_data += " json_response = json.loads(response)\n" fun_data += " if json_response[\"status\"] == \"OK\":\n" fun_data += " pass\n" fun_data += " elif json_response[\"status\"] == \"ERROR\":\n" fun_data += " pass\n" fun_data += " else:\n raise Exception(\"status未返回OK或ERROR\")\n" f.write(fun_data)
def operator_approve_seller_agent(self, mobile, status=False): operator = EmployeeSession('100031', '123456') data = Config('trade').data['http://dev.trade.worldfarm.com'][ '/admin/cs/seller-agency/list'] data['status'] = 1 data['_tk_'] = operator.token data['_deviceId_'] = operator.deviceId wait = Request().post( url='http://dev.trade.worldfarm.com/admin/cs/seller-agency/list', data=data) wait_list = json.loads(wait)['content']['datas'] for i in wait_list: if i['mobile'] == mobile: Request().post( url= 'http://dev.trade.worldfarm.com/admin/cs/seller-agency/detail-resource-list', data={ '_tk_': operator.token, '_deviceId_': operator.deviceId, 'id': i['id'] }) audit_data = Config( 'trade').data['http://dev.trade.worldfarm.com'][ '/admin/cs/seller-agency/audit'] audit_data['_tk_'] = operator.token audit_data['_deviceId_'] = operator.deviceId audit_data['id'] = i['id'] if status: # type=1表示通过 audit_data['type'] = 1 Request().post( url= 'http://dev.trade.worldfarm.com/admin/cs/seller-agency/audit', data=audit_data) self.L.logger.debug('手机号 %s 的用户上传的中介资料审核通过' % str(mobile)) else: # type=2表示审核不通过 audit_data['type'] = 2 Request().post( url= 'http://dev.trade.worldfarm.com/admin/cs/seller-agency/audit', data=audit_data) self.L.logger.debug('手机号 %s 的用户上传的中介资料审核未通过' % str(mobile)) else: pass
def openDest(self): try: config = Config.readConfig() lastOpenDir = config['lastOpenDir'] except: lastOpenDir = './' file, type = QFileDialog.getOpenFileName(self, 'Open a JSon file', lastOpenDir) if file: dir = os.path.dirname(file) Config.writeConfig({'lastOpenDir': dir}) try: f = open(file, 'r', encoding='utf-8') text = f.read() data = json.load(f) self.textEdit_2.setPlainText(text) f.close() except: QMessageBox.warning(self, 'Error', 'Not JSon')
def service_farm_im_list(self, seller_agency_id): # 联系卖家中介-农场列表(通过) data = Config('trade').data['http://dev.trade.worldfarm.com'][ '/admin/farm/im-list'] data['_tk_'] = self.service.token data['_deviceId_'] = self.service.device_id data['sellerAgencyId'] = seller_agency_id farm_im_list = Request().post( url='http://dev.trade.worldfarm.com/admin/farm/im-list', data=data) return farm_im_list
def service_seller_agency_detail(self, seller_agent_id): # 卖家中介信息(通过 ) data = Config('trade').data['http://dev.trade.worldfarm.com'][ '/admin/seller-agency/detail'] data['_tk_'] = self.service.token data['_deviceId_'] = self.service.device_id data['sellerAgencyId'] = seller_agent_id seller_agency_detail = Request().post( url='http://dev.trade.worldfarm.com/admin/seller-agency/detail', data=data) return seller_agency_detail
def service_im_account(self): # 登录IM,获取账号IM信息-failed data = Config('ms').data['http://dev.ms.worldfarm.com'][ '/admin/im-auth/get/im-account/service'] data['_tk_'] = self.service.token data['_deviceId_'] = self.service.device_id im_auth_account = Request().post( url= 'http://dev.ms.worldfarm.com/admin/im-auth/get/im-account/service', data=data) return im_auth_account
def service_get_acc_id(self, user_id): # 客服通过聊天获取对方IM账号-failed data = Config('ms').data['http://dev.ms.worldfarm.com'][ '/admin/im-auth/service-get/accid'] data['_tk_'] = self.service.token data['_deviceId_'] = self.service.device_id data['userId'] = user_id get_acc_id = Request().post( url='http://dev.ms.worldfarm.com/admin/im-auth/service-get/accid', data=data) return get_acc_id
def service_see_buyer_detail(self, buyer_id): # 买家资料信息(通过) data = Config('trade').data['http://dev.trade.worldfarm.com'][ '/admin/im-buyer/buyer-detail'] data['_tk_'] = self.service.token data['_deviceId_'] = self.service.device_id data['buyerId'] = buyer_id see_buyer_detail = Request().post( url='http://dev.trade.worldfarm.com/admin/im-buyer/buyer-detail', data=data) return see_buyer_detail
def get_short_massage_code(mobile): data_sso = Config('Sso').data data = data_sso['http://192.168.62.253:31007'][ '/mobile/sso/verify-code-get'] data["mobile"] = mobile code = Request().post( url="http://192.168.62.253:31007/mobile/sso/verify-code-get", data=data) Tool.L.logger.debug("手机号 %s 发送验证码成功" % str(mobile)) return Redis().get('VerifyCodeMobile: SmsVerifyCode:9_REGISTER_%s' % str(mobile))
def service_buyer_detail_resource_list(self, resource_id): # 买家资料详情资源列表() data = Config('trade').data['http://dev.trade.worldfarm.com'][ '/admin/cs/buyer-resource/detail-resource-list'] data['_tk_'] = self.service.token data['_deviceId_'] = self.service.device_id data['id'] = resource_id detail_resource_list = Request().post( url='http://dev.trade.worldfarm.com' '/admin/cs/buyer-resource/detail-resource-list', data=data) return detail_resource_list
def service_get_order_list(self, buyer_id): # 进入对话窗口调用-买家农场列表(返回为空) data_trade = Config('trade').data order_list_param = data_trade['http://dev.trade.worldfarm.com'][ '/admin/im-buyer/order-list'] order_list_param['_tk_'] = self.service.token order_list_param['_deviceId_'] = self.service.device_id order_list_param['buyerId'] = buyer_id order_list = Request().post( url='http://dev.trade.worldfarm.com/admin/im-buyer/order-list', data=order_list_param) return order_list
def service_remark_user_list(self, user_id): # 用户备注列表(通过) data = Config('trade').data['http://dev.trade.worldfarm.com'][ '/admin/customer-service-remark/user-list'] data['_tk_'] = self.service.token data['_deviceId_'] = self.service.device_id data['userId'] = user_id remark_farm_list = Request().post( url= 'http://dev.trade.worldfarm.com/admin/customer-service-remark/user-list', data=data) return remark_farm_list
def service_send_auth_url(self, order_id): # 邀请上传资质(通过) data = Config('trade').data['http://dev.trade.worldfarm.com'][ '/admin/im-buyer/before-send-auth-url'] data['_tk_'] = self.service.token data['_deviceId_'] = self.service.device_id data['orderId'] = order_id send_auth_url = Request().post( url= 'http://dev.trade.worldfarm.com/admin/im-buyer/before-send-auth-url', data=data) return send_auth_url
def service_see_sub_detail(self, buyer_id): # 查看订阅规则(通过) data = Config('trade').data['http://dev.trade.worldfarm.com'][ '/admin/im-buyer/sub-detail'] if data is None: data = {} data['_tk_'] = self.service.token data['_deviceId_'] = self.service.device_id data['buyerId'] = buyer_id see_sub_detail = Request().post( url='http://dev.trade.worldfarm.com/admin/im-buyer/sub-detail', data=data) return see_sub_detail
def service_remark_update_user(self, user_remark_id, remark): # 修改用户备注 data = Config('trade').data['http://dev.trade.worldfarm.com'][ '/admin/customer-service-remark/update-user'] data['_tk_'] = self.service.token data['_deviceId_'] = self.service.device_id data['Id'] = user_remark_id data['remark'] = remark remark_update_user = Request().post( url='http://dev.trade.worldfarm.com' '/admin/customer-service-remark/update-user', data=data) return remark_update_user
def seller_agent_search_farm(self, keyWords, language): seller = UserSession('18602832572', '123456a') data = Config('trade').data['http://dev.trade.worldfarm.com'][ '/mobile/farm/search'] data['_language_'] = language data['_tk_'] = seller.token data['_deviceId_'] = seller.deviceId data['keyWords'] = keyWords r = Request().post( url='http://dev.trade.worldfarm.com/mobile/farm/search', data=data) r_content = json.loads(r) print(r_content) return r_content
class App: def __init__(self): self.config = Config() self.config.from_ini('../Application/conf') # self.data = pd.read_csv('../Data/ml-1m/newtransaction.csv') self.data = pd.read_csv('../Data/bbg/newtransaction.csv') self.samples = [[int(i[0]), int(i[1])] for i in self.data.values[:,0:2]] self.labels = [int(i[0]) for i in self.data.values[:,0:2]] # self.targets = [int(i[2]) for i in self.data.values] self.targets = [1 for i in self.samples] self.Lock = Lock() m = Manager() self.result = m.list() def mulProcess(self,result,processParameters): algName = processParameters[0] parameters = processParameters[1] alg = AlgFactory.create(algName) rec_cv = StratifiedKFold(self.labels, 2) clf = grid_search.GridSearchCV(alg, parameters, cv=rec_cv) clf.fit(self.samples, self.targets) print(clf.best_estimator_) print(clf.grid_scores_) self.Lock.acquire() result.append(algName) result.append([clf.best_estimator_,clf.best_score_]) result.append(clf.grid_scores_) self.Lock.release() def fit(self): ''' for algName in self.config.algList: for para in self.config.paras[algName].iter(): s1 = datetime.datetime.now() threadParameters = [algName, para] self.mulThread(threadParameters) print algName + 'time consuming:' + str(datetime.datetime.now()-s1) raw_input() ''' print 'Fitting begin' process_que = [] s = datetime.datetime.now() for algName in self.config.algList: for para in self.config.paras[algName].iter(): Parameters = [algName, para] process = Process(target=self.mulProcess, args=(self.result,Parameters)) process_que.append(process) for t in process_que: t.start() for t in process_que: t.join() print 'time consuming:' + str(datetime.datetime.now()-s) t = pd.DataFrame(list(self.result)) t.to_csv('all_result') def best_alg(self): print 'Selecting best Alg' self.fit() scores = np.array(self.result[1::3])[:,1] print scores index = np.argwhere(scores == scores.max())[0][0] best_method = self.result[3*index] print 'best is: ' + best_method return best_method def recommend(self, uids): print 'Recommending' bestMethod = self.best_alg() alg = AlgFactory.create(bestMethod) alg.fit(self.samples, self.targets) recommendList = [] for u in uids: recommendList.append(alg.recommend(u)) return recommendList def recommendAll(self): print 'Recommending' # bestMethod = self.best_alg() # alg = AlgFactory.create(bestMethod) alg = AlgFactory.create('ItemCF') uids = list(set(np.array(self.samples)[:,0])) alg.fit(self.samples, self.targets) recommendList = [] for u in uids: rec = alg.recommend(u) rec.insert(0, u) recommendList.append(rec) t = pd.DataFrame(recommendList) t.to_csv('rec_list')
import os import random import time from matching_models.IRDALB import IRDALB from utils.Config import Config from utils.IO import mkdir_p, copy_source_to_dir if __name__ == "__main__": parser = argparse.ArgumentParser( description='Solve basic paper matching formulation as LP.') parser.add_argument('config', type=str, help='config file.') args = parser.parse_args() config = Config(args.config) loads = np.load(config.load_f) if config.load_lb_f: loads_lb = np.load(config.load_lb_f) else: loads_lb = None covs = np.load(config.cov_f) scores = np.load(config.score_f) ms = config.makespan now = datetime.datetime.now() ts = "{:04d}-{:02d}-{:02d}-{:02d}-{:02d}-{:02d}".format( now.year, now.month, now.day, now.hour, now.minute, now.second) rand = random.Random(config.random_seed)