mirror of
https://source.perfectable.org/nivertius/napi.git
synced 2025-07-02 03:14:46 +02:00
moved from getopts to argparse
This commit is contained in:
parent
f090173aca
commit
9ab87b958e
1 changed files with 12 additions and 17 deletions
29
napi
29
napi
|
@ -8,31 +8,26 @@ import hashlib
|
||||||
import sys
|
import sys
|
||||||
import urllib
|
import urllib
|
||||||
import os
|
import os
|
||||||
|
import argparse
|
||||||
from xml.etree.ElementTree import XML
|
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
from xml.etree.ElementTree import XML
|
||||||
|
|
||||||
base_url = "http://napiprojekt.pl/api/api-napiprojekt3.php"
|
base_url = "http://napiprojekt.pl/api/api-napiprojekt3.php"
|
||||||
password = "iBlm8NTigvru0Jr0"
|
password = "iBlm8NTigvru0Jr0"
|
||||||
input_filename = '/tmp/napi-temp-file'
|
input_filename = '/tmp/napi-temp-file'
|
||||||
|
default_language = "PL"
|
||||||
|
|
||||||
from getopt import getopt
|
parser = argparse.ArgumentParser(description='Searches subtitles for movies from napiproject')
|
||||||
|
parser.add_argument('-l', '--language', dest='language', default=default_language,
|
||||||
|
help='requested subtitle language')
|
||||||
|
parser.add_argument('movies', metavar='movie', nargs='+',
|
||||||
|
help='movie for which to find subtitles')
|
||||||
|
|
||||||
opts, args = getopt(sys.argv[1:], '', ['language='])
|
args = parser.parse_args()
|
||||||
|
|
||||||
language = "PL"
|
for movie_filename in args.movies:
|
||||||
|
|
||||||
for optname, optvalue in opts:
|
|
||||||
if optname == '--language':
|
|
||||||
language = optvalue
|
|
||||||
|
|
||||||
if len(args) < 1:
|
|
||||||
print "usage: %s <movie>" % (sys.argv[0],)
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
for movie_filename in args:
|
|
||||||
|
|
||||||
digest = hashlib.md5()
|
digest = hashlib.md5()
|
||||||
try:
|
try:
|
||||||
|
@ -48,7 +43,7 @@ for movie_filename in args:
|
||||||
"downloaded_subtitles_id" : movie_digest,
|
"downloaded_subtitles_id" : movie_digest,
|
||||||
"mode" : "31",
|
"mode" : "31",
|
||||||
"client" : "NapiProjekt",
|
"client" : "NapiProjekt",
|
||||||
"downloaded_subtitles_lang" : language
|
"downloaded_subtitles_lang" : args.language
|
||||||
}
|
}
|
||||||
|
|
||||||
request_data = urllib.urlencode(request_data)
|
request_data = urllib.urlencode(request_data)
|
||||||
|
|
Loading…
Add table
Reference in a new issue