using subprocess instead of os.system

This commit is contained in:
Paweł Płazieński 2016-02-20 16:08:46 +01:00
parent 71cb0943e3
commit 383c9af291

16
napi
View file

@ -21,6 +21,7 @@ import urllib2
import xml.etree.ElementTree as ET
import base64
import subprocess
base_url = "http://napiprojekt.pl/api/api-napiprojekt3.php"
password = "iBlm8NTigvru0Jr0"
@ -56,7 +57,20 @@ def download_subtitles(digest):
input_file.write(base64.b64decode(content))
nazwa = movie_filename[:-4]+'.srt'
if (os.system("/usr/local/bin/7z x -y -so -p" + password + " " + input_filename + " 2>/dev/null >\""+nazwa+"\"")):
executed = [
'/usr/bin/7z', # executable
'x', # command: extract
'-p' + password, # use password
'-y', # assume yes on all queries
'-so', # into standard out
input_filename, # input file
]
with open(nazwa, "w") as output_file:
process = subprocess.Popen(executed, stdout=output_file)
result = process.wait()
if result != 0:
print "nie ma napisa do filmu", sys.argv[1]
os.remove(nazwa)
else: