-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilereader.py
More file actions
45 lines (34 loc) · 1.09 KB
/
Copy pathfilereader.py
File metadata and controls
45 lines (34 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import csv
import json
import datetime as dt
import boto3
import os
import lambda_function as lmbFunction
datestamp = dt.datetime.now().strftime("%Y/%m/%d")
timestamp = dt.datetime.now().strftime("%s")
filename_json = "/tmp/file_{ts}.json".format(ts=timestamp)
filename_csv = "/tmp/file_{ts}.csv".format(ts=timestamp)
def processLine (line):
line = line
line = line.split(",")
data = []
#csv_file = csv.DictReader(line)
dataPre = list(line)
dataPreII = json.dumps(dataPre)
data = json.loads(dataPreII)
return data
def readFile (response,filetype):
if filetype == 'json':
text = response["Body"].read().decode()
data = json.loads(text)
print('Complete read of JSON')
return data
elif filetype == 'csv':
csvcontent = response['Body'].read().decode('utf-8-sig').split('\n')
data = []
csv_file = csv.DictReader(csvcontent)
dataPre = list(csv_file)
dataPreII = json.dumps(dataPre)
data = json.loads(dataPreII)
print('Complete read of CSV')
return data