summaryrefslogtreecommitdiff
path: root/anidb_add
diff options
context:
space:
mode:
authorzyp <zyp@localhost>2006-05-17 01:21:27 +0200
committerzyp <zyp@localhost>2006-05-17 01:21:27 +0200
commita2ebd9bca9c4077dc6642c29d4e6f2d7107c0c24 (patch)
tree43f990d5b73fded2d37159a8e18a8ae4c9c09840 /anidb_add
parent8e9e23cddd72d2dd407164f8a7e835fa6c84b4d2 (diff)
[project @ zyp-20060516232127-1ed2efc46068ab87]
[project @ 33] Added optionparser.
Diffstat (limited to 'anidb_add')
-rw-r--r--anidb_add63
1 files changed, 0 insertions, 63 deletions
diff --git a/anidb_add b/anidb_add
deleted file mode 100644
index b0d06bd..0000000
--- a/anidb_add
+++ /dev/null
@@ -1,63 +0,0 @@
-#!/usr/bin/env python
-
-import pyanidb, pyanidb.hash
-import ConfigParser, os, sys, getpass, multihash
-
-def auth():
- try:
- c = ConfigParser.ConfigParser()
- c.read(os.path.expanduser('~/.pyanidb.conf'))
- username = c.get('auth', 'username')
- password = c.get('auth', 'password')
- except:
- username = raw_input('Username: ')
- password = getpass.getpass()
- return username, password
-
-username, password = auth()
-
-try:
- a = pyanidb.AniDB(username, password)
- #t = a.ping()
- #if t:
- # print 'AniDB is reachable, %.3fs' % (t)
- #else:
- # print 'AniDB is unreachable.'
- # sys.exit(1)
- a.auth()
- print 'Logged in as user %s.' % (username)
- if a.new_version:
- print 'New version available.'
-
- files = []
- for name in sys.argv[1:]:
- if os.access(name, os.R_OK):
- files.append(name)
- else:
- print 'Invalid file: %s' % (name)
- for filename, hash in pyanidb.hash.hash_files(files):
- hash = hash.ed2k()
- size = os.stat(filename).st_size
- print 'Hashed: ed2k://|file|%s|%d|%s|' % (filename, size, hash)
- try:
- while 1:
- try:
- a.add_hash(size, hash)
- except pyanidb.AniDBTimeout:
- print 'Connection timed out, retrying.'
- continue
- break
- except pyanidb.AniDBUnknownFile:
- print 'Unknown file: %s' % (filename)
- continue
- print 'Added file: %s' % (filename)
- print 'All operations finished.'
-except pyanidb.AniDBUserError:
- print 'Invalid username/password.'
- sys.exit(1)
-except pyanidb.AniDBTimeout:
- print 'Connection timed out.'
- sys.exit(1)
-except pyanidb.AniDBError, e:
- print 'Fatal error:', e
- sys.exit(1)