Skip to content

Commit

Permalink
Merge pull request #83 from jrafaelrn/ifood_alive_beta
Browse files Browse the repository at this point in the history
from request to selenium
  • Loading branch information
jrafaelrn authored Oct 25, 2024
2 parents fd4e0cd + 96bdadf commit 53210c6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
35 changes: 20 additions & 15 deletions src/functions/ifood_alive/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import base64
import requests
import sender

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager


def check_if_alive():

Expand All @@ -15,6 +19,8 @@ def check_if_alive():
}
]

# Configura o WebDriver do Chrome
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))

for loja in urls:

Expand All @@ -23,20 +29,19 @@ def check_if_alive():
msg = None

try:
# Faz a requisição GET para a URL
response = requests.get(url)

# Verifica se a requisição foi bem-sucedida (código 200)
if response.status_code == 200:
# Verifica se o texto "Loja Fechada" está presente no conteúdo da página
if "Loja Fechada" in response.text:
msg = f"'Loja Fechada': {loja['loja']}."
else:
msg = f"'Loja Aberta': {loja['loja']}."
else:
msg = f"Erro ao acessar a página da loja {loja['loja']}. Código de status: {response.status_code}"

except requests.exceptions.RequestException as e:
driver.get(url)
print(f"Acessando {nome_loja}: {url}")

# Tenta encontrar o elemento que indica que a loja está fechada
try:
driver.find_element(By.XPATH, "//h2[contains(text(), 'Loja fechada')]")
msg = f"'Loja Fechada': {nome_loja}."
except:
continue
finally:
driver.quit()

except Exception as e:
msg = f"Ocorreu um erro na requisição para a loja {loja['loja']}: {e}"

# Envia a mensagem para o Telegram
Expand Down
2 changes: 1 addition & 1 deletion src/functions/ifood_alive/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
requests
selenium

0 comments on commit 53210c6

Please sign in to comment.