Coder Social home page Coder Social logo

santiagotorres / bg_daemon Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 2.0 101 KB

An extensible python set of classes to update your background images.

License: GNU General Public License v2.0

Python 95.07% Makefile 0.46% Shell 0.91% Objective-C 3.55%

bg_daemon's Introduction

bg_daemon

An extensible python set of classes to update your background images.

Build Status Coverage Status

Consider that this is not fully tested yet, if you encounter anything unexpected please let me know

Installation

Right now, you can simply run

$ sudo ./setup.py install

Once the installation is done, you must add a cronjob. As of this time, I'm working in an out of the box way to add a cronjob, in the meantime, you can do the following from a python shell:

>>> import bg_daemon.util
>>> bg_daemon.util.add_crontab_entry()

That's it, now it's installed.

Configuration

The very first time that "background_daemon.py" is called, it creates a directory in your home called ".bg_daemon". Inside it, you will find the settings.json file. You can edit this file to modify the behavior of the daemon.

Setting up the fetcher

A fetcher is the module that's in charge of getting images from god knows where and hand them to the polling daemon.

Right now, the only available fetcher is the imgur.com fetcher, so I will describe it here.

Mode

Right now, the fetcher supports two "modes":

  • "recent" (default): that fetches the latest image in a random subreddit
  • "keywords": creates a random query from a list of keywords and a random subreddit

By setting the "mode" value here, you modify how the fetcher downloads images from imgur.

Keywords

If you use the keywords mode, you can populate this list (see the example file), with words that interest you to build queries.

Subreddits

You can populate this list with subreddits of interest, earthporn is a great choice. Keep in mind that not all files are hosted in imgur, so they will not be available (until someone writes a fetcher for that).

min_width, min_height

You can set a minimum size constraint so the images have a proper resolution.

blacklist_words

You can set a list of values that you do not want to appear in the title, or description of the image. Imgur can host some really nasty things, so this seems to be a required feature.

nsfw

By default, files marked as nsfw are ignored, but you can change this by setting nsfw:True in settings.json

Setting up the daemon

Choosing a fetcher

The fetcher is dynamically loaded here, a string identifying the fetcher is supplied to choose it. "imgurfetcher" is the only available option as of now.

Frequency

Here you define the time, in seconds, before changing the image. It defaults to a minute, but it's a better idea to put it to, say, 3600 so it changes every hour.

Retries and slack

It is possible that sometimes the fetcher fails (e.g., a 404, server is overloaded, you lost connection, etc.), instead of failing silently, the daemon can wait "slack" amount of time and retry up to "retries" times.

You can set slack to a low number to make it wait less between retries and increase the number of retries if needed. I'd advise you to leave it in the default values.

Target

In simple words, where do you want to save this. It defaults to $HOME/.bg_daemon/bg.jpg

Backup

If backup is "yes", then the daemon will backup the last image if there is any. it will save the image in the same folder as the target and add a "hashed-prefix" to the filename to uniquely identify each image.

In other words, it moves the old image to a new location before writing the new one.

Update_hook

In order to change the background you might need to call a command that updates the background with the new image. I personally use 'feh' in linux, so you can use it also.

If you are using this on a mac, you should change this

Env

The environment variables for the update_hook. I wouldn't touch them unless the system isn't working.

bg_daemon's People

Contributors

eldeveloper avatar santiagotorres avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

bg_daemon's Issues

One of the dependencies is breaking the build

This is the list of dependencies we had installed when everything worked:

imgurpython==1.1.5
mock==1.0.1
requests==2.6.0
virtualenv==12.1.1

This is our new list of dependencies:

imgurpython==1.1.6
mock==1.3.0
requests==2.7.0
virtualenv==13.1.2

I'm imagining mock isn't behaving as it should anymore.... I'll dig into this.

imgurfetcher doesn't do well with albums.

I tried changing the name of the subreddit to spaceporn and the following exception showed up:

yoshikivazquezbaeza:~$ background_daemon.py 
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/bin/background_daemon.py", line 4, in <module>
    __import__('pkg_resources').run_script('bg-daemon==0.0.1', 'background_daemon.py')
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pkg_resources.py", line 517, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pkg_resources.py", line 1443, in run_script
    exec(script_code, namespace, namespace)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/bg_daemon-0.0.1-py2.7.egg/EGG-INFO/scripts/background_daemon.py", line 240, in <module>

  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/bg_daemon-0.0.1-py2.7.egg/EGG-INFO/scripts/background_daemon.py", line 196, in poll

  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/bg_daemon-0.0.1-py2.7.egg/EGG-INFO/scripts/background_daemon.py", line 128, in update

  File "build/bdist.macosx-10.6-intel/egg/bg_daemon/fetchers/imgurfetcher.py", line 131, in query
  File "build/bdist.macosx-10.6-intel/egg/bg_daemon/fetchers/imgurfetcher.py", line 233, in _select_image
AttributeError: GalleryAlbum instance has no attribute 'width'

This may be a shot in the dark, but I think fetcher needs to verify that it is indeed looking at an image not an album.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.