I have a batch file that calls mostly Python 2 scripts, however at the very beginning it needs to call a Python 3 script.
My Python 2 path (default, this is what is returned when I call python -V):
C:\Python27\python.exe
My Python 3 path:
C:\Users\Isaac\Anaconda3\python.exe
(The weird file structure is because I use an IDE that came with a pre-built python installation)
This is the batch file (I don't know if I actually need the timeout command or not):
for /f "tokens=2 delims=:." %%x in ('chcp') do set cp=%%x
chcp 1252>nul
start C:\Users\Isaac\Anaconda3\python.exe opennorth_downloader.py %1
timeout /t 10 /nobreak
gen_outline.py --collection objects F:\electoral_map\%1\candidates\candidates_Bloc_Québécois.json
json2csv.py F:\electoral_map\%1\candidates\candidates_Bloc_Québécois.json F:\electoral_map\%1\candidates\candidates_Bloc_Québécois.outline.json -o F:\electoral_map\%1\candidates\Bloc_Québécois.csv
del F:\electoral_map\%1\candidates\candidates_Bloc_Québécois.json
del F:\electoral_map\%1\candidates\candidates_Bloc_Québécois.outline.json
gen_outline.py --collection objects F:\electoral_map\%1\candidates\candidates_Christian_Heritage.json
json2csv.py F:\electoral_map\%1\candidates\candidates_Christian_Heritage.json F:\electoral_map\%1\candidates\candidates_Christian_Heritage.outline.json -o F:\electoral_map\%1\candidates\Christian_Heritage.csv
del F:\electoral_map\%1\candidates\candidates_Christian_Heritage.json
del F:\electoral_map\%1\candidates\candidates_Christian_Heritage.outline.json
gen_outline.py --collection objects F:\electoral_map\%1\candidates\candidates_Conservative.json
json2csv.py F:\electoral_map\%1\candidates\candidates_Conservative.json F:\electoral_map\%1\candidates\candidates_Conservative.outline.json -o F:\electoral_map\%1\candidates\Conservative.csv
del F:\electoral_map\%1\candidates\candidates_Conservative.json
del F:\electoral_map\%1\candidates\candidates_Conservative.outline.json
gen_outline.py --collection objects F:\electoral_map\%1\candidates\candidates_Forces_et_Démocratie.json
json2csv.py F:\electoral_map\%1\candidates\candidates_Forces_et_Démocratie.json F:\electoral_map\%1\candidates\candidates_Forces_et_Démocratie.outline.json -o F:\electoral_map\%1\candidates\Forces_et_Démocratie.csv
del F:\electoral_map\%1\candidates\candidates_Forces_et_Démocratie.json
del F:\electoral_map\%1\candidates\candidates_Forces_et_Démocratie.outline.json
gen_outline.py --collection objects F:\electoral_map\%1\candidates\candidates_Green_Party.json
json2csv.py F:\electoral_map\%1\candidates\candidates_Green_Party.json F:\electoral_map\%1\candidates\candidates_Green_Party.outline.json -o F:\electoral_map\%1\candidates\Green_Party.csv
del F:\electoral_map\%1\candidates\candidates_Green_Party.json
del F:\electoral_map\%1\candidates\candidates_Green_Party.outline.json
gen_outline.py --collection objects F:\electoral_map\%1\candidates\candidates_Liberal.json
json2csv.py F:\electoral_map\%1\candidates\candidates_Liberal.json F:\electoral_map\%1\candidates\candidates_Liberal.outline.json -o F:\electoral_map\%1\candidates\Liberal.csv
del F:\electoral_map\%1\candidates\candidates_Liberal.json
del F:\electoral_map\%1\candidates\candidates_Liberal.outline.json
gen_outline.py --collection objects F:\electoral_map\%1\candidates\candidates_Libertarian.json
json2csv.py F:\electoral_map\%1\candidates\candidates_Libertarian.json F:\electoral_map\%1\candidates\candidates_Libertarian.outline.json -o F:\electoral_map\%1\candidates\Libertarian.csv
del F:\electoral_map\%1\candidates\candidates_Libertarian.json
del F:\electoral_map\%1\candidates\candidates_Libertarian.outline.json
gen_outline.py --collection objects F:\electoral_map\%1\candidates\candidates_NDP.json
json2csv.py F:\electoral_map\%1\candidates\candidates_NDP.json F:\electoral_map\%1\candidates\candidates_NDP.outline.json -o F:\electoral_map\%1\candidates\NDP.csv
del F:\electoral_map\%1\candidates\candidates_NDP.json
del F:\electoral_map\%1\candidates\candidates_NDP.outline.json
chcp %cp%>nul
pause
I know that everything works except for this line:
start C:\Users\Isaac\Anaconda3\python.exe opennorth_downloader.py %1
(The batch file worked when it was run without it with what it does set up in advance)
This is the script that it references:
from sys import argv
import urllib
party_name_list = ["Conservative", "Liberal", "NDP", "Green Party", "Bloc Québécois", "Forces et Démocratie", "Libertarian", "Christian Heritage"]
for party_name in party_name_list:
with urllib.request.urlopen(r"https://represent.opennorth.ca/candidates/house-of-commons/?limit=1000&party_name={}".format(urllib.parse.quote_plus(party_name))) as url:
with open(r"F:\electoral_map\{0}\candidates\candidates_{1}.json".format(argv[1], party_name.replace(' ', '_')), "wb+") as f:
f.write(url.read())
print("finished {0}".format(party_name))
print("all done")
The batch file is called with a single argument: "20150915" which represents a date and points everything to a single folder that everything is contained within.
Can anybody see a reason why that problem line would fail? It looks like what it is supposed to be according to this