Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0a59e70

Browse files
Todo - Task 1 - Completed
Addition of new colu,m in existing table. Inserting the time info during execution
1 parent fa401c0 commit 0a59e70

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

‎Excersise/GoldRate/HelloWorld.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
test_list = [i for i in test_list1 if i != '\n']
3737

38-
todayDate = "11/February/2020\n"
38+
#todayDate = "11/February/2020\n"
3939

4040
dateObj = date.today()
4141

@@ -77,11 +77,11 @@ def connectToDB():
7777
password='root')
7878
if connection.is_connected():
7979
db_Info = connection.get_server_info()
80-
print("Connected to MySQL Server version ", db_Info)
80+
print("\nConnected to MySQL Server version ", db_Info)
8181
cursor = connection.cursor()
8282
cursor.execute("select database();")
8383
record = cursor.fetchone()
84-
print("You're connected to database: ", record)
84+
print("\nYou're connected to database: ", record)
8585
return connection
8686
except Error as e:
8787
print("Error while connecting to MySQL", e)
@@ -100,43 +100,40 @@ def insertRecord(con):
100100
# Check current time, act accordingly.
101101
curremtTime = datetime.now()
102102
curremtTime = curremtTime.strftime("%H:%M")
103-
print(curremtTime)
104103

105-
if (curremtTime == "12:34"):
104+
if (curremtTime == "12:10"):
106105
infoSource = "Scheduled Job"
107106
else:
108107
infoSource = "Manual Trigger"
109108

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 +"');"
113110

114111
#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] +"');"
115112
cursor = con.cursor()
116113
cursor.execute(workingQuery)
117114
con.commit()
118-
print(cursor.rowcount, "Record inserted successfully into Laptop table")
115+
print("\n",cursor.rowcount, "Record inserted successfully into Gold Rate table")
119116
return True
120117

121118
def disconnectDB(con):
122119
if (con.is_connected()):
123120
con.close()
124-
print("MySQL connection is closed")
121+
print("MySQL connection is closed\n")
125122
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")
127124

128-
print("Connecting to your database..")
125+
print("\nConnecting to your database..\n")
129126
time.sleep(5)
130127
connectionHook = connectToDB()
131-
print("collecting records to save..")
128+
print("\ncollecting records to save..\n")
132129
time.sleep(3)
133130
insertData = insertRecord(connectionHook)
134-
print("Records are inserted in DB, can be used for Analytics purpose in future!")
131+
print("\nRecords are inserted in DB, can be used for Analytics purpose in future!\n")
135132
time.sleep(5)
136133

137134
diconnect = disconnectDB(connectionHook)
138135

139136
time.sleep(10)
140-
print("Good Bye!")
137+
print("\nGood Bye!")
141138

142139
time.sleep(3)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /