35
35
36
36
test_list = [i for i in test_list1 if i != '\n ' ]
37
37
38
- todayDate = "11/February/2020\n "
38
+ # todayDate = "11/February/2020\n"
39
39
40
40
dateObj = date .today ()
41
41
@@ -77,11 +77,11 @@ def connectToDB():
77
77
password = 'root' )
78
78
if connection .is_connected ():
79
79
db_Info = connection .get_server_info ()
80
- print ("Connected to MySQL Server version " , db_Info )
80
+ print ("\n Connected to MySQL Server version " , db_Info )
81
81
cursor = connection .cursor ()
82
82
cursor .execute ("select database();" )
83
83
record = cursor .fetchone ()
84
- print ("You 're connected to database: " , record )
84
+ print ("\n You 're connected to database: " , record )
85
85
return connection
86
86
except Error as e :
87
87
print ("Error while connecting to MySQL" , e )
@@ -100,43 +100,40 @@ def insertRecord(con):
100
100
# Check current time, act accordingly.
101
101
curremtTime = datetime .now ()
102
102
curremtTime = curremtTime .strftime ("%H:%M" )
103
- print (curremtTime )
104
103
105
- if (curremtTime == "12:34 " ):
104
+ if (curremtTime == "12:10 " ):
106
105
infoSource = "Scheduled Job"
107
106
else :
108
107
infoSource = "Manual Trigger"
109
108
110
- workingQuery = "INSERT INTO `world`.`daily_gold_rates` (`todays_date`, `twentyFour_carot_eight_grams`,`twentyFour_carot_one_gram`, `twentyTwo_carot_eight_grams`, `twentyTwo_carot_one_gram`, `info_source` ) VALUES ('" + str (todaysDateFormatToDB ) + "','" + gold_rate ['24K' ]['8g' ] + "'," + "'" + gold_rate ['24K' ]['1g' ]+ "'," + "'" + gold_rate ['22K' ]['8g' ] + "'," + "'" + gold_rate ['22K' ]['1g' ] + "','" + infoSource + "');"
111
-
112
- print (workingQuery )
109
+ workingQuery = "INSERT INTO `world`.`daily_gold_rates` (`todays_date`, `twentyFour_carot_eight_grams`,`twentyFour_carot_one_gram`, `twentyTwo_carot_eight_grams`, `twentyTwo_carot_one_gram`, `info_source`, `info_landed_time` ) VALUES ('" + str (todaysDateFormatToDB ) + "','" + gold_rate ['24K' ]['8g' ] + "'," + "'" + gold_rate ['24K' ]['1g' ]+ "'," + "'" + gold_rate ['22K' ]['8g' ] + "'," + "'" + gold_rate ['22K' ]['1g' ] + "','" + infoSource + "'," + "'" + curremtTime + "');"
113
110
114
111
#something3 = "INSERT INTO `world`.`daily_gold_rates` (`todays_date`,`twentyFour_carot_eight_grams`,`twentyFour_carot_one_gram`,`twentyTwo_carot_eight_grams`,`twentyTwo_carot_one_gram`) VALUES (" + "'" + sample[0] +"'," + "'" + sample[1] + "','" + sample[2] + "','" + sample[3] +"','" + sample[4] +"');"
115
112
cursor = con .cursor ()
116
113
cursor .execute (workingQuery )
117
114
con .commit ()
118
- print (cursor .rowcount , "Record inserted successfully into Laptop table" )
115
+ print (" \n " , cursor .rowcount , "Record inserted successfully into Gold Rate table" )
119
116
return True
120
117
121
118
def disconnectDB (con ):
122
119
if (con .is_connected ()):
123
120
con .close ()
124
- print ("MySQL connection is closed" )
121
+ print ("MySQL connection is closed\n " )
125
122
else :
126
- print ("We tried, but it seems your connection is in active state! However it must be already closed." )
123
+ print ("We tried, but it seems your connection is in active state! However it must be already closed.\n " )
127
124
128
- print ("Connecting to your database.." )
125
+ print ("\n Connecting to your database..\n " )
129
126
time .sleep (5 )
130
127
connectionHook = connectToDB ()
131
- print ("collecting records to save.." )
128
+ print ("\n collecting records to save..\n " )
132
129
time .sleep (3 )
133
130
insertData = insertRecord (connectionHook )
134
- print ("Records are inserted in DB, can be used for Analytics purpose in future!" )
131
+ print ("\n Records are inserted in DB, can be used for Analytics purpose in future!\n " )
135
132
time .sleep (5 )
136
133
137
134
diconnect = disconnectDB (connectionHook )
138
135
139
136
time .sleep (10 )
140
- print ("Good Bye!" )
137
+ print ("\n Good Bye!" )
141
138
142
139
time .sleep (3 )
0 commit comments