diff --git a/qhp-download.py b/qhp-download.py index d794f37..83c789f 100644 --- a/qhp-download.py +++ b/qhp-download.py @@ -72,6 +72,7 @@ def main(): parser.add_argument('-f', '--from', action='store', dest='from_', help='Starting date', required=True) parser.add_argument('-t', '--to', action='store', dest='to', help='Ending date', required=True) parser.add_argument('-r', '--rescale', action='store', dest='rescale', help='Rescale to timeframe') + parser.add_argument('-d', '--time-delta', action='store', dest='time_delta', help='Add given time delta (in seconds)', required=False) args = parser.parse_args() @@ -86,6 +87,10 @@ def main(): start_time = datetime.datetime.strptime(args.from_, "%Y%m%d") end_time = datetime.datetime.strptime(args.to, "%Y%m%d") + timedelta = datetime.timedelta() + if args.time_delta: + timedelta = datetime.timedelta(seconds=int(args.time_delta)) + rq = { "ticker" : symbol, "from" : start_time.strftime("%Y-%m-%dT%H:%M:%S"), @@ -96,11 +101,14 @@ def main(): s.send_multipart([bytes(json.dumps(rq), "utf-8")]) parts = s.recv_multipart() + if parts[0] != b'OK': + print("Error:", parts[1]) + line_count = 0 - with open(args.output_file, 'w') as f: + with open(args.output_file, 'w', newline='') as f: writer = csv.writer(f) writer.writerow(['', '', '', '