Giter Site home page Giter Site logo

alanhussey / golden-hour Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rush340/golden-hour

23.0 8.0 11.0 30 KB

Record a sunset timelapse and post it to twitter with the weather report

Home Page: https://twitter.com/goldenhourSEA

Python 100.00%

golden-hour's Introduction

golden-hour

A python script to generate a timelapse video. Designed specifically to record at sunset, and post to twitter with a weather report.

Setup

This project assumes that you will run this on a Raspberry Pi with a CSI-port camera, although pull requests to broaden that support are certainly accepted. @goldenhourSEA runs on a Pi 3 Model B with the Camera Module V2.

Installation

Installing FFmpeg

FFmpeg is used to convert the sequence of photos captured by the camera into a video suitable for uploading to Twitter. FFmpeg must be compiled with x264 support. On a Raspberry Pi running Raspbian, simply sudo apt install ffmpeg. If you are running this on a Mac, brew install ffpmeg should be sufficient.

Installing golden-hour

  1. Check out this repo to a convenient location on your Pi.
  2. Run pip install .
  3. Run golden-hour --help to check that it's hooked up right!

Configuration

Configuration data - Twitter and Dark Sky credentials, and location information, will all live in a .yaml file. You can put this wherever you want but we recommend ~/.config/golden-hour.yaml. Check out example_config.yaml for the expected format of the file.

Location

So that golden-hour knows when sunset will happen, tell it where the camera is located via the configuration file. For many major cities, you can just specify the city name. See example_config.yaml for the format.

Twitter
  1. Create a Twitter account.
    • I recommend a name like "goldenhourXYZ", where XYZ is airport code or abbrevation for your city.
    • You may want to associate the account with a phone number, to avoid Twitter's anti-spam measures.
  2. Create a Twitter "app" for that account.
    • Make sure to set the access permissions to "Read and write", otherwise you won't be able to post tweets.
    • In the root of the repo, create a twitter_secrets.yaml file, and put the consumer key, consumer secret, access token, and access token secret in there:
Dark Sky (optional)

If you want the weather report, get a Dark Sky API key.

Running as a one-off

Once it's installed, run golden-hour --help for usage instructions. If you get the error "-bash: golden-hour: command not found", you may need to restart your shell or check that golden-hour is installed somewhere on your PATH. See "Gotchas" below.

Running automatically

Once you have everything set up, set up a cron job to run golden-hour at the same time every day. Make sure it runs at least one hour before the earliest sunset of the year. You can find this by looking at the "Sun Graph" for your city at timeanddate.com (for example, here is Seattle).

Example crontab entry (Insert this into your user's crontab with crontab -e):

0 15 * * *  golden-hour --start-before-sunset 60  --post-to-twitter

For another example, which uses a specially crafted .sh file and a virtualenv, check out alanhussey's setup . Note that this may be out of date from the latest version of code in this repo.

Where are the logs?

When it is run by cron, by default golden-hour will send logs to syslog. You can monitor them with tail -F /var/log/syslog.

Gotchas:
  • depending on how you installed golden-hour, you will need to make sure that it's on your PATH. This may mean adding something like PATH=~/.local/bin:/usr/local/bin:$PATH to your crontab and your ~/.bash_profile, or activating a virtualenv.
  • cron runs in a different environment from your normal shell. In my case, it did not have access to ffmpeg, because I had installed it to /usr/local/bin, but the $PATH only had /bin and /usr/bin.
  • Your Pi may not be configured to your local timezone. Run date to see what time it is for your Pi, and set the cron job to run at an appropriate translated time. I set mine to run at 2300, which is 3pm local time.

golden-hour's People

Contributors

alanhussey avatar rush340 avatar thatneat avatar

Stargazers

JbLb avatar  avatar Masters avatar Kyle Prins avatar  avatar  avatar  avatar Raffaele avatar Patrick O'Keeffe avatar Duncan M avatar Winston Hughes avatar  avatar Mike Kelly avatar Logan Sims avatar George Boomer III avatar Dan O'Brien avatar Adner V avatar Al Miller avatar Steve Schenk avatar Brandon West avatar Matt Scott avatar Daniel Schep avatar Chad Chabot avatar

Watchers

 avatar Dan O'Brien avatar Al Miller avatar  avatar  avatar  avatar  avatar  avatar

golden-hour's Issues

Make the camera configurable

Right now this is hard-coded to use either the Raspberry Pi camera module on linux, or the FaceTime camera on macOS.

Twitter upload sometimes fails

I'm occasionally getting this error:

Traceback (most recent call last):
  File "/home/pi/.local/bin/golden-hour", line 11, in <module>
    load_entry_point('golden-hour', 'console_scripts', 'golden-hour')()
  File "/home/pi/golden-hour/golden_hour/main.py", line 138, in main
    media=timelapse_filename
  File "/home/pi/golden-hour/golden_hour/tweet.py", line 38, in post_update
    media_id = api.UploadMediaChunked(mediafile)
  File "/home/pi/.local/lib/python3.7/site-packages/twitter/api.py", line 1420, in UploadMediaChunked
    filename=filename)
  File "/home/pi/.local/lib/python3.7/site-packages/twitter/api.py", line 1353, in _UploadMediaChunkedAppend
    data=body_data)
  File "/home/pi/.local/lib/python3.7/site-packages/twitter/api.py", line 4919, in _RequestChunkedUpload
    raise TwitterError(str(e))
twitter.error.TwitterError: ('Connection aborted.', BrokenPipeError(32, 'Broken pipe'))

Presumably this just happens because some kind of hiccup occurs during the long-ish process of uploading the video. Maybe we should add a retry, perhaps using backoff?

Clean up tmp files

Make sure to delete the timelapse photos and the completed video after a successful upload.

Recommended cron job configuration

The --start-before-sunset flag is designed to allow golden-hour to be started at an arbitrary time before sunset. Document this, and recommend how to set up a cron job.

A better way to set configuration

#1 and #6 make this more important. Ideally we could expect a .golden-hour config directory in the user's home directory, which would contain twitter auth secrets, location config, the weather report template, etcetera.

Turn this into a proper installable package

Right now "installation" means checking out this repo and building a functional virtualenv by hand. It'd be nice if that wasn't needed.

Ideally, installation* would be a single command (with pipsi?), and would expose this functionality as a console script.

* ffmpeg is a separate issue

Make location configurable

A few places have Seattle hard-coded. Making this configurable will make it easier to run golden-hour in other locations.

Support sunrise

Some people are blessed with beautiful sunrises. Make it easier for them to record sunrise timelapses.

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.