コード例 #1
0
    def get_pendingdownload(self):
        """Хүлээгдэж байгаа мэдээлэл татах хүсэлтийг авах
        """
        try:
            q = session.query(Info).filter(Info.status == Info.STATUS_PENDING)
            if ('mode' in request.json):
                q.filter(Info.mode == request.json['mode'])

            q.order_by(Info.created_at.asc())
            count = q.count()
            info = None
            if (count > 0):
                row = q.first()
                info = row.to_dict()
                if ('withprocess' in request.json
                        and request.json['withprocess'] == 1):
                    row.status = Info.STATUS_PROCESSING
                session.flush()
            print(info)
            return json.dumps(
                {
                    'result': 'success',
                    'count': count,
                    'info': info
                },
                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')
コード例 #2
0
    def setresponse(self):
        try:
            requestParams ={
                'fields': {
                    "id": {
                        "type":"integer",
                        "required":True},
                    'action': {
                        "type":"string",
                        "required":True},
                    'response': {
                        "type":"string",
                        "required":True}
                },
                'message': {
                    'id': {
                        "type":"өгөгдлийн төрөл буруу байна",
                        "required":"Утга тодорхойгүй байна"},
                    'action': {
                        "type":"өгөгдлийн төрөл буруу байна",
                        "required":"Утга тодорхойгүй байна"},
                    'response': {
                        "type":"өгөгдлийн төрөл буруу байна",
                        "required":"Утга тодорхойгүй байна"}
                }
            }
            
            v = BuValidator(requestParams)            
            v.validate(request.json)
            ucount = session.query(Request)\
                        .filter(Request.id==request.json['id'])\
                        .filter(Request.status==Request.STATUS_PROCESSING)\
                        .update({
                            'status':Request.STATUS_FINISHED, #'response':request.json['response'],
                            'updated_at':datetime.datetime.now()
                        })
            
                
            if(ucount>0):
                if(request.json['action']=="searchbyname"):
                    res =json.loads(request.json['response'])
                    if('result' in res):
                        for x in res['result']:
                            c = session.query(Customer).filter_by(rnumber=x[3]).first()
                            if(c is None):
                                session.add(Customer(id=x[0],rnumber=x[3],lastname=x[1],firstname=x[2]))
                                session.flush()
            
            return json.dumps({
                'result':'success'
            },ensure_ascii=False).encode('utf8')

        except Exception as e:
            traceback.print_exc()
            msg =  e.args if len(e.args)>0 else str(e)            
            return json.dumps({
                'result':'error',
                'msg': msg
            },ensure_ascii=False).encode('utf8')
コード例 #3
0
ファイル: Models.py プロジェクト: Batboldsanghi/ComputeServer
 def get_pendingC1(cls, mode):
     row = session.query(cls)\
         .filter_by(mode = mode, c1status = cls.C1_STATUS_PENDING)\
         .filter(cls.detail.isnot(None))\
         .filter(cls.status==cls.STATUS_FINISHED)\
         .order_by(cls.created_at.desc())\
         .first()
     if (row != None):
         row.c1status = cls.C1_STATUS_PROCESSING
         session.flush()
         return row
     else:
         return None
コード例 #4
0
    def activation(self):
        try:
            activationParams = {
                "fields" : {
                    "email": {
                        "type": "string", 
                        "required": True, 
                        "regex": '^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'
                    },
                    "code":{"type":"string", "required": True}
                },
                "message" : {
                    "email":{
                        "type": "тэмдэгт оруулна уу",
                        "required": "email тодорхойгүй байна",
                        "regex": "имэйлээ зөв оруулна уу"
                    },
                    "code":{
                        "type": "Өгөгдлийн төрөл буруу байна",
                        "required": "Код тодорхойгүй байна"
                    }
                }
            }
            

            v = BuValidator(activationParams)
            v.validate(request.json)

            email = request.json['email']
            user = session.query(User).filter_by(email=email).first()
            if(user==None):
                raise Exception('email is wrong')

            if('code' in request.json):
                if(bcrypt.checkpw(request.json.get('code').encode("utf8"),user.activation.encode("utf8"))==False):
                    raise Exception('activation code is wrong')
                user.status=User.STATUS_ACTIVE
                session.flush()

            

            return json.dumps({
                'result':'success'
            })
        except Exception as e:
            msg =  e.args if len(e.args)>0 else str(e)
            return json.dumps({
                'result':'error',
                'msg': msg
            },ensure_ascii=False).encode('utf8')        
コード例 #5
0
ファイル: server.py プロジェクト: Batboldsanghi/ComputeServer
 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)
