Omkar008 commited on
Commit
1e272ca
1 Parent(s): 57f6c59

Update controllers/ws_controller.py

Browse files
Files changed (1) hide show
  1. controllers/ws_controller.py +12 -1
controllers/ws_controller.py CHANGED
@@ -8,6 +8,12 @@ import requests
8
  from bs4 import BeautifulSoup
9
  from models.models import Message, Attachment
10
  from fastapi import WebSocket
 
 
 
 
 
 
11
 
12
  def get_messages(code: str,brand_name: Optional[str] = None) -> List[Message]:
13
  access_token = code
@@ -66,6 +72,10 @@ def fetch_message_data(access_token: str, message_id: str) -> Message:
66
  body = extract_body_from_mail(message_data)
67
 
68
  attachments = extract_attachments_from_mail(access_token, message_data)
 
 
 
 
69
  body_len = 0
70
  if body is not None :
71
  body_len = len(body)
@@ -79,7 +89,8 @@ def fetch_message_data(access_token: str, message_id: str) -> Message:
79
  # print("Printing attachment Data: ")
80
  # print(attachments)
81
  # print("Completed this mail.")
82
- return Message(message_id=message_id, body_len=body_len,body=body, attachments=attachments, company=company_from_mail)
 
83
 
84
 
85
  def extract_subject_from_mail(message_data: dict) -> str:
 
8
  from bs4 import BeautifulSoup
9
  from models.models import Message, Attachment
10
  from fastapi import WebSocket
11
+ from services import utils as ut
12
+
13
+ def get_company_type(company_name:str)->str:
14
+ company_types_dict ={'ao yun': 'wines and spirit', 'ardbeg': 'wines and spirit', 'belvedere': 'wines and spirit', 'bodega numanthia': 'wines and spirit', 'chandon': 'wines and spirit', 'château cheval blanc': 'wines and spirit', "château d'yquem": 'wines and spirit', 'château galoupet': 'wines and spirit', 'cheval des andes': 'wines and spirit', 'clos19': 'wines and spirit', 'cloudy bay': 'wines and spirit', 'colgin cellars': 'wines and spirit', 'dom pérignon': 'wines and spirit', 'domaine des lambrays': 'wines and spirit', 'eminente': 'wines and spirit', 'glenmorangie': 'wines and spirit', 'hennessy': 'wines and spirit', 'joseph phelps': 'wines and spirit', 'krug': 'wines and spirit', 'mercier': 'wines and spirit', 'moët & chandon': 'wines and spirit', 'newton vineyard': 'wines and spirit', 'ruinart': 'wines and spirit', 'terrazas de los andes': 'wines and spirit', 'veuve clicquot': 'wines and spirit', 'volcan de mi tierra': 'wines and spirit', 'woodinville': 'wines and spirit' , 'berluti': 'Fashion & Leather Goods', 'celine': 'Fashion & Leather Goods', 'christian dior': 'Fashion & Leather Goods', 'emilio pucci': 'Fashion & Leather Goods', 'fendi': 'Fashion & Leather Goods', 'givenchy': 'Fashion & Leather Goods', 'kenzo': 'Fashion & Leather Goods', 'loewe': 'Fashion & Leather Goods', 'loro piana': 'Fashion & Leather Goods', 'louis vuitton': 'Fashion & Leather Goods', 'marc jacobs': 'Fashion & Leather Goods', 'moynat': 'Fashion & Leather Goods', 'patou': 'Fashion & Leather Goods', 'rimowa': 'Fashion & Leather Goods','acqua di parma': 'Perfumes & Cosmetics', 'benefit cosmetics': 'Perfumes & Cosmetics', 'cha ling': 'Perfumes & Cosmetics', 'fenty beauty by rihanna': 'Perfumes & Cosmetics', 'fresh': 'Perfumes & Cosmetics', 'givenchy parfums': 'Perfumes & Cosmetics', 'guerlain': 'Perfumes & Cosmetics', 'kenzo parfums': 'Perfumes & Cosmetics', 'kvd beauty': 'Perfumes & Cosmetics', 'loewe perfumes': 'Perfumes & Cosmetics', 'maison francis kurkdjian': 'Perfumes & Cosmetics', 'make up for ever': 'Perfumes & Cosmetics', 'officine universelle buly': 'Perfumes & Cosmetics', 'olehenriksen': 'Perfumes & Cosmetics', 'parfums christian dior': 'Perfumes & Cosmetics', 'stella by stella mccartney': 'Perfumes & Cosmetics','bulgari': 'Watches & Jewelry', 'chaumet': 'Watches & Jewelry', 'fred': 'Watches & Jewelry', 'hublot': 'Watches & Jewelry', 'repossi': 'Watches & Jewelry', 'tag heuer': 'Watches & Jewelry', 'tiffany & co.': 'Watches & Jewelry', 'zenith': 'Watches & Jewelry','24s': 'Selective retailing', 'dfs': 'Selective retailing', 'la grande epicerie de paris': 'Selective retailing', 'le bon marché rive gauche': 'Selective retailing', 'sephora': 'Selective retailing','belmond': 'Other activities', 'cheval blanc': 'Other activities', 'connaissance des arts': 'Other activities', 'cova': 'Other activities', 'investir': 'Other activities', "jardin d'acclimatation": 'Other activities', 'le parisien': 'Other activities', 'les echos': 'Other activities', 'radio classique': 'Other activities', 'royal van lent': 'Other activities'}
15
+ print(company_types_dict["louis vuitton"])
16
+ return company_types_dict.get(company_name.lower(), 'Others')
17
 
18
  def get_messages(code: str,brand_name: Optional[str] = None) -> List[Message]:
19
  access_token = code
 
72
  body = extract_body_from_mail(message_data)
73
 
74
  attachments = extract_attachments_from_mail(access_token, message_data)
75
+ high_level_company_type = get_company_type(company_from_mail)
76
+ structed_attachment_data = extract_json_from_attachments(access_token , message_data)
77
+
78
+
79
  body_len = 0
80
  if body is not None :
81
  body_len = len(body)
 
89
  # print("Printing attachment Data: ")
90
  # print(attachments)
91
  # print("Completed this mail.")
92
+ return Message(message_id=message_id, body_len=body_len,body=body, attachments=attachments, company=company_from_mail,high_level_company_type=high_level_company_type,structured_data = structed_attachment_data)
93
+
94
 
95
 
96
  def extract_subject_from_mail(message_data: dict) -> str: