Skip to content

Instantly share code, notes, and snippets.

@petersendidit
Forked from philgruneich/movieDiary.py
Created June 24, 2014 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petersendidit/465ad3e19a3fc7732c9a to your computer and use it in GitHub Desktop.
Save petersendidit/465ad3e19a3fc7732c9a to your computer and use it in GitHub Desktop.
#coding: utf-8
import requests
import urllib
import json
import re
import sys
import webbrowser
movie = urllib.quote(sys.argv[1])
dayone = 'dayone://post?entry='
r = requests.get('http://www.imdb.com/xml/find?json=1&nr=1&tt=on&q=%s' % movie).text
t = json.loads(r)
try:
pop = t['title_popular'] + t['title_exact']
except:
try:
pop = t['title_popular']
except:
pop = t['title_exact']
films = {}
for film in pop:
title = film['title']
description = re.match("(^\d{4}).*<a href='/name/nm\d+/'>(.*)</a>", film['description'])
if description:
year = description.group(1)
director = description.group(2)
the_string = '%s (%s, %s)' % (title, year, director)
films[the_string] = {'Title': title, 'Year': year, 'Director': director}
if len(films.keys()) == 1:
for film in films.keys():
dayone+='{{'
dayone+="|{0}||\n|:---:|---:|\n|{1}|{2}|\n|".format(films[film]['Title'], films[film]['Director'], films[film]['Year'])
dayone+="[list:What's the rating?|★ ★ ★ ★ ★|★ ★ ★ ★|★ ★ ★|★ ★=|★]||\n#Movies"
dayone+='}}'
else:
dayone+='[list:What\'s the movie?'
for film in films.keys():
dayone+='|{0}={{{{|{1}||\n|:---:|---:|\n|{2}|{3}|\n}}}}'.format(film, films[film]['Title'], films[film]['Director'], films[film]['Year'])
dayone+="]{{|[list:What's the rating?|★ ★ ★ ★ ★|★ ★ ★ ★|★ ★ ★|★ ★|★]||\n#Movies}}"
the_url = 'launchpro://?url=' + urllib.quote(dayone)
webbrowser.open(the_url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment