Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pymysql.cursors
- connection = pymysql.connect(host='127.0.0.1',
- user='root',
- password='',
- db='someDB',
- charset='utf8mb4',
- cursorclass=pymysql.cursors.DictCursor)
- def insertInDB(date, times, county, month):
- month = "0" + str(month) if month < 10 else str(month)
- date = "0" + str(date) if int(date) < 10 else str(date)
- try:
- with connection.cursor() as cursor:
- # Create a record.
- sql = 'INSERT INTO `timetables`(`id`, `county`, `date`, `fajr`, `shurooq`, `dhuhr`, `asr`, `maghrib`, `isha`)'
- sql += 'VALUES (NULL, "' + county + '", "' + '2017-' + month + '-' + date + '", '
- i=0
- while i < len(times)-1:
- sql += '"' + times[i] + '", '
- i+=1
- sql += '"' + times[i] + '")'
- print(sql)
- cursor.execute(sql)
- connection.commit()
- finally:
- return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement