Skip to content

Commit

Permalink
Merge pull request #1 from Sponsorlytix-Ltd/feature/sheet_database
Browse files Browse the repository at this point in the history
sheet_database init
  • Loading branch information
heitoranjos15 authored May 21, 2021
2 parents e24b99c + 9dfcf7b commit 53dce01
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
Empty file added sponsorlytix_aws/__init__.py
Empty file.
32 changes: 32 additions & 0 deletions sponsorlytix_aws/comprehend.py
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.
49 changes: 49 additions & 0 deletions sponsorlytix_sheet_databases/broadcast.py
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()

0 comments on commit 53dce01

Please sign in to comment.