Exemple #1
0
def run():
    try:
        config.init_config()
        # blacklist the current wallpaper if requested
        if config.blacklistcurrent:
            reddit.blacklist_current()
        # check if the program is run in a special case (save or startup)
        if config.save:
            wallpaper.save_wallpaper()
            sys.exit(0)
        if config.startup:
            connection.wait_for_connection(config.startupattempts, config.startupinterval)
        # make sure you're actually connected to reddit
        if not connection.connected("http://www.reddit.com"):
            print("ERROR: You do not appear to be connected to Reddit. Exiting")
            sys.exit(1)
        links = reddit.get_links()
        titles = links[1]
        valid = reddit.choose_valid(links[0])
        valid_url = valid[0]
        title = titles[valid[1]]
        download.download_image(valid_url, title)
        download.save_info(valid_url, title)
        wallpaper.set_wallpaper()
        external_script()
    except KeyboardInterrupt:
        sys.exit(1)
Exemple #2
0
def choose_valid(links):
    if len(links) == 0:
        print("No links were returned from any of those subreddits. Are they valid?")
        sys.exit(1)
    for i, origlink in enumerate(links):
        link = origlink[0]
        config.log("checking link # {0}: {1}".format(i, link))
        if not (link[-4:] == '.png' or link[-4:] == '.jpg' or link[-5:] == '.jpeg'):
            if re.search('(imgur\.com)(?!/a/)', link):
                link = link.replace("/gallery", "")
                link += ".jpg"
            else:
                continue
        if not (connection.connected(link) and check_dimensions(link) and check_blocklist(link)):
            continue

        def check_same_url(link):
            with open(config.walldir + '/url.txt', 'r') as f:
                currlink = f.read()
                if currlink == link:
                    print("current wallpaper is the most recent, will not re-download the same wallpaper.")
                    sys.exit(0)
                else:
                    return True

        if config.force_dl or not (os.path.isfile(config.walldir + '/url.txt')) or check_same_url(link):
            return [link, origlink[1], origlink[2]]
    print("No valid links were found from any of those subreddits.  Try increasing the maxlink parameter.")
    sys.exit(0)
Exemple #3
0
def choose_valid(links):
    if len(links) == 0:
        print("No links were returned from any of those subreddits. Are they valid?")
        sys.exit(1)
    for i, origlink in enumerate(links):
        link = origlink[0]
        config.log("checking link # {0}: {1}".format(i, link))
        if not (link[-4:] == '.png' or link[-4:] == '.jpg' or link[-5:] == '.jpeg'):
            if re.search('(imgur\.com)(?!/a/)', link):
                link = link.replace("/gallery", "")
                link += ".jpg"
            else:
                continue
        if not (connection.connected(link) and check_dimensions(link) and check_blacklist(link)):
            continue

        def check_same_url(link):
            with open(config.walldir + '/url.txt', 'r') as f:
                currlink = f.read()
                if currlink == link:
                    print("current wallpaper is the most recent, will not re-download the same wallpaper.")
                    sys.exit(0)
                else:
                    return True

        if config.force_dl or not (os.path.isfile(config.walldir + '/url.txt')) or check_same_url(link):
            return [link, origlink[1], origlink[2]]
    print("No valid links were found from any of those subreddits.  Try increasing the maxlink parameter.")
    sys.exit(0)
Exemple #4
0
def run():
    try:
        config.init_config()
        # blacklist the current wallpaper if requested
        if config.blacklistcurrent:
            reddit.blacklist_current()
        # check if the program is run in a special case (save or startup)
        if config.save:
            wallpaper.save_wallpaper()
            sys.exit(0)
        if config.autostartup:
            if config.opsys == "Linux":
                dfile = resource_string(__name__,
                                        'conf_files/linux-autostart.desktop')
                path = os.path.expanduser("~/.config") + "/autostart"
                if not os.path.exists(path):
                    os.makedirs(path)
                    config.log(path + " created")
                with open(path + "/wallpaper-reddit.desktop", "wb") as f:
                    f.write(dfile)
                print("Autostart file created at " + path)
                sys.exit(0)
            else:
                print(
                    "Automatic startup creation only currently supported on Linux"
                )
                sys.exit(1)
        if config.startup:
            connection.wait_for_connection(config.startupattempts,
                                           config.startupinterval)
        # make sure you're actually connected to reddit
        if not connection.connected("http://www.reddit.com"):
            print(
                "ERROR: You do not appear to be connected to Reddit. Exiting")
            sys.exit(1)
        links = reddit.get_links()
        titles = links[1]
        permalinks = links[2]
        valid = reddit.choose_valid(links[0])
        valid_url = valid[0]
        title = titles[valid[1]]
        permalink = permalinks[valid[1]]
        download.download_image(valid_url, title)
        download.save_info(valid_url, title, permalink)
        wallpaper.set_wallpaper()
        external_script()
    except KeyboardInterrupt:
        sys.exit(1)
Exemple #5
0
def run():
    try:
        config.init_config()
        # blacklist the current wallpaper if requested
        if config.blacklistcurrent:
            reddit.blacklist_current()
        # check if the program is run in a special case (save or startup)
        if config.save:
            wallpaper.save_wallpaper()
            sys.exit(0)
        if config.autostartup:
            if config.opsys == "Linux":
                dfile = resource_string(__name__, 'conf_files/linux-autostart.desktop')
                path = os.path.expanduser("~/.config") + "/autostart"
                if not os.path.exists(path):
                    os.makedirs(path)
                    config.log(path + " created")
                with open(path + "/wallpaper-reddit.desktop", "wb") as f:
                    f.write(dfile)
                print("Autostart file created at " + path)
                sys.exit(0)
            else:
                print("Automatic startup creation only currently supported on Linux")
                sys.exit(1)
        if config.startup:
            connection.wait_for_connection(config.startupattempts, config.startupinterval)
        # make sure you're actually connected to reddit
        if not connection.connected("http://www.reddit.com"):
            print("ERROR: You do not appear to be connected to Reddit. Exiting")
            sys.exit(1)
        links = reddit.get_links()
        if (config.lottery == True):
            random.shuffle(links)
        valid = reddit.choose_valid(links)
        download.download_image(valid[0], valid[1])
        download.save_info(valid)
        wallpaper.set_wallpaper()
        external_script()
    except KeyboardInterrupt:
        sys.exit(1)