Advertisement
bluethundr12

Untitled

Apr 28th, 2019
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. import mysql.connector
  2. import csv
  3. source_dir = "source_files/aws_bills/"
  4. source_file = "test_data.csv"
  5. source = source_dir + source_file
  6. def main():
  7.     mydb = mysql.connector.connect(user='xxxx', password='xxxxxx',
  8.                                 host='xxxxxx',
  9.                                 database='aws_bill')
  10.     cursor = mydb.cursor()
  11.     with open(source) as csv_file:
  12.         csv_reader = csv.reader(csv_file, delimiter=',')
  13.         sql = "INSERT INTO billing_info (InvoiceId) VALUES (%d)"
  14.         for row in csv_reader:
  15.             print("Row type: ", type(row))
  16.             print(row)
  17.             #cursor.execute(sql, (row))
  18.     #close the connection to the database.
  19.     mydb.commit()
  20.     cursor.close()
  21.     print("Done")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement