def __parse_mail_name(self, text): if isbasestring(text): if ("<" in text) and (">" in text) : s=text return s[0:s.find('<')-1] else: return "" else: return ""
def __parse_mail(self, text): if isbasestring(text): if ("<" in text) and (">" in text) : s=text return s[s.find('<')+1:s.find('>')] else: return text else: return ""
def get_default_values(self): """ We want to use our Values child instead which creates a get and __contains__ method """ if not self.process_default_values: return DictValues(self.values) defaults = self.defaults.copy() for option in self._get_all_options(): default = defaults.get(option.dest) if isbasestring(default): opt_str = option.get_opt_string() defaults[option.dest] = option.check_value(opt_str, default) return DictValues(defaults)
def request(url, params): """http request""" for k, v in params.iteritems(): if isbasestring(v): params[k] = v.encode("utf8") else: params[k] = v try: url = url + "?" + urllib.urlencode(params) logging.debug(url) ret_val = urllib.urlopen(url).read() return True, ret_val except: logging.error(traceback.format_exc()) return False, None
def __add_model(self, model): """モデルをCSV文字列に変換. """ model_cls = model.__class__ cls_name = model_cls.__name__ tar_model_table = self.__model_table.get(cls_name, None) if tar_model_table is None: # 新規登録. self.__model_table[cls_name] = '' # モデルのクラスを登録. if self.__cls_table.get(cls_name) is None: self.__cls_table[cls_name] = model_cls self.__cls_name.append(cls_name) csv_data_list = [] for field in model_cls._meta.fields: # フィールドに設定されている値. value = getattr(model, field.attname) if isinstance(field, ObjectField): value = field.get_db_prep_save(value, None) if value is None: value = 'NULL' elif isinstance(value, datetime.datetime): value = "%04d-%02d-%02d %02d:%02d:%02d" % ( value.year, value.month, value.day, value.hour, value.minute, value.second) elif isinstance(value, bool): value = int(value) elif isbasestring(value): # 無理やりだけどバイナリデータをエスケープ. value = MySQLdb.escape_string(StrUtil.to_s(value)) csv_data_list.append('"%s"' % value) # 書き込む. csv_text = ModelCSVManager.STR_KUGIRI.join(csv_data_list) + '\r\n' self.__model_table[cls_name] += csv_text if ModelCSVManager.SIZE_MAX <= len(self.__model_table[cls_name]): return True else: return False
def add_forces(server_id, forces_info): server = Server.load(server_id=server_id) try: if server.server_host.index(':') > 0: url = "http://%s/gameApi/modifyForcesTimes.do?" % server.server_host except: url = "http://%s:8088/gameApi/modifyForcesTimes.do?" % server.server_host logging.info(url) #url = "http://localhost:8088/gameApi/modifyForcesTimes.do?" params = {} for k, v in forces_info.iteritems(): if isbasestring(v): params[k] = v.encode("utf8") else: params[k] = v url = url + urllib.urlencode(params) data = None try: data = urllib.urlopen(url).read() except Exception, e: logging.info(e)
def predict(self, image_path): try: self.learning_model = pickle.load( open("./Models/naivebayes_model.p", "rb")) except: print "Please train the Naive Bayes model first" if isbasestring(image_path): image = self.dsr.read_img_bw(image_path) else: image = image_path image = image.reshape(-1, image.shape[0] * image.shape[1]) result = self.learning_model.predict(image) return result # from NaiveBayes import NaiveBayes # NB = NaiveBayes() # # NB.training('I:\\eclipse_workspace\\CharacterRecognition\\digits_dataset_clean', cv=5) # # print NB.predict('I:\\eclipse_workspace\\CharacterRecognition\\test1.jpg') # data_x, data_y = NB.get_data() # print data_x.shape, data_y.shape # NB.first_exp(data_x, data_y, NB.learning_model, algorithm_name='NaiveBayes' ,num_iter=50)
def __init__(self, params = None): if not params: return elif isbasestring(params): self.__parse_string(params) return
def system_mail_approve(system_mail_id, approve_user, approve=False): system_mail = get_system_mail(system_mail_id) if system_mail.status != 0: return else: system_mail.status = 3 system_mail.persist() system_mail.approve_user = approve_user system_mail.approve_time = datetime.now() result_map = {} if approve: server_ids = system_mail.server_ids.split(",") send_server_ids = [] for server_id in server_ids: mail_info = {} mail_info["title"] = system_mail.title mail_info["content"] = system_mail.content mail_info["toolIds"] = system_mail.tool_ids mail_info["lodoIds"] = system_mail.lodo_ids mail_info["target"] = system_mail.target mail_info["sourceId"] = system_mail.system_mail_id if system_mail.date: mail_info["date"] = int( time.mktime(system_mail.date.timetuple())) * 1000 else: mail_info["date"] = int(time.time()) mail_info["partner"] = system_mail.partner_id server = Server.load(server_id=server_id) url = "http://" + server.server_host + ":8088/gameApi/sendMail.do?" params = {} for k, v in mail_info.iteritems(): if isbasestring(v): params[k] = v.encode("utf8") else: params[k] = v url = url + urllib.urlencode(params) logging.info("server:%s,url:%s" % (server_id, url)) result_map[server_id] = 0 approve_info = {} try: ret_val = urllib.urlopen(url).read() approve_info[server_id] = ret_val result = json.loads(ret_val) if result.get("rt") == 1000: send_server_ids.append(server_id) result_map[server_id] = 1 else: logging.warn(u"邮件发送失败.server_id[%s], msg[%s]" % (server_id, result.get("msg"))) except: approve_info[server_id] = traceback.format_exc() logging.error(traceback.format_exc()) system_mail.status = 1 system_mail.send_server_ids = ",".join(send_server_ids) system_mail.approve_info = json.dumps(approve_info) else: system_mail.status = 2 system_mail.persist() return 1, result_map
def system_mail_approve(system_mail_id, approve_user, approve=False): system_mail = get_system_mail(system_mail_id) if system_mail.status != 0: return else: system_mail.status = 3 system_mail.persist() system_mail.approve_user = approve_user system_mail.approve_time = datetime.now() result_map = {} if approve: server_ids = system_mail.server_ids.split(",") send_server_ids = [] for server_id in server_ids: mail_info = {} mail_info["title"] = system_mail.title mail_info["content"] = system_mail.content mail_info["toolIds"] = system_mail.tool_ids mail_info["lodoIds"] = system_mail.lodo_ids mail_info["target"] = system_mail.target mail_info["sourceId"] = system_mail.system_mail_id if system_mail.date: mail_info["date"] = int(time.mktime(system_mail.date.timetuple())) * 1000 else: mail_info["date"] = int(time.time()) mail_info["partner"] = system_mail.partner_id server = Server.load(server_id=server_id) url = "http://" + server.server_host + ":8088/gameApi/sendMail.do?" params = {} for k, v in mail_info.iteritems(): if isbasestring(v): params[k] = v.encode("utf8") else: params[k] = v url = url + urllib.urlencode(params) logging.info("server:%s,url:%s" % (server_id, url)) result_map[server_id] = 0 approve_info = {} try: ret_val = urllib.urlopen(url).read() approve_info[server_id] = ret_val result = json.loads(ret_val) if result.get("rt") == 1000: send_server_ids.append(server_id) result_map[server_id] = 1 else: logging.warn(u"邮件发送失败.server_id[%s], msg[%s]" % (server_id, result.get("msg"))) except: approve_info[server_id] = traceback.format_exc() logging.error(traceback.format_exc()) system_mail.status = 1 system_mail.send_server_ids = ",".join(send_server_ids) system_mail.approve_info = json.dumps(approve_info) else: system_mail.status = 2 system_mail.persist() return 1, result_map