-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchangeformat.py
More file actions
53 lines (39 loc) · 1.71 KB
/
changeformat.py
File metadata and controls
53 lines (39 loc) · 1.71 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
#call this function by py change.py datalines
import re
import sys
"""WELCOME20 current_date – 7 days Welcome offer 20
SEASONAL15 current_date – 1 days Seasonal offer 15
HAPPY30 current_date Happy hours offer 30
DHAMAKA20 current_date + 31 days Marching it offer 20"""
"""INSERT INTO coupon_details
VALUES('WELCOME20',date_sub(curdate(),interval 7 day),'Welcome offer',20);"""
datas=sys.argv[1]
values=[]
with open(datas) as f:
for data in f:
pattern=r"^([\w][\d]) current_date [-– ]* ([\d]) days ([\w ]) (\d*)$"
insertis=r"INSERT INTO coupon_details VALUES('\1',date_sub(curdate(),interval \2 day),'\3',\4),"
values.append(re.sub(pattern,insertis, data))
with open("newdata.txt", "w") as file:
for value in values:
file.write(value):
import re
import sys
"""WELCOME20 current_date – 7 days Welcome offer 20
SEASONAL15 current_date – 1 days Seasonal offer 15
HAPPY30 current_date Happy hours offer 30
DHAMAKA20 current_date + 31 days Marching it offer 20"""
"""INSERT INTO coupon_details
VALUES('WELCOME20',date_sub(curdate(),interval 7 day),'Welcome offer',20);"""
datas=sys.argv[1]
values=[]
with open(datas) as f:
for data in f:
data = data.encode("ascii", "ignore").decode()
data=re.sub('\s+',' ',data)
pattern=r"^([\w][\d]) current_date [-– ]* ([\d]) days ([\w ]) (\d*)$"
insertis=r"INSERT INTO coupon_details VALUES('\1',date_sub(curdate(),interval \2 day),'\3',\4),"
values.append(re.sub(pattern,insertis, data))
with open("newdata.txt", "w") as file:
for value in values:
file.write(value)