コード例 #6
0
    def create(self):
        try:
            createParams = {
                "fields" : {
                    "email": {
                        "type": "string", 
                        "required": True, 
                        "regex": '^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'
                    },
                    "password": {"type": "string","required": True,"minlength":4}
                },
                "message" : {
                    "email":{
                        "type": "тэмдэгт оруулна уу",
                        "required": "email тодорхойгүй байна",
                        "regex": "имэйлээ зөв оруулна уу"
                    },
                    "password":{
                        "type": "Нууц үг үсэг тоо байна",
                        "required": "Нууц үг тодорхойгүй байна",
                        "minlength": "Нууц үг 4 олон тэмдэгттэй байна"
                    }
                }
            }
            

            v = BuValidator(createParams)
            v.validate(request.json)
            code = '123456'
            password_hashed = bcrypt.hashpw(request.json['password'].encode("utf8"), bcrypt.gensalt())
            code_hashed = bcrypt.hashpw(code.encode("utf8"), bcrypt.gensalt())
            
            user = User(
                uuid=User.generateID(),
                email=request.json['email'],
                password = password_hashed,
                activation = code_hashed
            )            
            session.add(user)
            session.flush()
            return json.dumps({
                'result':'success' 
            })        
        except Exception as e:            
            msg =  e.args if len(e.args)>0 else str(e)
            return json.dumps({
                'result':'error',
                'msg': msg
            },ensure_ascii=False).encode('utf8')
コード例 #7
0
    def crequest(self):

        try:
            requestParams = {
                'fields': {
                    'name': {
                        "type": "string",
                        "minlength": 2,
                        "required": True
                    }
                },
                'message': {
                    'name': {
                        "type": "Нэр буруу байна",
                        "minlength": "Нэр буруу байна",
                        "required": "Нэр тодорхойгүй байна"
                    },
                }
            }

            v = BuValidator(requestParams)
            dd = request.form.to_dict()
            del (dd['csrf_token'])
            v.validate(dd)

            req = json.dumps(
                {
                    "inputVal": request.form['name'],
                    "expression": "c.customername",
                    "id": "01",
                    "isCitizen": "true"
                },
                ensure_ascii=False).encode('utf8')

            cc = session.query(Request)\
                .filter(Request.action=="searchbyname")\
                .filter(Request.request==req)\
                .filter(Request.status.in_((0,1)))\
                .count()
            if (cc == 0):
                session.add(Request(action="searchbyname", request=req))
                session.flush()
            return redirect("/customer/index")

        except Exception as e:
            msg = e.args if len(e.args) > 0 else str(e)
            print(msg)
            return redirect("/customer/search")
コード例 #8
0
    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")
コード例 #9
0
    def setDetail(self):
        """Монгол банкны мэдээлэлийг шинэчилж байна.
        """
        try:
            setDetailParams = {
                'fields': {
                    'id': {
                        'type': 'integer',
                        'required': True
                    },
                    'rnumber': {
                        "type": "string",
                        "required": True,
                        "registernumber": True
                    },
                    'status': {
                        'type': 'integer'
                    },
                    'detail': {
                        'type': 'string',
                        'nullable': True
                    },
                    'detail2': {
                        'type': 'string',
                        'nullable': True
                    }
                },
                'message': {
                    'id': {
                        'type': 'Төрөл буруу байна',
                        'required': 'id тодорхойгүй байна'
                    },
                    'rnumber': {
                        "type": "өгөгдлийн төрөл буруу байна",
                        "registernumber": "Регистрийн дугаар буруу байна",
                        "required": "Регистрийн дугаар тодорхойгүй байна"
                    },
                    'status': {
                        'type': 'Төрөл буруу байна'
                    },
                    'detail': {
                        'type': 'Төрөл буруу байна'
                    },
                    'detail2': {
                        'type': 'Төрөл буруу байна'
                    }
                }
            }

            v = BuValidator(setDetailParams)
            v.validate(request.json)

            row = session.query(Info).filter_by(
                id=request.json['id'],
                rnumber=request.json['rnumber']).first()
            if (row is None):
                raise Exception('бичлэг байхгүй байна')
            if ('status' in request.json):
                row.status = request.json['status']
            if ('detail' in request.json):
                row.detail = request.json['detail']
            if ('detail2' in request.json):
                row.detail2 = request.json['detail2']
            session.flush()

            return json.dumps({
                'result': 'success',
                'row': row.to_dict()
            },
                              ensure_ascii=False)
        except Exception as e:

            traceback.print_exc()
            msg = e.args if len(e.args) > 0 else str(e)

            return json.dumps({
                'result': 'error',
                'msg': msg
            },
                              ensure_ascii=False).encode('utf8')
