forked from RishabKattimani/FaunaDBReadCSV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsvread (Rishab Kattimani's conflicted copy 2020-07-24).py
51 lines (40 loc) · 1.63 KB
/
csvread (Rishab Kattimani's conflicted copy 2020-07-24).py
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
46
47
48
49
50
51
#-------------------------------------------------------------------------------
# Imports
from faunadb import query as q
from faunadb.objects import Ref
from faunadb.client import FaunaClient
from csv import *
from datetime import datetime, date
import config as config
#-------------------------------------------------------------------------------
# Variables & Setup
client = FaunaClient(secret=config.secret) # Connection To Fauna
# ------------------------------------------------------------------------------
# Reading CSV File
with open('data.csv', 'r') as read_obj:
csv_reader = reader(read_obj)
#-------------------------------------------------------------------------------
# Getting Age
for row in csv_reader:
date_str = row[2]
date_object = datetime.strptime(row[2], '%m/%d/%Y').date()
today = date.today()
age = (today.year - date_object.year)
#-------------------------------------------------------------------------------
# Age Groups
if age >= 19 and age <= 60:
AgeGroup = "Adult"
if age >= 60 and age <= 1000:
AgeGroup = "Senior"
if age >= 9 and age <= 19:
AgeGroup = "Teen"
if age >= 0 and age <= 9:
AgeGroup = "Child"
#-------------------------------------------------------------------------------
# Pushing Data To FaunaDB
print (age, AgeGroup)
client.query(
q.create(
q.collection("BollywoodActor"),
{"data": {"Name": row[0], "Image": row[1], "DOB": row[2], "Age": age, "AgeGroup": AgeGroup}}
))