forked from philipperemy/FX-1-Minute-Data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert_est_to_target_time.py
More file actions
26 lines (24 loc) · 973 Bytes
/
Copy pathconvert_est_to_target_time.py
File metadata and controls
26 lines (24 loc) · 973 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import csv
import os
import sys
from datetime import datetime
from datetime import timedelta
if __name__ == '__main__':
args = sys.argv
if len(args) != 3:
print('Usage: {0} <filename> <time zone difference>\n' \
'Example: {0} DAT_ASCII_EURJPY_M1_201705.csv +13'.format(args[0].split(os.sep)[-1]))
else:
time_zone_difference = int(args[2])
input_filename = args[1]
output_filename = 'OUT_' + input_filename
with open(output_filename, 'w') as w:
with open(input_filename, 'r') as r:
reader = csv.reader(r, delimiter=';')
for row in reader:
print(row)
new_row = list(row)
ts = datetime.strptime(new_row[0], '%Y%m%d %H%M%S')
ts += timedelta(hours=time_zone_difference)
new_row[0] = ts.strftime('%Y%m%d %H%M%S')
w.write(';'.join(new_row) + '\n')