Skip to content

Commit 8db006f

Browse files
committed
- Tuple of Column names for csv file and table are now centralised
1 parent 763c4ad commit 8db006f

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

NSE_Option_Chain_Analyzer.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ def __init__(self, window: Tk) -> None:
3535
self.log() if self.logging else None
3636
self.dates: List[str] = [""]
3737
self.indices: List[str] = ["NIFTY", "BANKNIFTY", "FINNIFTY"]
38+
self.output_columns: Tuple[str, str, str, str, str, str, str, str, str] = (
39+
'Time', 'Value', 'Call Sum\n(in K)', 'Put Sum\n(in K)', 'Difference\n(in K)', 'Call Boundary\n(in K)',
40+
'Put Boundary\n(in K)', 'Call ITM', 'Put ITM')
41+
self.csv_headers: Tuple[str, str, str, str, str, str, str, str, str] = (
42+
'Time', 'Value', 'Call Sum (in K)', 'Put Sum (in K)', 'Difference (in K)',
43+
'Call Boundary (in K)', 'Put Boundary (in K)', 'Call ITM', 'Put ITM')
3844
self.headers: Dict[str, str] = {
3945
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, '
4046
'like Gecko) '
@@ -335,9 +341,7 @@ def export(self, event: Optional[Event] = None) -> None:
335341
if not csv_exists:
336342
with open(f"NSE-OCA-{self.index}-{self.expiry_date}.csv", "a", newline="") as row:
337343
data_writer: csv.writer = csv.writer(row)
338-
data_writer.writerow((
339-
'Time', 'Value', 'Call Sum (in K)', 'Put Sum (in K)', 'Difference (in K)',
340-
'Call Boundary (in K)', 'Put Boundary (in K)', 'Call ITM', 'Put ITM'))
344+
data_writer.writerow(self.csv_headers)
341345

342346
with open(f"NSE-OCA-{self.index}-{self.expiry_date}.csv", "a", newline="") as row:
343347
data_writer: csv.writer = csv.writer(row)
@@ -357,9 +361,7 @@ def export_row(self, values: Optional[List[Union[str, float, numpy.float64]]]) -
357361
if not csv_exists:
358362
with open(f"NSE-OCA-{self.index}-{self.expiry_date}.csv", "a", newline="") as row:
359363
data_writer: csv.writer = csv.writer(row)
360-
data_writer.writerow((
361-
'Time', 'Value', 'Call Sum (in K)', 'Put Sum (in K)', 'Difference (in K)',
362-
'Call Boundary (in K)', 'Put Boundary (in K)', 'Call ITM', 'Put ITM'))
364+
data_writer.writerow(self.csv_headers)
363365
except Exception as err:
364366
print(err, "9")
365367
else:
@@ -625,12 +627,9 @@ def main_win(self) -> None:
625627
top_frame.columnconfigure(0, weight=1)
626628
top_frame.pack(fill="both", expand=True)
627629

628-
output_columns: Tuple[str, str, str, str, str, str, str, str, str] = (
629-
'Time', 'Value', 'Call Sum\n(in K)', 'Put Sum\n(in K)', 'Difference\n(in K)', 'Call Boundary\n(in K)',
630-
'Put Boundary\n(in K)', 'Call ITM', 'Put ITM')
631-
self.sheet: tksheet.Sheet = tksheet.Sheet(top_frame, column_width=85, align="center", headers=output_columns,
632-
header_font=("TkDefaultFont", 9, "bold"), empty_horizontal=0,
633-
empty_vertical=20, header_height=35)
630+
self.sheet: tksheet.Sheet = tksheet.Sheet(top_frame, column_width=85, align="center",
631+
headers=self.output_columns, header_font=("TkDefaultFont", 9, "bold"),
632+
empty_horizontal=0, empty_vertical=20, header_height=35)
634633
self.sheet.enable_bindings(
635634
("toggle_select", "drag_select", "column_select", "row_select", "column_width_resize",
636635
"arrowkeys", "right_click_popup_menu", "rc_select", "copy", "select_all"))

0 commit comments

Comments
 (0)