summaryrefslogtreecommitdiffstats
path: root/Imdb.py
blob: 25df175678cec0048a7b1a0067c6f3257f5b8d39 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-

from urllib2 import urlopen
from json import loads
from urllib import quote_plus
from re import findall

def titleCode(title):
	try:
		html = urlopen("http://www.imdb.com/find?s=tt&q=" + quote_plus(title)).read()
	except:
		return ""
	titleCodes = findall("/title/tt([0-9]{7})/", html)
	if len(titleCodes) > 0:
		return titleCodes[0]
	else:
		return ""