On Jul 02, gourgi <[EMAIL PROTECTED]> wrote:
> Hi, i hope this is the correct place to submit this
Here is perfect, thanks for the more than clear bug report.
> vdbpy_add.py : Every field in videodb is filled/updated correctly
> (including the actors) except the ratings.
Ratings are retrieved by IMDbPY, and from a fast test using my
local SQL copy of the database and both the 'http' and 'mobile'
data access systems, its value is fetched correctly and inserted
into the videoDB database.
Is it true for every movie you try to insert? Can you give me
a title (or imdbID) or two?
It's also possible that something has changed in videoDB: my local
copy can be a bit old: I'll update from the CVS later.
> ???Bug report:
[...]
> 3::Fight Club::imdb:0137523::http://akas.imdb.com/title/ttimdb:0137523/
Uhhh... funny format to save the imdb (I assume it's because videoDB
can store references from many different sources). :-)
I've fixed this one in the CVS, and I attach the new vdbpy_batch.py
to this mail.
Try it, and let me know if this fix the problem.
> Thanks for maintaining those great tools, imdbpy Rocks!!
Thanks to you for the report! I've added your name to the credits.
--
Davide Alberani <[EMAIL PROTECTED]> [PGP KeyID: 0x465BFD47]
http://erlug.linux.it/~da/
#!/usr/bin/env python
"""vdbpy_batch.py
Process a number of movies in batch.
"""
import sys, os, ConfigParser, getopt, commands
import MySQLdb
import _mysql_exceptions
import imdb
DUMP = 0
DUMP_WHERE = ''
UPDATE = 0
UPDATE_FILES = []
CONF_FILE = ''
TEST = 0
IMDB_AS = 'http'
IMDB_KWDS = {}
IMDB_PARAMS = []
help = """vdbpy_batch.py usage:
%s dump [-f conffile] [-t] [WHERE clause]
%s update [-f conffile] [-t] [-o] file1 [file2, file3, ...]
-f conffile use the conffile file.
-t test mode, do nothing.
-o override field already in the database.
""" % (sys.argv[0], sys.argv[0])
if len(sys.argv) < 2:
print help
sys.exit(1)
try:
optlist, args = getopt.getopt(sys.argv[2:], 'of:ht', ['help'])
except getopt.error, e:
print 'Troubles with arguments.'
print help
sys.exit(1)
if sys.argv[1] == 'dump':
DUMP = 1
DUMP_WHERE = ' '.join(args)
elif sys.argv[1] == 'update':
UPDATE = 1
UPDATE_FILES = args
if len(UPDATE_FILES) == 0:
print 'At least one file name required.'
sys.exit(1)
else:
print 'Must specify "dump" or "update" mode.'
print help
sys.exit(1)
for opt in optlist:
if opt[0] == '-o':
if not UPDATE:
print '-o must be used with the "update" command.'
sys.exit(1)
elif opt[0] == '-f':
if not UPDATE:
print '-f must be used with the "update" command.'
CONF_FILE = opt[1]
elif opt[0] in ('-h', '--help'):
print help
sys.exit(0)
elif opt[0] == '-t':
TEST = 1
# Read and parse the configuration file.
conffile = ConfigParser.ConfigParser()
confset = { # Parameters to connect to the database.
'db_server': '',
'db_password': '',
'db_database': '',
'db_user': '',
# If set, data from the config file override the data
# already in the database.
'override': 0}
if not CONF_FILE:
# ./vdbpyrc
CONF_FILE = ['vdbpyrc']
# /etc/vdbpyrc
CONF_FILE.append(os.path.join(os.sep, 'etc', 'vdbpyrc'))
if os.name != 'posix':
# C:\\Python24\etc\imdbpyweb.conf
CONF_FILE.append(os.path.join(sys.prefix, 'etc', 'vdbpyrc'))
# ~/.vdbpyrc
CONF_FILE.append(os.path.join(os.path.expanduser('~'), '.vdbpyrc'))
try: conffile.read(CONF_FILE)
except ConfigParser.Error, e:
print 'Unable to parse configuration file "%s".' % CONF_FILE
print str(e)
sys.exit(2)
if not conffile.has_section('config'):
print 'Section [config] not present in the configuration file.'
sys.exit(2)
for key in ('db_server', 'db_user', 'db_password', 'db_database'):
if not conffile.has_option('config', key):
print 'Required option "%s" not present in the [config] section.'
sys.exit(2)
confset[key] = conffile.get('config', key)
if not conffile.has_option('config', 'override'):
print 'Required option "override" not present in the [config] section.'
sys.exit(2)
confset['override'] = conffile.getboolean('config', 'override')
if [x for x in optlist if x[0] == '-o']: confset['override'] = 1
if conffile.has_option('config', 'imdbpy_as'):
the_as = conffile.get('config', 'imdbpy_as')
if the_as: IMDB_AS = the_as
if conffile.has_option('config', 'imdbpy_params'):
the_params = conffile.get('config', 'imdbpy_params')
if the_params:
for x in the_params.split(','):
if x.find('=') != -1:
k, v = x.split('=')
k, v = k.strip(), v.strip()
if k and v: IMDB_KWDS[k] = v
else:
x = x.strip()
if x: IMDB_PARAMS.append(x)
if DUMP:
db = MySQLdb.connect(db=confset['db_database'], host=confset['db_server'],
user=confset['db_user'], passwd=confset['db_password'],
use_unicode='latin_1')
curs = db.cursor()
try: curs.execute('SET NAMES "latin1";')
except _mysql_exceptions.MySQLError: pass
sql_query = 'SELECT id, title, imdbID from videodata'
if DUMP_WHERE: sql_query += ' WHERE %s' % DUMP_WHERE
sql_query += ';'
curs.execute(sql_query)
movies = curs.fetchall()
i = imdb.IMDb(IMDB_AS, *IMDB_PARAMS, **IMDB_KWDS)
for vid, title, imdbID in movies:
if imdbID:
imdbID = imdbID.replace('imdb:', '')
if not title:
if not imdbID:
print 'Skipping empty title (videodata.id: "%s").' % vid
continue
else: title = 'UNKNOWN TITLE'
print 'Dumping videodata.id "%s"... ' % vid,
sys.stdout.flush()
lines = []
if not imdbID:
print '(searching IMDb)... ',
sys.stdout.flush()
res = i.search_movie(title)
for r in res:
lines.append(u'%s::%s::%s::%s%s' %
(vid, r['long imdb title'], r.movieID,
i.get_imdbURL(r), os.linesep))
else:
imdbURL = u'http://akas.imdb.com/title/tt%s/' % imdbID
lines[:] = [u'%s::%s::%s::%s%s' % \
(vid, title, imdbID, imdbURL, os.linesep)]
fname = title.replace('/', '_').replace('\\', '_')
while os.path.isfile(fname): fname += '.x'
if not TEST:
f = open(fname.encode('latin_1', 'replace'), 'w')
f.writelines([l.encode('latin_1', 'replace') for l in lines])
f.close()
print 'done!'
if UPDATE:
for fname in UPDATE_FILES:
try:
fd = open(fname, 'rU')
cont = unicode(fd.readline(), 'latin_1', 'replace')
fd.close()
except IOError, e:
print 'Unable to read the "%s".' % fname
continue
cont = cont.split('::')
if len(cont) != 4:
print 'File "%s" is empty or contains wrong data.' % fname
continue
vid, title, imdbID, imdbURL = cont
cmd = 'vdbpy_add.py -f "%s" -u "%s"' % (CONF_FILE, vid)
if confset['override']:
cmd += ' -o'
if TEST:
cmd += ' -t'
cmd += ' "%s"' % imdbID
print 'running "%s"... ' % cmd,
sys.stdout.flush()
status, output = commands.getstatusoutput(cmd)
if not status: print 'done!'
else:
print 'Error %i; Output:' % status
print output
sys.exit(0)
-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
Imdbpy-devel mailing list
Imdbpy-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/imdbpy-devel