Use boto3 instead of urllib for getting csv files
This commit is contained in:
@@ -4,7 +4,7 @@ import json
|
||||
import click
|
||||
import boto3
|
||||
import csv
|
||||
import urllib2
|
||||
|
||||
|
||||
CONFIG_FILE_NAME = "driverConfig.json"
|
||||
CONFIG_OUTPUT_FILENAME = "config.txt"
|
||||
@@ -33,9 +33,10 @@ def get_driver_files():
|
||||
def get_driver_ids():
|
||||
"""Retrieve the master list of driver IDs from the S3 bucket."""
|
||||
ids = []
|
||||
url = 'https://s3.amazonaws.com/{}/deviceIds.csv'.format(DRIVER_BUCKET)
|
||||
response = urllib2.urlopen(url)
|
||||
csvreader = csv.DictReader(response)
|
||||
|
||||
csvfileObj = s3.Object(DRIVER_BUCKET, 'deviceIds.csv')
|
||||
csvString = csvfileObj.get()['Body'].read().decode('utf-8')
|
||||
csvreader = csv.DictReader(csvString.splitlines())
|
||||
for row in csvreader:
|
||||
ids.append(row)
|
||||
return ids
|
||||
@@ -57,8 +58,7 @@ def check_driver_id(driver_name):
|
||||
s3.Bucket(DRIVER_BUCKET).put_object(Key=file_key, Body=new_csv_contents)
|
||||
s3.ObjectAcl(DRIVER_BUCKET, file_key).put(ACL='public-read')
|
||||
return new_id
|
||||
|
||||
|
||||
|
||||
|
||||
@click.group()
|
||||
def cli():
|
||||
|
||||
Reference in New Issue
Block a user