#!/usr/bin/python3

import json
import sys
from pprint import pprint
import requests
import re
import os
import shutil

location = os.path.dirname(os.path.realpath(__file__))
data_dir = os.path.join(location, "..", "data")

config_name = sys.argv[1]
items = sys.argv[2:]
config_file = os.path.join(data_dir, config_name + ".json")
print("looking for ", config_file)

with open(config_file) as data_file:
	data = json.load(data_file)

for i in items:
	base_name = os.path.basename(i)
	data_file = os.path.join(data_dir, base_name)
	if os.path.exists(data_file):
		print(i, " already exists in data dir", data_dir)
	else:
		print("copying ", i, " to ", data_dir)		       
		shutil.copy(i, data_file)
	data['tickersource'] = base_name
	r = requests.post("http://localhost:5000/backtest",
			  data)
	k = base_name.rsplit(".", 1)
	outfile = k[0] + ".html"
	print("writing to ", outfile)
	with open(outfile, 'w') as outf:
		print(r.text, file=outf)

@@ -111,16 +111,371 @@
 t shutil
+%0Aimport argparse%0A%0Aparser = argparse.ArgumentParser(description='Process backtesting')%0Aparser.add_argument('--multifile', dest='multifile',%0A%09%09    action='store_true')%0Aparser.add_argument('progname', nargs='?', default=None)%0Aparser.add_argument('config_name',nargs='?',default=None)%0Aparser.add_argument('items',nargs='*')%0A%0Aargs = parser.parse_args(sys.argv)
 %0A%0Alocati
@@ -576,55 +576,8 @@
 %22)%0A%0A
-config_name = sys.argv%5B1%5D%0Aitems = sys.argv%5B2:%5D%0A
 conf
@@ -609,16 +609,21 @@
 ta_dir, 
+args.
 config_n
@@ -749,16 +749,21 @@
 or i in 
+args.
 items:%0A%09
@@ -1137,16 +1137,37 @@
 %22.%22, 1)%0A
+%09if args.multifile:%0A%09
 %09outfile
@@ -1184,16 +1184,17 @@
 %22.html%22%0A
+%09
 %09print(%22
@@ -1216,16 +1216,17 @@
 utfile)%0A
+%09
 %09with op
@@ -1251,16 +1251,158 @@
 s outf:%0A
+%09%09%09print(r.text, file=outf)%0A%09else:%0A%09%09outfile = args.config_name + %22.html%22%0A%09%09print(%22writing to %22, outfile)%0A%09%09with open(outfile, 'a') as outf:%0A%09
 %09%09print(

add single file mode