def import_schedule(self): rlist = [] if('rnumbers_file' in request.files): f = request.files['rnumbers_file'] rlist = [x.decode('utf-8') for x in f.stream.readlines()] elif('rnumbers' in request.form): rlist = request.form['rnumbers'].splitlines() if(len(rlist)>0): #data = request.form['rnumbers'].splitlines() rnumbers = bu.remove_duplicate(rlist) for rnumber in rnumbers: rnumber = rnumber.strip() if(len(rnumber)==10): #person params = { 'id':'01', 'expression':'c.registerno', 'inputVal':rnumber, 'isCitizen': 'true' } elif(len(rnumber)==7): #company params = { 'id':'03', 'expression':'c.registerno', 'inputVal':rnumber } else: continue filename = Info.generateFilename() info = Info( user_uuid='ab6ea344-ccd9-4e87-8e85-2d457a52d77e', rnumber=rnumber, params = json.dumps(params, ensure_ascii=False), filename = filename, mode= Info.MODE_SCHEDULE, status=Info.STATUS_PENDING ) session.add(info) session.flush() return redirect("/home/index") return render_template("info/import_schedule.html")
def run(self): print("compute 2 started") while (True): i = Info.get_pendingC1(Info.MODE_SCHEDULE) if (i): try: compute1(i.id, i.rnumber) i.c1status = Info.C1_STATUS_FINISHED except Exception as e: i.c1status = Info.C1_STATUS_ERROR traceback.print_exc() session.flush() else: time.sleep(5)
def create_df_from_apiserver(rnumber): q = session.query(Info)\ .filter_by(rnumber=rnumber)\ .filter(Info.detail.isnot(None))\ .filter(Info.status==Info.STATUS_FINISHED)\ .order_by(Info.created_at.desc()).all() rows = [u.to_tuple() for u in q] if (len(rows) == 0): return [] df_tmp = pd.DataFrame(rows) df_tmp.columns = Info.columns() return df_tmp
def creates(self): try: requestParams = { 'fields': { 'rnumbers': { "type": "list", "required": True }, 'mode': { "type": "integer", "allowed": [0, 1], "required": True } }, 'message': { 'rnumbers': { "type": "өгөгдлийн төрөл буруу байна", "required": "Регистрийн дугаар тодорхойгүй байна" }, 'mode': { "type": "өгөгдлийн төрөл буруу байна", "allowed": "Буруу утгатай байна", "required": "Утга тодорхойгүй байна" } } } v = BuValidator(requestParams) v.validate(request.json) for rnumber in request.json['rnumbers']: if (len(rnumber) == 10): #person params = { 'id': '01', 'expression': 'c.registerno', 'inputVal': rnumber, 'isCitizen': 'true' } elif (len(rnumber) == 7): #company params = { 'id': '03', 'expression': 'c.registerno', 'inputVal': rnumber } else: continue filename = Info.generateFilename() info = Info(user_uuid=self.auth.uuid, rnumber=rnumber, params=json.dumps(params, ensure_ascii=False), filename=filename, mode=request.json['mode'], status=Info.STATUS_PENDING) session.add(info) session.flush() return json.dumps({ 'result': 'success' }, ensure_ascii=False).encode('utf8') except Exception as e: msg = e.args if len(e.args) > 0 else str(e) traceback.print_exc() return json.dumps({ 'result': 'error', 'msg': msg }, ensure_ascii=False).encode('utf8')
if (len(rnumber) == 10): #person params = { 'id': '01', 'expression': 'c.registerno', 'inputVal': rnumber, 'isCitizen': 'true' } elif (len(rnumber) == 7): #company params = { 'id': '03', 'expression': 'c.registerno', 'inputVal': rnumber } else: continue filename = Info.generateFilename() info = Info(user_uuid='ab6ea344-ccd9-4e87-8e85-2d457a52d77e', rnumber=rnumber, params=json.dumps(params, ensure_ascii=False), filename=filename, mode=mode, status=Info.STATUS_PENDING) session.add(info) i += 1 if (i % 2 == 0): session.flush() session.flush()