-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalytics.py
More file actions
34 lines (29 loc) · 1.04 KB
/
analytics.py
File metadata and controls
34 lines (29 loc) · 1.04 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
from decouple import config
import json
import csv
import nexmo
import pandas as pd
class WhatsappAnalytics:
def __init__(self):
# Setting up Nexmo credentials
self.key = config('client_key')
self.secret = config('client_secret')
self.client = nexmo.Client(key=self.key, secret=self.secret)
def get_insights(self, contact_list):
print('Getting number insights')
data = []
for contact in contact_list:
insight_json = self.client.get_advanced_number_insight(
number=contact).get('country_name')
data.append(insight_json)
# convert the list
f = open('country_data.csv', 'w')
w = csv.writer(f, delimiter=',')
# create header
w.writerow(['country'])
# split the common separated string values into a CSV file
w.writerows([x.split(',') for x in data])
f.close()
print('Number insights generated successfully')
dataframe = pd.read_csv('country_data.csv')
return dataframe