示例#1
0
def check_profiles():
    file_name = "config.json"
    path = os.path.join('.settings', file_name)
    import helpers.main_helper as main_helper
    from apis.onlyfans.onlyfans import auth_details
    json_config, json_config2 = main_helper.get_config(path)
    json_settings = json_config["settings"]
    profile_directories = json_settings["profile_directories"]
    profile_directory = profile_directories[0]
    matches = ["OnlyFans"]
    for match in matches:
        q = os.path.abspath(profile_directory)
        profile_site_directory = os.path.join(q, match)
        if os.path.exists(profile_site_directory):
            e = os.listdir(profile_site_directory)
            e = [os.path.join(profile_site_directory, x, "auth.json")
                 for x in e]
            e = [x for x in e if os.path.exists(x)]
            if e:
                continue
        default_profile_directory = os.path.join(
            profile_site_directory, "default")
        os.makedirs(default_profile_directory, exist_ok=True)
        auth_filepath = os.path.join(default_profile_directory, "auth.json")
        if not os.path.exists(auth_filepath):
            new_item = {}
            new_item["auth"] = auth_details().export()
            main_helper.export_data(new_item, auth_filepath)
            string = f"{auth_filepath} has been created. Fill in the relevant details and then press enter to continue."
            input(string)
        print
    print
示例#2
0
def fix(config={}):
    added = []
    changed = []
    fix = []
    settings = {}
    global_user_agent = ""
    for key, value in config.items():
        if key == "settings":
            settings = value
            auto_profile_choice = settings.pop("auto_profile_choice", None)
            socks5_proxies = settings.pop("socks5_proxy", None)
            if socks5_proxies:
                fixed_socks5_proxies = []
                for socks5_proxy in socks5_proxies:
                    fixed_socks5_proxy = f"socks5://{socks5_proxy}"
                    fixed_socks5_proxies.append(fixed_socks5_proxy)
                settings["proxies"] = fixed_socks5_proxies
            global_user_agent = settings.pop("global_user_agent", None)
        if key == "supported":
            for key2, value2 in value.items():
                temp_auth = value2.pop("auth", None)
                if temp_auth:
                    q = os.path.abspath(".settings")
                    backup_config_filepath = os.path.join(
                        q, "config_backup.json")
                    print(
                        f"LEGACY CONFIG FOUND, BACKING IT UP AND CREATING A NEW ONE. ({backup_config_filepath})"
                    )
                    export_json(backup_config_filepath, config)
                    print
                    temp_auth["user_agent"] = global_user_agent
                    auth = {}
                    temp_auth = auth_details(temp_auth).__dict__
                    auth["auth"] = temp_auth
                    if "profile_directories" in settings:
                        dpd = settings["profile_directories"][0]
                        default_profile_directory = os.path.join(
                            os.path.abspath(dpd), key2, "default")
                        os.makedirs(default_profile_directory, exist_ok=True)
                        profile_auth_filepath = os.path.join(
                            default_profile_directory, "auth.json")
                        export_json(profile_auth_filepath, auth)
                        print(
                            f"{profile_auth_filepath} HAS BEEN CREATED, CHECK IF IT'S CORRECT."
                        )
                print
                for key3, settings in value2.items():
                    if key3 == "settings":
                        settings["text_length"] = int(settings["text_length"])
                        re = settings.pop("download_paths", None)
                        if re:
                            settings["download_directories"] = re
                            string = f"download_paths to download_directories in {key2}"
                            changed.append(string)
                        re = settings.get("metadata_directory_format", None)
                        if not re:
                            settings[
                                "metadata_directory_format"] = "{site_name}/{username}/Metadata"
                            string = f"metadata_directory_format in {key2}"
                            added.append(string)
                        filename_format = settings.pop("file_name_format",
                                                       None)
                        if filename_format:
                            settings["filename_format"] = filename_format
                        reformats = {
                            k: v
                            for k, v in settings.items() if "_format" in k
                        }
                        bl = ["date_format"]
                        reformats = {
                            k: v
                            for k, v in reformats.items() if k not in bl
                        }
                        for re_name, re_value in reformats.items():
                            top = ["{id}", "{file_name}"]
                            bottom = ["{media_id}", "{filename}"]
                            z = list(zip(top, bottom))
                            for x in z:
                                if x[0] in re_value:
                                    settings[re_name] = settings[
                                        re_name].replace(x[0], x[1])
                                    reformats[re_name] = settings[re_name]
                        x = format_types(reformats)
                        q = x.check_rules()
                        if not q[1]:
                            fix.append(f"{key2} - {q[0]}")
                        c = x.check_unique()
                        if not c["bool_status"]:
                            s = f"{key2} - {c['string']}"
                            s_list = s.split("\n")
                            fix.extend(s_list)
                        print
            value.pop("fourchan", None)
            value.pop("bbwchan", None)
    added = "\n".join([f"Added {x}" for x in added if x])
    changed = "\n".join([f"Changed {x}" for x in changed if x])
    fix = "\n".join([f"Fix: {x}" for x in fix if x])
    seperator = "\n" * 2
    changed2 = seperator.join([added, changed, fix])
    if not all(x for x in changed2.split("\n") if not x):
        changed2 = changed2.strip()
        if changed2:
            print(f"\n{changed2}")
        if fix:
            string = "\nFix the problems above and then restart the script."
            print(string.upper())
            input()
            exit(0)
    return config, changed2