Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. import pymysql.cursors
  2.  
  3. connection = pymysql.connect(host='127.0.0.1',
  4. user='root',
  5. password='',
  6. db='someDB',
  7. charset='utf8mb4',
  8. cursorclass=pymysql.cursors.DictCursor)
  9.  
  10. def insertInDB(date, times, county, month):
  11. month = "0" + str(month) if month < 10 else str(month)
  12. date = "0" + str(date) if int(date) < 10 else str(date)
  13.  
  14. try:
  15. with connection.cursor() as cursor:
  16. # Create a record.
  17. sql = 'INSERT INTO `timetables`(`id`, `county`, `date`, `fajr`, `shurooq`, `dhuhr`, `asr`, `maghrib`, `isha`)'
  18. sql += 'VALUES (NULL, "' + county + '", "' + '2017-' + month + '-' + date + '", '
  19. i=0
  20. while i < len(times)-1:
  21. sql += '"' + times[i] + '", '
  22. i+=1
  23. sql += '"' + times[i] + '")'
  24. print(sql)
  25.  
  26. cursor.execute(sql)
  27. connection.commit()
  28. finally:
  29. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement