File size: 2,002 Bytes
94a7d52
 
457afbf
 
94a7d52
 
 
 
 
 
 
 
 
457afbf
 
94a7d52
 
 
 
457afbf
 
 
94a7d52
 
 
 
 
ffd6997
94a7d52
457afbf
 
 
94a7d52
 
 
db16884
cd5aacd
db16884
 
94a7d52
cd5aacd
94a7d52
 
 
 
457afbf
 
94a7d52
 
 
 
 
 
 
 
 
db16884
cd5aacd
db16884
 
94a7d52
db16884
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
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:
{{Title}}  
  
De: ~{{ORIGINAL PRICE}}~  
πŸ”₯*POR: {{CUPOM DISCOUNTED PRICE}} β€” {{TOTAL DISCOUNT PERCENTAGE}}% OFF*  

🎟️ CUPOM: {main_cupom.upper()} {'ou ' + cupom_1.upper() if cupom_1.upper() else ''}  
πŸ›’ Compre aqui: {{short_url}}  
###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:
{{Title}}  
  
De: ~{{ORIGINAL PRICE}}~  
πŸ”₯ *Por: {{CUPOM DISCOUNTED PRICE}} β€” {{TOTAL DISCOUNT PERCENTAGE}}% OFF*  

🎟️ CUPOM: {main_cupom.upper()} {'ou ' + cupom_1.upper() if cupom_1.upper() else ''}
πŸ›’ Compre aqui: {{short_url}}  
###End Template
   """
    
    def keep_css_selectors(self) -> list[str]:
        return ['.rl-card-featured']

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