Exemple #1
0
def get_off_services():
    session = get_session('ekomobile')
    services = get_class('service_fx')
    hstr_services = get_class('hstr_service_fx')
    result = []
    sers = session.query(hstr_services.object_id, hstr_services.service_id).\
        filter(or_(not hstr_services.deactivated,
                   hstr_services.deactivated > datetime.now())).\
        group_by(hstr_services.service_id).all()
    print('Get services list')

    for rec in sers:

        rapi = Rest(ctn=int(rec[0]))
        ser_name = session.query(services.bee_sync).filter(
            services.i_id == int(rec[1]), services).one()[0]
        api_sers = rapi.get_services_list()['services']
        for ser in api_sers:
            if ser['name'] == ser_name:
                result.append([ser_name, ser['removeInd']])
        if result[-1][0] != ser_name:
            warnings.warn('Kosyak, phone={}, service={}'.format(
                rapi.ctn, ser_name))
        print('Made {} of {}'.format(sers.index(rec) + 1, len(sers)))
    session.close()
    try:
        ex_write(['code', 'y/n'], result,
                 "C:/Users/админ/Desktop/remove_services.xlsx")
    except Exception:
        return result
Exemple #2
0
def get_off_services():
    session = get_session("ekomobile")
    services = get_class("service_fx")
    hstr_services = get_class("hstr_service_fx")
    result = []
    sers = (
        session.query(hstr_services.object_id, hstr_services.service_id)
        .filter(or_(not hstr_services.deactivated, hstr_services.deactivated > datetime.now()))
        .group_by(hstr_services.service_id)
        .all()
    )
    print("Get services list")

    for rec in sers:

        rapi = Rest(ctn=int(rec[0]))
        ser_name = session.query(services.bee_sync).filter(services.i_id == int(rec[1]), services).one()[0]
        api_sers = rapi.get_services_list()["services"]
        for ser in api_sers:
            if ser["name"] == ser_name:
                result.append([ser_name, ser["removeInd"]])
        if result[-1][0] != ser_name:
            warnings.warn("Kosyak, phone={}, service={}".format(rapi.ctn, ser_name))
        print("Made {} of {}".format(sers.index(rec) + 1, len(sers)))
    session.close()
    try:
        ex_write(["code", "y/n"], result, "C:/Users/админ/Desktop/remove_services.xlsx")
    except Exception:
        return result
Exemple #3
0
def remove_subscription(nums='C:/Users/админ/Desktop/1.txt',
                        begin=0,
                        show=False):
    rapi = Rest()
    count = 0

    if not isinstance(nums, list):
        nums = open(nums).readlines()
    for phone in nums[begin:]:
        rapi.change_owner(ctn=str(phone).strip())
        try:
            subscrs = rapi.get_subscriptions()['subscriptions']
        except KeyError:
            print(rapi.get_subscriptions())
        count += len(subscrs)
        for el in subscrs:
            rapi.remove_subscription(subscription_id=el['id'],
                                     subscription_type=el['type'])
        if len(subscrs) > 0:
            print('Made {} request(-s) for {}th of {} numbers'.format(
                len(subscrs),
                nums.index(phone) + 1, len(nums)))
        else:
            print(
                "Didn't found subscriptions on {}.\n{}th of {} numbers".format(
                    rapi.ctn,
                    nums.index(phone) + 1, len(nums)))
            nums.remove(phone)
    print('Totally made {} requests for remove subscriptions'.format(count))
    if count != 0:
        check_subscription(nums, show)
Exemple #4
0
def get_mass_serv():
    session = get_session('ekomobile')

    rapi = Rest()
    services = get_class('service_fx')
    agree = get_class('operator_agree')
    ctn = get_class('ctn')
    btp = get_class('operator_tarif')
    banlist = session.query(agree.i_id).filter(agree.moboperator == 1,
                                               agree.payment_type == 0,
                                               agree.discontinued == 0).all()
    banlist = [el[0] for el in banlist]
    ctnlist = session.query(ctn.msisdn, ctn.operator_tarif).filter(
        ctn.operator_agree.in_(banlist),
        ctn.status == 1).group_by(ctn.operator_tarif).all()
    result = []

    for el in ctnlist:

        rapi.change_owner(ctn=int(el[0]))
        rez = rapi.get_available_services()['availableServices']
        if len(rez) == 0:
            print(rapi.ctn)
        for r in rez:
            tarif = session.query(
                btp.name).filter(btp.i_id == int(el[1])).one()[0]
            try:
                serv = session.query(services.i_id).filter(
                    services.bee_sync == r['name']).one()[0]
            except NoResultFound:
                serv = 'Нет в билле!'
            result.append([
                rapi.ctn, el[1], tarif, serv, r['name'], r['entityName'],
                r['rcRate']
            ])
        print('{} из {}'.format(ctnlist.index(el) + 1, len(ctnlist)))

    names = ['Номер', 'Тариф', 'Техкод услуги', 'Название услуги', 'АП услуги']

    session.close()
    try:
        ex_write(names, result, path='C:/Users/ГостЪ/Desktop/services.xlsx')
    except ValueError:
        return result
    else:
        return
Exemple #5
0
def remove_subscription(nums="C:/Users/админ/Desktop/1.txt", begin=0, show=False):
    rapi = Rest()
    count = 0

    if not isinstance(nums, list):
        nums = open(nums).readlines()
    for phone in nums[begin:]:
        rapi.change_owner(ctn=str(phone).strip())
        try:
            subscrs = rapi.get_subscriptions()["subscriptions"]
        except KeyError:
            print(rapi.get_subscriptions())
        count += len(subscrs)
        for el in subscrs:
            rapi.remove_subscription(subscription_id=el["id"], subscription_type=el["type"])
        if len(subscrs) > 0:
            print("Made {} request(-s) for {}th of {} numbers".format(len(subscrs), nums.index(phone) + 1, len(nums)))
        else:
            print(
                "Didn't found subscriptions on {}.\n{}th of {} numbers".format(
                    rapi.ctn, nums.index(phone) + 1, len(nums)
                )
            )
            nums.remove(phone)
    print("Totally made {} requests for remove subscriptions".format(count))
    if count != 0:
        check_subscription(nums, show)
Exemple #6
0
def get_mass_serv():
    session = get_session("ekomobile")

    rapi = Rest()
    services = get_class("service_fx")
    agree = get_class("operator_agree")
    ctn = get_class("ctn")
    btp = get_class("operator_tarif")
    banlist = (
        session.query(agree.i_id).filter(agree.moboperator == 1, agree.payment_type == 0, agree.discontinued == 0).all()
    )
    banlist = [el[0] for el in banlist]
    ctnlist = (
        session.query(ctn.msisdn, ctn.operator_tarif)
        .filter(ctn.operator_agree.in_(banlist), ctn.status == 1)
        .group_by(ctn.operator_tarif)
        .all()
    )
    result = []

    for el in ctnlist:

        rapi.change_owner(ctn=int(el[0]))
        rez = rapi.get_available_services()["availableServices"]
        if len(rez) == 0:
            print(rapi.ctn)
        for r in rez:
            tarif = session.query(btp.name).filter(btp.i_id == int(el[1])).one()[0]
            try:
                serv = session.query(services.i_id).filter(services.bee_sync == r["name"]).one()[0]
            except NoResultFound:
                serv = "Нет в билле!"
            result.append([rapi.ctn, el[1], tarif, serv, r["name"], r["entityName"], r["rcRate"]])
        print("{} из {}".format(ctnlist.index(el) + 1, len(ctnlist)))

    names = ["Номер", "Тариф", "Техкод услуги", "Название услуги", "АП услуги"]

    session.close()
    try:
        ex_write(names, result, path="C:/Users/ГостЪ/Desktop/services.xlsx")
    except ValueError:
        return result
    else:
        return
Exemple #7
0
def check_subscription(nums, show=False, for_return=False):

    rapi = Rest()

    rez = []
    for phone in nums:
        try:
            rapi.change_owner(ctn=str(phone).strip())
        except NoResultFound:
            continue
        subscrs = rapi.get_subscriptions()["subscriptions"]
        if len(subscrs) > 0:
            rez.append(rapi.ctn)
            if show:
                for el in subscrs:
                    print(el[""])
        print("Check {} of {}".format(nums.index(phone) + 1, len(nums)))
    print("Now count of numbers with active subscriptions = {}".format(len(rez)))

    if len(rez) > 0:
        print("Numbers with subscriptions:")
        for el in rez:
            print(str(el))
Exemple #8
0
def check_subscription(nums, show=False, for_return=False):

    rapi = Rest()

    rez = []
    for phone in nums:
        try:
            rapi.change_owner(ctn=str(phone).strip())
        except NoResultFound:
            continue
        subscrs = rapi.get_subscriptions()['subscriptions']
        if len(subscrs) > 0:
            rez.append(rapi.ctn)
            if show:
                for el in subscrs:
                    print(el[''])
        print('Check {} of {}'.format(nums.index(phone) + 1, len(nums)))
    print('Now count of numbers with active subscriptions = {}'.format(
        len(rez)))

    if len(rez) > 0:
        print('Numbers with subscriptions:')
        for el in rez:
            print(str(el))