<reponame>JoaoLeal92/crawler_ps5
# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
# from itemadapter import ItemAdapter
import telegram_send
from datetime import datetime


class Crawlerps5Pipeline:

    def process_item(self, item, spider):
        if item['price']:
            telegram_send.send(messages=[f"Produto {item['name']} encontrado por {item['price']} na url abaixo: \n\n {item['url']}"])
        else:
            current_date = datetime.now()
            current_hour = current_date.hour
            current_minute = current_date.minute

            # Checks if bot has run for 24h (every 7 am)
            if current_hour == 9 and current_minute <= 1:
                telegram_send.send(messages=["Bot ativo por 24h, produto ainda não encontrado"])

        if not item['name']:
            telegram_send.send(messages=["Ocorreu um erro ao buscar o produto, verificar no site"])

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
# from itemadapter import ItemAdapter
import telegram_send
from datetime import datetime


class Crawlerps5Pipeline:

    def process_item(self, item, spider):
        if item['price']:
            telegram_send.send(messages=[f"Produto {item['name']} encontrado por {item['price']} na url abaixo: \n\n {item['url']}"])
        else:
            current_date = datetime.now()
            current_hour = current_date.hour
            current_minute = current_date.minute

            # Checks if bot has run for 24h (every 7 am)
            if current_hour == 9 and current_minute <= 1:
                telegram_send.send(messages=["Bot ativo por 24h, produto ainda não encontrado"])

        if not item['name']:
            telegram_send.send(messages=["Ocorreu um erro ao buscar o produto, verificar no site"])
# Define your item pipelines here # # Don't forget to add your pipeline to the ITEM_PIPELINES setting # See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html # useful for handling different item types with a single interface # from itemadapter import ItemAdapter # Checks if bot has run for 24h (every 7 am)