Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Download Edit And Upload A CSV to S3

TODO: scrub this to verify the includes are setup and pull it out of a function

Code

import boto3
import csv

from io import StringIO


    def process_csv_files(self):
        print("-- Processing CSV Files")
        for attachment in self.attachments:
            print(attachment['name'])
            raw_string = s3.get_object(Bucket=self.bucket, Key=attachment['original_key'])['Body'].read().decode('utf-8')
            lines = raw_string.splitlines()
            csv_reader = csv.reader(lines)
            new_csv_data = StringIO()
            csv_writer = csv.writer(new_csv_data)
            for row in csv_reader:
                csv_writer.writerow(['asdf'])
            s3.put_object(Body=new_csv_data.getvalue(), Bucket=self.bucket, Key=attachment['finalized_key'])