bluethundr12

Untitled

Apr 28th, 2019
149
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3
  2. import mysql.connector
  3. import csv
  4. import os
  5. source = os.path.join('source_files', 'aws_bills', 'test_data.csv')
  6. def main():
  7.     # See which headers are available
  8.     mydb = mysql.connector.connect(user='xxxx', password='xxxxx',
  9.                                 host='xxxxx',
  10.                                 database='aws_bill')
  11.     cursor = mydb.cursor()
  12.     try:
  13.         with open(source) as csv_file:
  14.             csv_reader = csv.reader(csv_file, delimiter=',')
  15.             sql = "INSERT INTO billing_info (InvoiceId) VALUES (%s)"
  16.             for row in csv_reader:
  17.                 row = (', '.join(row))
  18.                 print(row)
  19.                 #cursor.execute(sql, (row[0],))
  20.     except:
  21.         mydb.rollback()
  22.     finally:
  23.         mydb.close()
  24.  
  25. if __name__ == "__main__":
  26.     main()
RAW Paste Data