Ejemplo n.º 1
0
def manage_subscriptions(api: start,
                         auth_count=0,
                         identifier="",
                         refresh: bool = False):
    if identifier:
        results = api.get_subscription(identifier=identifier)
        results = [results]
    else:
        results = api.get_subscriptions(refresh=refresh)
    if blacklist_name:
        r = api.get_lists()
        if not r:
            return [False, []]
        new_results = [c for c in r if blacklist_name == c["name"]]
        if new_results:
            item = new_results[0]
            list_users = item["users"]
            if int(item["usersCount"]) > 2:
                list_id = str(item["id"])
                list_users = api.get_lists_users(list_id)
            users = list_users
            bl_ids = [x["username"] for x in users]
            results2 = results.copy()
            for result in results2:
                identifier = result.username
                if identifier in bl_ids:
                    print("Blacklisted: " + identifier)
                    results.remove(result)
    results.sort(key=lambda x: x.subscribedByData.expiredAt)
    results.sort(key=lambda x: x.is_me, reverse=True)
    results2 = []
    for result in results:
        result.auth_count = auth_count
        username = result.username
        now = datetime.utcnow().date()
        # subscribedBy = result["subscribedBy"]
        subscribedByData = result.subscribedByData
        result_date = subscribedByData.expiredAt if subscribedByData else datetime.utcnow(
        ).isoformat()
        price = subscribedByData.price
        subscribePrice = subscribedByData.subscribePrice
        result_date = datetime.fromisoformat(result_date).replace(
            tzinfo=None).date()
        if ignore_type in ["paid"]:
            if price > 0:
                continue
        if ignore_type in ["free"]:
            if subscribePrice == 0:
                continue
        results2.append(result)
    api.auth.subscriptions = results2
    return results2
Ejemplo n.º 2
0
def account_setup(api: start, identifier=""):
    status = False
    authed = api.login()
    if isinstance(authed, create_auth):
        jobs = json_settings["jobs"]
        profile_directory = json_global_settings["profile_directories"][0]
        profile_directory = os.path.abspath(profile_directory)
        profile_directory = os.path.join(profile_directory, authed.username)
        profile_metadata_directory = os.path.join(
            profile_directory, "Metadata")
        metadata_filepath = os.path.join(
            profile_metadata_directory, "Mass Messages.json")
        print
        if authed.isPerformer:
            imported = import_archive(metadata_filepath)
            mass_messages = api.get_mass_messages(resume=imported)
            export_archive(mass_messages, metadata_filepath,
                           json_settings)
        # chats = api.get_chats()
        if not identifier and jobs["scrape_names"]:
            # metadata_filepath = os.path.join(
            #     profile_metadata_directory, "Subscriptions.json")
            # imported = import_archive(metadata_filepath)
            subscriptions = api.get_subscriptions()
        # collection = []
        # for subscription in subscriptions:
        #     delattr(subscription,"download_info")
        #     delattr(subscription,"sessions")
        #     delattr(subscription,"scraped")
        #     delattr(subscription,"is_me")
        #     delattr(subscription,"links")
        #     collection.append(subscription)
        # collection = jsonpickle.encode(
        #     collection, unpicklable=False)
        # collection = jsonpickle.decode(collection)
        # export_archive(collection, metadata_filepath,
        #                 json_settings)
        status = True
    return status