File size: 2,231 Bytes
94a7d52
 
457afbf
 
94a7d52
 
 
 
 
 
 
 
 
457afbf
 
94a7d52
 
 
 
457afbf
 
 
94a7d52
 
 
 
 
ffd6997
94a7d52
457afbf
 
 
94a7d52
 
 
cd5aacd
 
 
 
70492c1
 
94a7d52
cd5aacd
94a7d52
 
70492c1
94a7d52
 
 
457afbf
 
94a7d52
 
 
 
 
 
 
 
 
cd5aacd
94a7d52
cd5aacd
 
4640e50
 
94a7d52
cd5aacd
94a7d52
 
d07fe15
94a7d52
 
 
457afbf
 
94a7d52
 
 
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from abc import ABC, abstractmethod
from shortener_tool import ShortenerTool
from advanced_scrape_tool import AdvancedScrapingTool
from crewai_tools import ScrapeElementFromWebsiteTool

class Merchant():
    def __init__(self):
        pass
        
    @abstractmethod
    def get_template(self, main_cupom, cupom_1, store = None) -> str:
        pass
    
    def keep_css_selectors(self) -> list[str]:
        return ['body']

    @abstractmethod
    def shorten_url(self, url: str) -> str:
        pass
    
    def get_scraper_tool(self):
        return ScrapeElementFromWebsiteTool()

class NaturaMerchant(Merchant):
    
    def __init__(self, natura_api_token: str):
        super().__init__()
        self.shortener_tool = ShortenerTool(natura_api_token=natura_api_token)

    def get_scraper_tool(self):
        return AdvancedScrapingTool()
    
    def get_template(self, main_cupom, cupom_1, store = None) -> str:
        return f"""
###Template:
{{Description}}. {{Title}}  
  
(ENTREGA FEITA PELA PRÓPRIA NATURA)  
  
Preço original: ~{{ORIGINAL PRICE}}~  
*HOJE: {{CUPOM DISCOUNTED PRICE}} — {{TOTAL DISCOUNT PERCENTAGE}}% OFF*  

🎟️ CUPOM: {main_cupom.upper()} {'ou ' + cupom_1.upper() if cupom_1.upper() else ''}  
🛒 Compre aqui: {{short_url}}  

⚠️ Faça login com o mesmo email e senha que já usa para comprar na Natura!
###End Template
    """
    
    def keep_css_selectors(self) -> list[str]:
        return ['h1.text-2xl', '#product-price', '.pt-4']

    def shorten_url(self, url: str) -> str:
        return self.shortener_tool.run(url)
    
class MercadoLivreMerchant(Merchant):
    
    def get_template(self, main_cupom, cupom_1, store = None) -> str:
        return f"""
###Template:
{{Description}}. {{Title}}  

(MERCADO LIVRE - {store.upper()} OFICIAL)  
  
Preço original: ~{{ORIGINAL PRICE}}~  
*HOJE: {{CUPOM DISCOUNTED PRICE}} — {{TOTAL DISCOUNT PERCENTAGE}}% OFF*  

🎟️ CUPOM: {main_cupom.upper()}  
🛒 Compre aqui: {{short_url}}  
    	    
⚠️ Selecione a loja oficial {store.upper()}
###End Template
   """
    
    def keep_css_selectors(self) -> list[str]:
        return ['.rl-card-featured']

    def shorten_url(self, url: str) -> str:
        return url