Skip to content

Commit

Permalink
Changed dockerfile for supporting selenium and firefox.
Browse files Browse the repository at this point in the history
Made proper linting and making the build fail on improper coding.
  • Loading branch information
DennisJensen95 committed Sep 11, 2022
1 parent a7170cf commit 38e116a
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 12 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ jobs:
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
flake8 . --count --select=E9,F63,F7 --show-source --statistics
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
flake8 . --count --ignore=W605 --max-complexity=10 --max-line-length=127 --statistics
- name: Unit tests
working-directory: ./src
run: |
Expand Down
31 changes: 28 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,36 @@ COPY requirements.txt requirements.txt
RUN pip install --user -r requirements.txt

FROM python:3.10-slim AS application-image

ENV GECKODRIVER_VER v0.31.0
ENV FIREFOX_VER 104.0

RUN set -x \
&& apt update \
&& apt upgrade -y \
&& apt install -y \
firefox-esr

# Add latest FireFox
RUN set -x \
&& apt install -y \
libx11-xcb1 \
libdbus-glib-1-2 \
curl \
bzip2 \
&& curl -sSLO https://download-installer.cdn.mozilla.net/pub/firefox/releases/${FIREFOX_VER}/linux-x86_64/en-US/firefox-${FIREFOX_VER}.tar.bz2 \
&& tar -jxf firefox-* \
&& mv firefox /opt/ \
&& chmod 755 /opt/firefox \
&& chmod 755 /opt/firefox/firefox

RUN set -x \
&& curl -sSLO https://github.com/mozilla/geckodriver/releases/download/${GECKODRIVER_VER}/geckodriver-${GECKODRIVER_VER}-linux64.tar.gz \
&& tar zxf geckodriver-*.tar.gz \
&& mv geckodriver /usr/bin/

WORKDIR /curly-girl
COPY --from=compile-image /root/.local /root/.local
COPY src src

CMD ["python", "src/main.py"]



2 changes: 1 addition & 1 deletion ci/code_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
summary: str = coverage_report.stdout.read().decode("utf-8")

last_line = summary.splitlines()[-1]
coverage = re.findall("\d+", last_line)[-1]
coverage = re.findall('\d+', last_line)[-1]

print(coverage)
4 changes: 2 additions & 2 deletions src/aws_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ def get_secret():
secret = get_secret_value_response['SecretString']
secret = json.loads(secret)
return True, secret
return False, "Unable to get secret"

return False, "Unable to get secret"
2 changes: 1 addition & 1 deletion src/logger/init_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ def getLogger(logger_name: str):
logger = logging.getLogger(logger_name)
coloredlogs.install(level="DEBUG", logger=logger)

return logger
return logger
5 changes: 3 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Standard library
from lib2to3.pgen2.token import OP
from time import sleep
import schedule

Expand Down Expand Up @@ -39,7 +38,7 @@ def click_only_essential_cookies(driver: webdriver):
# Click on parent
element.find_element(By.XPATH, "..").click()

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


def extract_posts_from_page(driver: webdriver):
Expand Down Expand Up @@ -108,6 +107,8 @@ def main():
schedule.every(1).minutes.do(
check_if_any_cancellation, secrets, facebook_page)

check_if_any_cancellation(secrets, facebook_page)

log.debug("Start the scheduler")
while True:
schedule.run_pending()
Expand Down
5 changes: 4 additions & 1 deletion src/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ def test_identifying_positiv_cancellation(self):
self.assertTrue(is_canellation_post)

def test_identifying_negative_cancellation(self):
post_text = """Så er der nyhed fra innersense Du kan nu købe en Collection og spare 25% af normal prisen! Du får shampoo, Balsam, leave in og detox maske - alt du skal bruge for at komme i gang 😍"""
post_text = """Så er der nyhed fra innersense Du kan nu købe en
Collection og spare 25% af normal prisen! Du får shampoo,
Balsam, leave in og detox maske - alt du skal bruge for at
komme i gang 😍"""
is_canellation_post = identify_cancellation(post_text)
self.assertFalse(is_canellation_post)

Expand Down

0 comments on commit 38e116a

Please sign in to comment.