Skip to content

Commit

Permalink
Cookies pop up handling and code coverage badge.
Browse files Browse the repository at this point in the history
1. Able to get passed cookies pop up on facebook.
2. Enabled code coverage badge.
  • Loading branch information
DennisJensen95 committed Aug 28, 2022
1 parent afea0a1 commit 1c61d98
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM python:3.11-slim

6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# curly-girl-vinthers-appointment
This repo scrapes posts from vinthers klippe kælder to fastly notify if there is an available appointment.

![CI-Build](https://github.com/DennisJensen95/curly-girl-vinthers-appointment/actions/workflows/main.yml/badge.svg)
![Coverage Badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/DennisJensen95/2b7862c80c14d562c8659e1283543190/raw/curly-girl-coverage.json)

This repo scrapes posts from vinthers klippe kælder to fastly notify if there is an available appointment.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
coverage=6.4.*
coverage==6.4.*
coloredlogs
14 changes: 14 additions & 0 deletions src/logger/init_logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Standard library
import logging
import os

# Third party library
import coloredlogs


def getLogger(logger_name: str):
logger_name = os.path.basename(logger_name).replace(".py", "")
logger = logging.getLogger(logger_name)
coloredlogs.install(level="DEBUG", logger=logger)

return logger
46 changes: 44 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,50 @@
import autoscraper
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import logging
from logger.init_logger import getLogger

log = getLogger(__file__)


def click_only_essential_cookies(driver: webdriver):
# Fetch the button
element = driver.find_element(
By.XPATH, "//*[contains(text(), 'Only allow essential cookies')]")

# Click on parent
element.find_element(By.XPATH, "..").click()

log.debug(f"Clicked on the Only allow essential cookies button")


def extract_posts_from_page(driver: webdriver):
log.debug("Extract the posts from the page")
try:
element = driver.find_element(
By.XPATH, "//*[data-ad-comet-preview, 'message']")
log.debug(
f"What text are we finding here? Tag is: {element.tag_name} {element.text}")
except Exception as e:
log.debug("No posts found")
log.error("Error: {}".format(e))


def main():
print("Scrape the curly girl website")

log.debug("Scrape the curly girl website")
facebook_page = "https://www.facebook.com/Vinthersklippekaelder"

driver = webdriver.Firefox()
driver.get(facebook_page)
driver.implicitly_wait(5)

sleep(3)
click_only_essential_cookies(driver)
extract_posts_from_page(driver)

driver.close()


if __name__ == "__main__":
Expand Down

0 comments on commit 1c61d98

Please sign in to comment.