示例#1
0
def main():
    GLOBAL.config = getConfig('config.json')

    ####### UNCOMMENT TO DEBUG #######
    # debug({})
    ##################################

    GLOBAL.arguments = parseArguments()

    if GLOBAL.arguments.log is not None:
        GLOBAL.arguments.log = GLOBAL.arguments.log.name

    if GLOBAL.arguments.subreddit is not None:
        GLOBAL.arguments.subreddit = "+".join(GLOBAL.arguments.subreddit)

    GLOBAL.directory = Path(GLOBAL.arguments.directory)

    checkConflicts()

    print(sys.argv)

    if GLOBAL.arguments.NoDownload:
        getPosts()
        quit()

    if GLOBAL.arguments.log is not None:
        logDir = Path(GLOBAL.arguments.log)
        downloader(postFromLog(logDir))

    else:
        downloader(getPosts())
def main():
    GLOBAL.arguments = parseArguments()

    if GLOBAL.arguments.directory is not None:
        GLOBAL.directory = Path(GLOBAL.arguments.directory)
    else:
        GLOBAL.directory = Path(input("download directory: "))

    print("\n"," ".join(sys.argv),"\n",noPrint=True)

    try:
        checkConflicts()
    except ProgramModeError as err:
        PromptUser()

    if not Path(GLOBAL.configDirectory).is_dir():
        os.makedirs(GLOBAL.configDirectory)
    GLOBAL.config = getConfig(GLOBAL.configDirectory / "config.json")

    if GLOBAL.arguments.log is not None:
        logDir = Path(GLOBAL.arguments.log)
        download(postFromLog(logDir))
        sys.exit()
    
    try:
        POSTS = getPosts(prepareAttributes())
    except InsufficientPermission:
        print("You do not have permission to do that")
        sys.exit()
    except NoMatchingSubmissionFound:
        print("No matching submission was found")
        sys.exit()
    except NoRedditSupoort:
        print("Reddit does not support that")
        sys.exit()
    except NoPrawSupport:
        print("PRAW does not support that")
        sys.exit()
    except MultiredditNotFound:
        print("Multireddit not found")
        sys.exit()
    except InvalidSortingType:
        print("Invalid sorting type has given")
        sys.exit()
    except InvalidRedditLink:
        print("Invalid reddit link")
        sys.exit()

    if POSTS is None:
        print("I could not find any posts in that URL")
        sys.exit()

    if GLOBAL.arguments.NoDownload:
        sys.exit()

    else:
        download(POSTS)
def main():

    VanillaPrint(
        f"\nBulk Downloader for Reddit v{__version__}\n" \
        f"Written by Ali PARLAKCI – [email protected]\n\n" \
        f"https://github.com/aliparlakci/bulk-downloader-for-reddit/"
    )
    GLOBAL.arguments = parseArguments()

    if GLOBAL.arguments.directory is not None:
        GLOBAL.directory = Path(GLOBAL.arguments.directory.strip())
    else:
        GLOBAL.directory = Path(input("\ndownload directory: ").strip())

    print("\n"," ".join(sys.argv),"\n",noPrint=True)
    print(f"Bulk Downloader for Reddit v{__version__}\n",noPrint=True
    )

    try:
        checkConflicts()
    except ProgramModeError as err:
        PromptUser()

    if not Path(GLOBAL.defaultConfigDirectory).is_dir():
        os.makedirs(GLOBAL.defaultConfigDirectory)

    if Path("config.json").exists():
        GLOBAL.configDirectory = Path("config.json")
    else:
        GLOBAL.configDirectory = GLOBAL.defaultConfigDirectory  / "config.json"

    GLOBAL.config = getConfig(GLOBAL.configDirectory)

    if GLOBAL.arguments.log is not None:
        logDir = Path(GLOBAL.arguments.log)
        download(postFromLog(logDir))
        sys.exit()

    try:
        POSTS = getPosts(prepareAttributes())
    except Exception as exc:
        logging.error(sys.exc_info()[0].__name__,
                      exc_info=full_exc_info(sys.exc_info()))
        print(log_stream.getvalue(),noPrint=True)
        print(exc)
        sys.exit()

    if POSTS is None:
        print("I could not find any posts in that URL")
        sys.exit()

    if GLOBAL.arguments.NoDownload:
        sys.exit()

    else:
        download(POSTS)
示例#4
0
def main():
    if sys.argv[-1].endswith(__file__):
        GLOBAL.arguments = parseArguments(input("> ").split())
    else:
        GLOBAL.arguments = parseArguments()
    if GLOBAL.arguments.directory is not None:
        GLOBAL.directory = Path(GLOBAL.arguments.directory)
    else:
        print("Invalid directory")
        quit()
    GLOBAL.config = getConfig(Path(PurePath(__file__).parent / 'config.json'))

    ####### UNCOMMENT TO DEBUG #######
    # debug({})
    ##################################

    checkConflicts()

    mode = prepareAttributes()

    print(sys.argv)

    if GLOBAL.arguments.log is not None:
        logDir = Path(GLOBAL.arguments.log)
        download(postFromLog(logDir))
        quit()

    try:
        POSTS = getPosts(prepareAttributes())
    except NoMatchingSubmissionFound:
        print("No matching submission was found")
        quit()
    except NoRedditSupoort:
        print("Reddit does not support that")
        quit()
    except NoPrawSupport:
        print("PRAW does not support that")
        quit()
    except MultiredditNotFound:
        print("Multireddit not found")
        quit()
    except InvalidSortingType:
        print("Invalid sorting type has given")
        quit()
    except InvalidRedditLink:
        print("Invalid reddit link")
        quit()

    if GLOBAL.arguments.NoDownload:
        quit()

    else:
        download(POSTS)
示例#5
0
def main():
    
    if Path("config.json").exists():
        GLOBAL.configDirectory = Path("config.json")
    else:
        if not Path(GLOBAL.defaultConfigDirectory).is_dir():
            os.makedirs(GLOBAL.defaultConfigDirectory)
        GLOBAL.configDirectory = GLOBAL.defaultConfigDirectory  / "config.json"
    try:
        GLOBAL.config = Config(GLOBAL.configDirectory).generate()
    except InvalidJSONFile as exception:
        VanillaPrint(str(exception.__class__.__name__),">>",str(exception))
        VanillaPrint("Resolve it or remove it to proceed")
        input("\nPress enter to quit")
        sys.exit()

    sys.argv = sys.argv + GLOBAL.config["options"].split()

    arguments = Arguments.parse()
    GLOBAL.arguments = arguments

    if arguments.set_filename:
        Config(GLOBAL.configDirectory).setCustomFileName()
        sys.exit()

    if arguments.set_folderpath:
        Config(GLOBAL.configDirectory).setCustomFolderPath()
        sys.exit()

    if arguments.set_default_directory:
        Config(GLOBAL.configDirectory).setDefaultDirectory()
        sys.exit()

    if arguments.set_default_options:
        Config(GLOBAL.configDirectory).setDefaultOptions()
        sys.exit()

    if arguments.use_local_config:
        JsonFile("config.json").add(GLOBAL.config)
        sys.exit()
        
    if arguments.directory:
        GLOBAL.directory = Path(arguments.directory.strip())
    elif "default_directory" in GLOBAL.config and GLOBAL.config["default_directory"] != "":
        GLOBAL.directory = Path(GLOBAL.config["default_directory"].format(time=GLOBAL.RUN_TIME))
    else:
        GLOBAL.directory = Path(input("\ndownload directory: ").strip())

    if arguments.downloaded_posts:
        GLOBAL.downloadedPosts = Store(arguments.downloaded_posts)
    else:
        GLOBAL.downloadedPosts = Store()

    printLogo()
    print("\n"," ".join(sys.argv),"\n",noPrint=True)

    if arguments.log is not None:
        logDir = Path(arguments.log)
        download(postFromLog(logDir))
        sys.exit()


    programMode = ProgramMode(arguments).generate()

    try:
        posts = getPosts(programMode)
    except Exception as exc:
        logging.error(sys.exc_info()[0].__name__,
                      exc_info=full_exc_info(sys.exc_info()))
        print(GLOBAL.log_stream.getvalue(),noPrint=True)
        print(exc)
        sys.exit()

    if posts is None:
        print("I could not find any posts in that URL")
        sys.exit()

    if GLOBAL.arguments.no_download: pass
    else: download(posts)