-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Sponsorlytix-Ltd/feature/sheet_database
sheet_database init
- Loading branch information
Showing
4 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import boto3 | ||
|
||
|
||
class Comprehend: | ||
|
||
def __init__(self, text, language='en'): | ||
self.language = language | ||
self.text = text | ||
self.comprehend = boto3.client('comprehend', 'us-east-2') | ||
|
||
def get_comprehend_data(self): | ||
comprehend_data = { | ||
'entity': self.__get_entities(), | ||
'key_phrases': self.__get_key_phrases(), | ||
'sentiment': self.__get_sentiment() | ||
} | ||
return comprehend_data | ||
|
||
def __get_entities(self): | ||
entities = self.comprehend.detect_entities(Text=self.text, LanguageCode=self.language) | ||
return entities.get('Entities') | ||
|
||
def __get_key_phrases(self): | ||
phrases = self.comprehend.detect_key_phrases(Text=self.text, LanguageCode=self.language) | ||
return phrases.get('KeyPhrases') | ||
|
||
def __get_sentiment(self): | ||
sentiment = self.comprehend.detect_sentiment(Text=self.text, LanguageCode=self.language) | ||
return { | ||
'score': sentiment.get('SentimentScore'), | ||
'sentiment': sentiment.get('Sentiment') | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from openpyxl import load_workbook | ||
import json | ||
|
||
|
||
|
||
country = '' | ||
|
||
|
||
|
||
|
||
class BroadcastSheets: | ||
def __init__(self): | ||
self.country = '' | ||
|
||
def __builder_broadcast(self, row_values): | ||
if row_values[0]: | ||
self.country = row_values[0] | ||
return { | ||
'territory': '', | ||
'country': self.country, | ||
'broadcast_name': row_values[1], | ||
'price': row_values[2], | ||
'average_last_month': row_values[3], | ||
'website': row_values[4], | ||
'ott_subs': row_values[5], | ||
'otts_subs_prices': row_values[6] | ||
} | ||
|
||
def __map_broadcast(self, row): | ||
row_values = [column_row.value for column_row in row] | ||
return self.__builder_broadcast(row_values) | ||
|
||
|
||
def process_broadcast_sheet(self, sheet): | ||
sheet_data = map(self.__map_broadcast, sheet.iter_rows(min_row=2)) | ||
return sheet_data | ||
|
||
def process_broadcast(self): | ||
workbook = load_workbook(filename="sheets/Broadcasters Rate Cards.xlsx") | ||
broadcast_data = dict() | ||
for territory in workbook.sheetnames: | ||
sheet = workbook[territory] | ||
broadcast_data.update( | ||
{ | ||
territory: self.process_broadcast_sheet(sheet) | ||
} | ||
) | ||
|
||
BroadcastSheets().process_broadcast() |