コード例 #10
0
    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')
コード例 #11
0
    def insert(cls, row):                
        ddrow = session.query(cls)\
            .filter_by(dd=row['d/d'],\
                registriindugaar=row['registriindugaar'],\
                zeeliinkhemzhee = row['zeeliinkhemzhee'],\
                zeelolgosonognoo = row['zeelolgosonognoo']\
            ).first()
        
        if(ddrow is None):                     
            new_row = Ddrows(
                downloaded_date=row['downloaded_date'],
                filename = row['filename'],                
                dd = row['d/d'],                
                registriindugaar = row['registriindugaar'],
                zeeliinkhemzhee = row['zeeliinkhemzhee'],
                zeelolgosonognoo = 	row['zeelolgosonognoo'],
                tologdokhognoo=row['tologdokhognoo'],
                valiutynner=row['valiutynner'],
                oriinuldegdel=row['oriinuldegdel'],
                kheviin=row['kheviin'],
                khugatsaakhetersen=row['khugatsaakhetersen'],
                kheviinbus=row['kheviinbus'],
                ergelzeetei=row['ergelzeetei'],
                muu=row['muu'],
                buleg=row['buleg'],
                dedbuleg=row['dedbuleg'],
                ukhekhbg_yndugaar=row['ukhekhbg-yndugaar'],
                ulsynburtgeliindugaar=row['ulsynburtgeliindugaar'],
                kartyndugaar=row['kartyndugaar'],
                tailbar=row['tailbar'],
                pred_tag=row['pred_tag'],
                payment_pred=row['payment_pred'],
                payment_pred_last=row['payment_pred_last'],
                rate_mean=row['rate_mean'],
                rate_pred=row['rate_pred'],
                month0=row['month0'],
                heviinbus_uldegdeltei=row['heviinbus_uldegdeltei'],
                heviinbus_uldegdelgui=row['heviinbus_uldegdelgui'],
                heviinbus_shugam=row['heviinbus_shugam'],

                loantypecode = row['loantypecode'],
                orgcode = row['orgcode'],
                statuscode = row['statuscode'],
                loanclasscode = row['loanclasscode']
            )
            
            session.add(new_row)
            session.flush()
        elif(ddrow.oriinuldegdel!=0 or ddrow.oriinuldegdel!=row['oriinuldegdel']):
            
            session.query(cls)\
                .filter_by(id=ddrow.id)\
                .update({
                    'downloaded_date':row['downloaded_date'],
                    'tologdokhognoo':row['tologdokhognoo'],
                    'valiutynner':row['valiutynner'],
                    'oriinuldegdel':row['oriinuldegdel'],
                    'kheviin':row['kheviin'],
                    'khugatsaakhetersen':row['khugatsaakhetersen'],
                    'kheviinbus':row['kheviinbus'],
                    'ergelzeetei':row['ergelzeetei'],
                    'muu':row['muu'],
                    'buleg':row['buleg'],
                    'dedbuleg':row['dedbuleg'],
                    'ukhekhbg_yndugaar':row['ukhekhbg-yndugaar'],
                    'ulsynburtgeliindugaar':row['ulsynburtgeliindugaar'],
                    'kartyndugaar':row['kartyndugaar'],
                    'tailbar':row['tailbar'],
                    'pred_tag':row['pred_tag'],
                    'payment_pred':row['payment_pred'],
                    'payment_pred_last':row['payment_pred_last'],
                    'rate_mean':row['rate_mean'],
                    'rate_pred':row['rate_pred'],
                    'month0':row['month0'],
                    'heviinbus_uldegdeltei':row['heviinbus_uldegdeltei'],
                    'heviinbus_uldegdelgui':row['heviinbus_uldegdelgui'],
                    'heviinbus_shugam':row['heviinbus_shugam'],

                    'loantypecode':row['loantypecode'],
                    'orgcode':row['orgcode'],
                    'statuscode':row['statuscode'],
                    'loanclasscode':row['loanclasscode']
                })
コード例 #12
0
    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()