To keep up2date with new and upcoming movies, I wrote a Python script to send me an weekly movie digest. It queries themoviedb.org and parses the "now-playing" and "upcoming pages", it creates the proper html and sends it. Putting it in a cronjob this happens weekly.

See the code here (previously I copied the code in the post, but what happens if I update it? I would push to github but would forget to update it in the post, hence a link to github only is best, with the exception of highlighting snippets in the post). This is the initial version and I might create a page to signup and let users select genres (which filter is already in), like any new books does for books. They actually inspired me to build this, their weekly new books mail is a nice service.

Note that the css styles are inside the html elements, which is not recommended for a website, but html email does not support linking to an external stylesheet, so here I didn't have a better option. Images count, so I use the bigger version, thanks to themoviedb.org's consistent url naming (replacing w92 by w185 in the poster url).

The mail code is a nice snippet I found on stackoverflow.

For DOM parsing, I highly recommend you get familiar with Beautiful Soup which makes parsing html easy and powerful.

The weekly digests are saved to sharemovies as well, see this example. See also some images below from two different mail clients.

Also note the encode/decodes that were needed, this article explains pretty well what to do when you are confronted with these annoying UnicodeDecodeError exceptions. Basically what worked for me is encoding obtained text from any websource to utf-8 when writing to a file or printing to stdout, and decoding to utf-8 when assigning it to variables.

Not much else, the rest is pretty basic Python. If you want to receive the weekly update, go to sharemovi.es and email via the Email button at the top. This homepage actually shows a subset of the upcoming and now-playing results I query with this script, however there it uses themoviedb API.

 

widget example
widget example
widget example


Bob Belderbos

I build useful apps and share my learning About me