Ejemplo n.º 1
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()
Ejemplo n.º 2
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()
def removeOutDatedSession():
    try:
        session = Session()
        allSessions, _ = getAllSessions()
        print("$" * 80)

        print("Before deletion total ->", len(allSessions))
        print("$" * 80)

        currentDate_splitted = common_util.getDate().split("-")
        cur_day, cur_mnth = int(currentDate_splitted[0]), int(
            currentDate_splitted[1])
        print("Current Date->", cur_day, "-", cur_mnth)
        for s in allSessions:
            date_splitted = s.date.split("-")

            session_day, session_mnth = int(date_splitted[0]), int(
                date_splitted[1])
            print("session Date->", session_day, "-", session_mnth)

            if cur_mnth > session_mnth:
                # like cur date  1-06-2021 and session date 31-05-2021 then also remove
                print("remove this session")
                session.delete(s)
            elif cur_mnth == session_mnth:
                if cur_day - session_day >= 1:
                    print("Remove this Session ")
                    session.delete(s)
                else:
                    print("Keep this session")
    except Exception as e:
        return "Failure to delete outdated Session", False
    finally:
        session.commit()
        session.close()
        lsts, _ = getAllSessions()
        print("$" * 80)
        print("After deletion total ->", len(lsts))
        print("$" * 80)