-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
131 lines (105 loc) · 3.25 KB
/
Copy pathutils.py
File metadata and controls
131 lines (105 loc) · 3.25 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import json
import os
import datetime
import calendar
import csv
import math
def get_query_data(cursor, query_is_1):
cursor.execute(query_is_1)
result = cursor.fetchall()
return result
def save_as_csv_file(file_name, list_data):
keys = list_data[0].keys()
with open(file_name+'.csv', 'w', newline='') as output_file:
dict_writer = csv.DictWriter(output_file, keys)
dict_writer.writeheader()
dict_writer.writerows(list_data)
return True
def get_near_100(x_val):
f1_in = int(math.ceil(x_val / 100.0)) * 100
f1_d = f1_in - x_val
if f1_d > 50:
f1_in = f1_in - 100
return f1_in
from datetime import datetime as dt
from datetime import date
def compare_date(source_date, ticker):
status = False
date_holder = ticker.replace("BANKNIFTY","").replace(".NFO","").replace("CE","").replace("PE","")
date_split = source_date.split("/")
date_2 = date_holder[:2]
month_2 = get_month_name(date_holder[:7])
year_2 = (date_holder[:7])[-2:]
date_1st = date_split[1]+'/'+date_split[0]+'/'+(date_split[2])[-2:]
date_2nd = month_2+'/'+date_2+'/'+year_2
a = dt.strptime(date_2nd, "%m/%d/%y")
b = dt.strptime(date_1st, "%m/%d/%y")
days = -1
if a >= b:
d0 = date(int(date_split[2]), int(date_split[1]), int(date_split[0]))
d1 = date(int(date_split[2]), int(month_2), int(date_2))
delta = d1 - d0
days = delta.days
status = True
else:
status = False
return days
def get_month_name(date_is):
if "JAN" in str(date_is):
return "01"
elif "FEB" in str(date_is):
return "02"
elif "MAR" in str(date_is):
return "03"
elif "APR" in str(date_is):
return "04"
elif "MAY" in str(date_is):
return "05"
elif "JUN" in str(date_is):
return "06"
elif "JUL" in str(date_is):
return "07"
elif "AUG" in str(date_is):
return "08"
elif "SEP" in str(date_is):
return "09"
elif "OCT" in str(date_is):
return "10"
elif "NOV" in str(date_is):
return "11"
elif "DEC" in str(date_is):
return "12"
is_status = compare_date('01/01/2020', 'BANKNIFTY30JAN2032500CE.NFO')
def get_month(date_is):
index_val = ''
prefix = ''
sufix = ''
if len(date_is) > 0:
date_split = date_is.split("/")
index_val = date_split[1]
prefix = date_split[0]
sufix = (date_split[2])[-2:]
if str(index_val) == '01':
return prefix+"JAN"+sufix
elif str(index_val) == '02':
return prefix+"FEB"+sufix
elif str(index_val) == '03':
return prefix+"MAR"+sufix
elif str(index_val) == '04':
return prefix+"APR"+sufix
elif str(index_val) == '05':
return prefix+"MAY"+sufix
elif str(index_val) == '06':
return prefix+"JUN"+sufix
elif str(index_val) == '07':
return prefix+"JUL"+sufix
elif str(index_val) == '08':
return prefix+"AUG"+sufix
elif str(index_val) == '09':
return prefix+"SEP"+sufix
elif str(index_val) == '10':
return prefix+"OCT"+sufix
elif str(index_val) == '11':
return prefix+"NOV"+sufix
elif str(index_val) == '12':
return prefix+"DEC"+sufix