Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import mysql.connector
- import csv
- import os
- source = os.path.join('source_files', 'aws_bills', 'test_data.csv')
- def main():
- # See which headers are available
- mydb = mysql.connector.connect(user='xxxx', password='xxxx',
- host='xxxx',
- database='aws_bill')
- cursor = mydb.cursor()
- with open(source) as csv_file:
- csv_reader = csv.reader(csv_file, delimiter=',')
- sql = "INSERT INTO billing_info (InvoiceId) VALUES {}"
- for row in csv_reader:
- row = (', '.join(row))
- print(row)
- cursor.execute(sql.format(row))
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement