コード例 #1
0
def updateUser(name,
               age,
               email,
               phone,
               dose_no,
               search_by,
               pincode,
               state_id=-1,
               dist_id=-1,
               dist_name='NA'):
    session = Session()

    user, _ = isUserExist(email)
    if _ != True:
        return "Failed to Update the Details as user doesnt exist", False
    user.name = name
    user.age = int(age)
    user.phone = phone
    user.dose_no = dose_no
    user.search_by = search_by
    user.pincode = int(pincode) if user.search_by == 'pincode' else -1
    user.dist_id = int(dist_id) if user.search_by == 'district' else -1
    user.state_id = int(state_id) if user.search_by == 'district' else -1
    user.dist_name = dist_name if user.search_by == 'district' else 'NA'
    session.add(user)
    session.commit()
    session.close()
    return 'Added SuccessFully', True
コード例 #2
0
def addUser(name, age, email, phone,dose_no, search_by,pincode,state_id=-1 ,dist_id=-1,dist_name='NA'):
    session=Session()
    
    user = User()
    user.name = name
    user.age = int(age)
    user.phone = phone
    user.email = email
    user.dose_no=dose_no
    user.search_by = search_by
    if user.search_by=='pincode':
        user.pincode = int(pincode)
    else:
        user.dist_id = int(dist_id)
        user.dist_name=dist_name
        user.state_id=int(state_id)

    user.secret_key=common_util.getToken()+common_util.getToken()
    _,isExist=isUserExist(email)
    if isExist==False:
        session.add(user)
        session.commit()
        session.close()
        return 'Added SuccessFully',True
    else:
        session.close()
        return 'User already exists with Email Id ',False
コード例 #3
0
def addCenter(cid, cname, caddr, cpin, fee, block_name):
    try:
        session = Session()

        temp = None
        centerobj = session.query(Center).filter(
            Center.center_id == cid).first()

        if centerobj != None:
            temp = centerobj
        else:
            temp = Center()
        temp.center_name = cname
        temp.center_id = cid
        temp.address = caddr
        temp.pincode = cpin
        temp.fee = fee
        temp.block_name = block_name
        temp.lastUpdated = common_util.getUtcTimeStamp()
        session.add(temp)
        res = session.commit()

        return "Added Center->[{}]".format(res), True

    except Exception as e:
        return "error {} occured while Adding Center {}  for {}".format(
            e, cid, cpin), False

    finally:
        session.close()
コード例 #4
0
def addDistrict(dist_id, dist_name='districtName', isTracked=False):
    print('*' * 80)
    print('Adding District {} with  id {} '.format(dist_name, dist_id))
    print('*' * 80)
    lastUpdated = common_util.getUtcTimeStamp()
    try:
        session = Session()
        res, isexist = isDistExist(dist_id)
        if isexist == False:
            print('-' * 80)
            print("District ", dist_id, "NOT EXIST IN DB ")
            temp_p = District()
            temp_p.district_name = dist_name
            temp_p.district_id = int(dist_id)
            temp_p.isTrackedAllPin = isTracked
            temp_p.lastUpdated = lastUpdated
            print(temp_p)
            session.add(temp_p)
            session.commit()
            session.close()
            print('-' * 80)

            return 'District added SuccessFully', True
        else:
            print("District  ", dist_id, "EXIST IN DB")

            return 'District Exist in DB ', False

    except Exception as e:

        return 'Exception -->{} '.format(e), False

    finally:
        session.close()
コード例 #5
0
def addSessions(sid, cid, min_age, available, avail_dose_1, avail_dose_2,
                slots, date, vaccine_name):
    try:
        session = Session()
        slots = ",".join(slots)
        sid = str(sid)
        cid = int(cid)
        available = int(available)
        date = str(date)
        vaccine_name = str(vaccine_name)
        print("$" * 80)
        # whether Session Exist.
        temp = None
        oldRecord = session.query(VaccineSession).filter(
            VaccineSession.session_id == sid).first()

        print("OLD RECORD-->", oldRecord)

        if oldRecord != None:
            temp = oldRecord
            print("{} {} already Exist hence Updating...".format(
                sid, vaccine_name))
            temp.last_avail_cnt = oldRecord.available
            temp.last_avail_dose_1 = oldRecord.avail_dose_1
            temp.last_avail_dose_2 = oldRecord.avail_dose_2

        else:
            temp = VaccineSession()
            print("{} {} is New Record".format(sid, vaccine_name))
            temp.last_avail_cnt = available
            temp.last_avail_dose_1 = avail_dose_1
            temp.last_avail_dose_2 = avail_dose_2

        temp.session_id = sid
        temp.center_id = cid
        temp.min_age = min_age
        temp.available = available
        temp.avail_dose_1 = avail_dose_1
        temp.avail_dose_2 = avail_dose_2
        temp.slots = slots
        temp.date = date
        temp.vaccine_name = vaccine_name
        temp.lastUpdated = common_util.getUtcTimeStamp()

        # for the first Time Last available is same as avail.
        session.add(temp)
        res = session.commit()

        return "Added Seesion->[{}]".format(res), True

    except Exception as e:
        print("A fatal Exception " + str(e))
        return "error [{}] occured while Adding Sessions of Vaccine for Center[{}]".format(
            e, cid), False

    finally:
        session.close()
コード例 #6
0
def startReceivingMail(email):
    session=Session()
    user ,_= isUserExist(email)
    if _!=True:
        return "Failed to Update the Details as user doesnt exist",False
    user.receive_email=True

    session.add(user)
    session.commit()
    session.close()
コード例 #7
0
def isUserExist(email):
    try:
        session = Session()
        res = session.query(User).filter(User.email == email).first()
        if res == None:
            return "Not found ", False
        return res, True
    except Exception as e:
        return 'Not Found e->{}'.format(e), False
    finally:
        session.close()
コード例 #8
0
def isPincodeExist(pincode):
    try:
        session = Session()
        res = session.query(Pincode).filter(Pincode.pincode == pincode).first()
        if res == None:
            raise Exception
        return res, True
    except Exception as e:
        return 'Not Found e->{}'.format(e), False
    finally:
        session.close()
コード例 #9
0
def getPreference(email):
    try:
        session = Session()
        res = session.query(UserPref).filter(UserPref.email == email).first()
        if res == None:
            return None, False
        return res, True
    except Exception as e:
        return 'Not Found e->{}'.format(e), False
    finally:
        session.close()
コード例 #10
0
def addPincode(pincode, district_id=-1):
    print('*' * 80)
    print('Adding Pincode {} with dist id {} '.format(pincode, district_id))
    print('*' * 80)
    lastUpdated = common_util.getUtcTimeStamp()
    try:
        session = Session()
        res, isexist = isPincodeExist(pincode)
        if isexist == False:
            print('-' * 80)
            print("PINCODE ", pincode, "NOT EXIST IN DB ")
            temp_p = Pincode()
            temp_p.pincode = int(pincode)
            temp_p.district_id = int(district_id)
            temp_p.lastUpdated = lastUpdated
            print(temp_p)
            session.add(temp_p)
            session.commit()
            session.close()
            print('-' * 80)

            return 'pincode added SuccessFully', True
        else:
            print("PINCODE ", pincode, "EXIST IN DB")

            # pincode exist..
            # now check whether it has District ID or not

            if district_id != -1 and res.district_id == -1:
                print('-+' * 40)
                print(
                    "Updating Pincode {} District id with {} where old dist id was {}"
                    .format(pincode, district_id, res.district_id))

                # queried district id is not provided i.e it is -1
                res.district_id = int(district_id)
                res.lastUpdated = lastUpdated
                session.add(res)
                session.commit()
                print('-+' * 40)

                # updated Pincode with District Id

            # else pincode already exist and no modification is going to be done .

            return 'Pincode Exists[no modification done]', False

    except Exception as e:

        return 'Exception -->{} '.format(e), False

    finally:
        session.close()
コード例 #11
0
def isDistExist(dist_id):
    try:
        session = Session()
        res = session.query(District).filter(
            District.district_id == dist_id).first()
        if res == None:
            raise Exception
        return res, True
    except Exception as e:
        return 'Not Found e->{}'.format(e), False
    finally:
        session.close()
コード例 #12
0
def updatePrevCnt(sid):
    try:
        session = Session()
        s = session.query(VaccineSession).filter(
            VaccineSession.session_id == sid).first()
        s.last_avail_cnt = s.available
        s.last_avail_dose_1 = s.avail_dose_1
        s.last_avail_dose_2 = s.avail_dose_2
        session.add(s)
        session.commit()
    except Exception as e:
        print("Exception at updating previous cnt", str(e))
    finally:
        session.close()
コード例 #13
0
def getAllCenters():
    try:
        session = Session()
        centers = session.query(Center).order_by(Center.lastUpdated).all()
        centerList = []
        for center in centers:
            centerList.append(center)

        return centerList, True

    except Exception as e:
        return "error {} occured while Getting all Centers ".format(e), False

    finally:
        session.close()
コード例 #14
0
def matchToken(email, tokenfromUser):
    try:
        session = Session()
        user, isExist = getPreference(email)
        if isExist == False:
            return "User Doesnot Exist", False

        if user.email == email and user.token == tokenfromUser and user.token != "NA":
            return "Validated Successfully ", True
        else:
            return "Failure to Validate Token", False
    except Exception as e:
        return "error occured While saving token " + str(e), False
    finally:
        session.close()
コード例 #15
0
def updateLastUpdated(dist_id):
    try:
        session = Session()
        Obj = session.query(District).filter(
            District.district_id == dist_id).first()
        if Obj == None:
            raise Exception
        Obj.lastUpdated = common_util.getUtcTimeStamp()
        session.add(Obj)
        session.commit()

        return "Updated LastUpdated Successfully", True
    except Exception as e:
        return 'Not Found e->{}'.format(e), False
    finally:
        session.close()
コード例 #16
0
def updateLastUpdated(pincode):
    try:
        session = Session()
        pinObj = session.query(Pincode).filter(
            Pincode.pincode == pincode).first()
        if pinObj == None:
            raise Exception
        pinObj.lastUpdated = common_util.getUtcTimeStamp()
        session.add(pinObj)
        session.commit()

        return "Updated LastUpdated Successfully", True
    except Exception as e:
        return 'Not Found e->{}'.format(e), False
    finally:
        session.close()
コード例 #17
0
def getAllSessions():
    try:
        session = Session()
        sessionsQ = session.query(VaccineSession).order_by(
            VaccineSession.lastUpdated).all()
        sessionList = []
        for s in sessionsQ:
            sessionList.append(s)

        return sessionList, True

    except Exception as e:
        return "error {} occured while Getting all Sessions ".format(e), False

    finally:
        session.close()
コード例 #18
0
def storeToken(email, newToken):
    try:
        session = Session()
        user, isExist = getPreference(email)
        if isExist == False:
            user = UserPref()
        user.token = newToken
        user.email = email
        session.add(user)
        session.commit()
        print("Stored key in db->", newToken)
        return "token added Successfully", True
    except Exception as e:
        return "error occured While saving token " + str(e), False
    finally:
        session.close()
コード例 #19
0
def getCenterByID(center_id):
    try:
        session = Session()
        center = session.query(Center).filter(
            Center.center_id == center_id).first()
        if center != None:
            return center, True
        else:
            return None, False

    except Exception as e:
        return "error {} occured while Getting Centers   for {}".format(
            e, cpin), False

    finally:
        session.close()
コード例 #20
0
def getCentersByPincode(pincode):
    try:
        session = Session()
        centers = session.query(Center).filter(
            Center.pincode == pincode).order_by(Center.lastUpdated).all()
        centerList = []
        for center in centers:
            centerList.append(center)

        return centerList, True

    except Exception as e:
        return "error {} occured while Getting Centers   for {}".format(
            e, cpin), False

    finally:
        session.close()
コード例 #21
0
def getSessionByCenter(center_id):
    try:
        session = Session()
        centers = session.query(VaccineSession).filter(
            VaccineSession.center_id == center_id).order_by(
                VaccineSession.lastUpdated).all()
        sList = []
        for center in centers:
            sList.append(center)

        return sList, True

    except Exception as e:
        return "error {} occured while Getting Sessions   for {}".format(
            e, center_id), False

    finally:
        session.close()
コード例 #22
0
def trackComplete(dist_id):
    try:

        session = Session()
        district = session.query(District).filter(
            District.district_id == dist_id).first()
        district.lastUpdated = common_util.getUtcTimeStamp()
        district.isTrackedAllPin = True

        session.add(district)
        session.commit()

        return 'Districts All pin tracked successfully', True

    except Exception as e:
        return "Exception occurred {}".format(e), False

    finally:
        session.close()
コード例 #23
0
def removeunTaggedPincode():
    try:
        session = Session()
        pincodes, _ = getAllPincodeWithoutDistricts()
        print("All pincodes without dist id ", pincodes['pincodes'])
        for pin in pincodes['pincodes']:
            print("Current Pin-> ", pin)
            usersLst, _ = user_model.getUsersofPincode(pin.pincode)
            print("total Users of this pincode-> ", usersLst['total'])
            if usersLst['total'] < 1:
                print("remove pincode ", pin.pincode,
                      " as no user is tagged to this pincode")
                session.delete(pin)

    except:
        return "Failed to remove untagged Pincode", False
    finally:
        session.commit()
        session.close()
コード例 #24
0
def getUserofDistID(distID):
    try:
        session = Session()
        users = session.query(User).filter(User.dist_id == distID).all()
        datas = {}
        userslst = []
        for user in users:
            userslst.append(user)

        datas['users'] = userslst
        datas['total'] = len(datas['users'])

        return datas, True

    except Exception as e:
        return "Exception occurred {}".format(e), False

    finally:
        session.close()
コード例 #25
0
def getUsersWithPincodeSelectBy():
    try:
        session = Session()
        users = session.query(User).filter(User.search_by == "pincode").all()
        datas = {}
        userslst = []
        for user in users:
            userslst.append(user)

        datas['users'] = userslst
        datas['total'] = len(datas['users'])

        return datas, True

    except Exception as e:
        return "Exception occurred {}".format(e), False

    finally:
        session.close()
コード例 #26
0
def removeUnTaggedDistricts():
    try:
        session = Session()
        alldist, _ = getAllDistricts()

        print(alldist)

        for dist in alldist['districts']:
            print(dist.district_id)
            allUsers, _ = user_model.getUserofDistID(dist.district_id)
            print(allUsers)
            if allUsers['total'] < 1:
                print("Remove ", dist.district_id,
                      " as no user is tagged to this dist id")
                session.delete(dist)
    except:
        return False
    finally:
        session.commit()
        session.close()
コード例 #27
0
def getPincodesByDistID(dist_id):
    try:
        session = Session()
        pincodes = session.query(Pincode).filter(
            Pincode.district_id == dist_id).order_by(
                Pincode.lastUpdated).all()
        datas = {}
        lst = []
        for pincode in pincodes:
            lst.append(pincode)

        datas['pincodes'] = lst
        datas['total'] = len(datas['pincodes'])
        return datas, True

    except Exception as e:
        return "Exception occurred {}".format(e), False

    finally:
        session.close()
コード例 #28
0
def getUsers():
    try:
        session = Session()
        users = session.query(User)
        datas = {}
        userslst = []
        for user in users:
            userslst.append(user)

        datas['users'] = userslst
        datas['total'] = len(datas['users'])
        print(datas)

        return datas, True

    except Exception as e:
        return "Exception occurred {}".format(e), False

    finally:
        session.close()
コード例 #29
0
def getAllPincodes():
    try:
        session = Session()
        pincodes = session.query(Pincode).order_by(Pincode.lastUpdated)
        datas = {}
        lst = []
        for pincode in pincodes:
            lst.append(pincode)

        datas['pincodes'] = lst
        datas['total'] = len(datas['pincodes'])
        print(datas)

        return datas, True

    except Exception as e:
        return "Exception occurred {}".format(e), False

    finally:
        session.close()
コード例 #30
0
def getAllSessionsWhereEmailNeededtoBEsend():
    try:
        session = Session()
        allsessions, suc = getAllSessions()
        validSessions = []
        if suc:
            for s in allsessions:
                print("Current Session -> ", s)
                if s.available - s.last_avail_cnt > 0:
                    print("Email needed to send for this")
                    validSessions.append(s)
                else:
                    print("email shouldnt sent for this")
                    pass
        return validSessions

    except:
        pass

    finally:
        session.close()