def add_error(self, request_url, request_method, request_data, error, traceback, created): """ Добавление ошибки в БД :param request_url: URL :param request_method: Метод :param request_data: Данные :param error: Ошибка :param traceback: Подробности :param created: Время создания :return: Результат выполнения функции (Строка) """ try: error_instance = ErrorLog(request_url=request_url, request_method=request_method, request_data=request_data, error=error, traceback=traceback, created=created) self.session.add(error_instance) self.session.flush() self.session.commit() return 'OK.' except Exception as e: return f'ERROR: {e}'
def do_sign(): if 'flag' not in session: current_app.logger.error("'flag' not in session,yiban id %s" % g.user.id) return error('请在易班客户端扫码进入此页面') t = datetime.now() minutes = t.hour * 60 + t.minute if minutes < 450: return error('签到时间未到,请在早上7:30-8:30之间签到') if minutes > 510: return error('签到时间已过,请在早上7:30-8:30之间签到') result, location = check_valid(int(session['flag']), float(request.form.get('latitude', 0)), float(request.form.get('longitude', 0))) if not result: e = ErrorLog(float(request.form.get('latitude', 0)), float(request.form.get('longitude', 0)), g.user.id, int(session['flag'])) e.save() return error( '位置信息有误,请尝试打开手机WIFI提高定位精度 <a href="javascript:;" class="open-popup" data-target="#info">详情</a>' ) one_day = timedelta(days=1) today = date.today() yesterday = today - one_day type = get_type(session['flag']) if type == 0: if g.user.last_read < yesterday: g.user.continue_read = 1 elif g.user.last_read == yesterday: g.user.continue_read += 1 elif g.user.last_read == today: return error('今天已经签过到了') g.user.last_read = today g.user.total_read += 1 else: if g.user.last_run < yesterday: g.user.continue_run = 1 elif g.user.last_run == yesterday: g.user.continue_run += 1 elif g.user.last_run == today: return error('今天已经签过到了') g.user.last_run = today g.user.total_run += 1 sign = SignLog(int(session['flag']), request.form.get('location_des', ''), request.form.get('latitude', ''), request.form.get('longitude', ''), g.yiban_id, session.get('flag', 1)) db.session.add(sign) db.session.add(g.user) db.session.commit() ranking = SignLog.query.filter(SignLog.type == type, SignLog.time == today).count() return success({'ranking': ranking, 'location': location})
def _error_log(self, exception, file_name, line_number): error_log = { 'url': self.url, 'created_at': datetime.utcnow(), 'exception': exception, 'file_name': file_name, 'line_number': line_number } ErrorLog(**error_log).save()
def error_handler(): if(request.method=='POST'): submitter=request.form.get("submitter") html=request.form.get("html") additionaldata=request.form.get("add") newrecord=ErrorLog() newrecord.submitter=submitter newrecord.html=html newrecord.error=request.form.get("error") newrecord.additionalinfo=additionaldata newrecord.created_at=datetime.now() newrecord.put() return "Thank you for submitting a bug report. I will take some time before I read this error, and take more time before I fix it. So... just be patient." return render_template('error_form.html')
def read_and_store_sms(sms_file): f = open(sms_file, mode='r') line_id = None line_number = 0 for current_line in f: try: line_number += 1 if len(current_line) <= 1: continue # this line is a new sms if current_line.strip().startswith("sms"): # split may contain more than we want because of the comma in content spited = current_line.split(",") direction, name, phone, date_time, content = spited[1], spited[ 2], spited[3], spited[5], spited[7], date_time = deal_with_sms_date_time(date_time) # the position of name and phone may exchange due to the direction if direction == "submit": pass else: name, phone = phone, name sp_list = [direction, name, phone, date_time, content] tp_list = [] for a in sp_list: tp_list.append(a.strip()) new_sms = Sms(sms_direction=tp_list[0], sms_name=tp_list[1], sms_phone=tp_list[2], sms_date=tp_list[3][:10], sms_time=tp_list[3], sms_content=tp_list[4]) new_sms.save() line_id = new_sms.get_id() continue # this line is a continue content if line_id is None: continue sms = Sms.get(id=line_id) sms.sms_content += current_line sms.save() except Exception, e: ErrorLog(error_line=line_number, error_function="read_and_store_sms", error_msg=e).save()
def read_and_store_tencent(txt_file): f = open(txt_file, mode='r') # start from where last end f.seek(3966 * 1024) line_id = None line_number = 0 for current_line in f: try: line_number += 1 # this line is empty if len(current_line) == 1: continue # this line is time line pattern = re.compile(r"^\d{4}(-\d\d){2} \d\d(:\d\d){2}") if pattern.match(current_line): line_date, line_time, line_user = current_line.split(" ")[0:3] if QQMsg.filter(msg_date=line_date, msg_time=line_date + " " + line_time, msg_user=line_user).exists(): # "already there" continue new_msg = QQMsg(msg_date=line_date, msg_time=line_date + " " + line_time, msg_user=line_user) new_msg.save() line_id = new_msg.get_id() continue # this line is a content if line_id is None: continue msg = QQMsg.get(id=line_id) msg.msg_content += current_line msg.save() except Exception, e: ErrorLog(error_line=line_number, error_function="read_and_store_tencent", error_msg=e).save()