Advertisement
bluethundr12

Untitled

Apr 28th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. import mysql.connector
  2. import csv
  3. import os
  4. source = os.path.join('source_files', 'aws_bills', 'test_data.csv')
  5. def main():
  6.  
  7.     # See which headers are available
  8.     mydb = mysql.connector.connect(user='xxxx', password='xxxx',
  9.                                 host='xxxx',
  10.                                 database='aws_bill')
  11.     cursor = mydb.cursor()
  12.     with open(source) as csv_file:
  13.         csv_reader = csv.reader(csv_file, delimiter=',')
  14.         sql = "INSERT INTO billing_info (InvoiceId) VALUES {}"
  15.         for row in csv_reader:
  16.             row = (', '.join(row))
  17.             print(row)
  18.             cursor.execute(sql.format(row))
  19. if __name__ == "__main__":
  20.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement