diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ff4a159 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM selenium/standalone-firefox-debug + +USER root + +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ + python3 \ + python3-pip \ + && apt-get clean && rm -rf /var/lib/apt/lists/* + + +RUN pip3 install \ + selenium \ + pandas \ + xlrd + +WORKDIR "/sportdb-helper" +COPY . . +ENTRYPOINT ["python3", "./insert-data.py"] \ No newline at end of file diff --git a/Makefile b/Makefile index 4b6374a..91f5636 100644 --- a/Makefile +++ b/Makefile @@ -1,22 +1,42 @@ # all commands involving docker use sudo, which is typically required to use docker commands -IMAGE := bichselb/sportdb-helper +SELENIUM_CONTAINER := selenium-container + +.PHONY: selenium +selenium: clean + sudo docker run -d \ + -p 4444:4444 \ + -p 5901:5900 \ + -v /dev/shm:/dev/shm \ + -e VNC_NO_PASSWORD=1 \ + --name $(SELENIUM_CONTAINER) \ + selenium/standalone-firefox-debug + + +IMAGE := sportdb-helper CONTAINER := sportdb-helper-container -TAG := latest -ROOTDIR := $$(pwd) -RUN := sudo docker run \ - -it \ - --name $(CONTAINER) \ - --workdir="/sportdp-helper" \ - -v $(ROOTDIR):/sportdp-helper \ - $(IMAGE) +# build the docker image +.PHONY: image +image: clean selenium + sudo docker build -t $(IMAGE) . -# launch a docker container using the image, which will provide a shell in the container -.PHONY: run -run: - cd docker && make image clean-container - $(RUN) python3 insert-data.py +# remove the created docker container +.PHONY: clean +clean: + sudo docker rm -f $(CONTAINER) || true + sudo docker rm -f $(SELENIUM_CONTAINER) || true -all: run +.PHONY: vnc +vnc: + vncviewer 127.0.0.1:5901 + + +.PHONY: run +run: + sudo docker run \ + --name $(CONTAINER) \ + --entrypoint "/bin/bash" \ + -it \ + $(IMAGE) \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index 784f037..0000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,42 +0,0 @@ -FROM ubuntu:18.04 - -############# -# packages # -############# - -RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ - firefox \ - python3 \ - python3-pip \ - wget \ - && apt-get clean && rm -rf /var/lib/apt/lists/* - -################ -# pip packages # -################ - -RUN pip3 install \ - selenium \ - pandas \ - xlrd - -############### -# geckodriver # -############### - -# prepare directory -ARG geckodir=/opt/geckodriver -ARG archive=geckodriver.tar.gz - -RUN mkdir -p $geckodir && \ - cd $geckodir && \ - wget -O $archive https://github.com/mozilla/geckodriver/releases/download/v0.23.0/geckodriver-v0.23.0-linux64.tar.gz && \ - tar -xvzf $archive && \ - chmod +x geckodriver && \ - ln -s "$geckodir/geckodriver" "/usr/local/bin/geckodriver" && \ - rm -archive - - -COPY ./root /sportdb-helper - -CMD ["./insert-data.py"] \ No newline at end of file diff --git a/docker/Makefile b/docker/Makefile deleted file mode 100644 index 78b1cc4..0000000 --- a/docker/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -# all commands involving docker use sudo, which is typically required to use docker commands - -IMAGE := bichselb/sportdb-helper -CONTAINER := sportdb-helper-container -TAG := latest - -DOCKERDIR := $$(pwd) -ROOTDIR := DOCKERDIR/.. -RUN := sudo docker run \ - -it \ - --name $(CONTAINER) \ - --workdir="/sportdp-helper" \ - -v $(ROOTDIR):/sportdp-helper \ - $(IMAGE) - -# build the docker image -.PHONY: image -image: - rsync ../ ./root --exclude=../docker - sudo docker build -t $(IMAGE):$(TAG) . - -# launch a docker container using the image, which will provide a shell in the container -.PHONY: run -run: image clean-container - $(RUN) - -# remove the created docker container -.PHONY: clean-container -clean-container: - sudo docker rm $(CONTAINER) || true diff --git a/docker/README.md b/docker/README.md deleted file mode 100644 index fff52ba..0000000 --- a/docker/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# Latex Plus - -Docker image supplying latex and some convenience tools. - -## How to install docker - -To install docker, follow the instructions on https://docs.docker.com/install/linux/docker-ce/ubuntu/. - -## Generating the docker image - -All relevant commands are described in the [Makefile](Makefile). diff --git a/images/.gitignore b/images/.gitignore new file mode 100644 index 0000000..fea95d2 --- /dev/null +++ b/images/.gitignore @@ -0,0 +1,2 @@ +/*.ogv +/output_tmp diff --git a/images/to-gif.sh b/images/to-gif.sh new file mode 100644 index 0000000..1d0113f --- /dev/null +++ b/images/to-gif.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# prerequisites: +# sudo apt install -y ffmpeg + +# source: https://unix.stackexchange.com/questions/35282/convert-ogv-video-to-gif-animation + +INPUT=in-action.ogv +OUTPUT=in-action.gif +TMP=output_tmp + +BASEDIR="$( dirname "$0")" + +cd "$BASEDIR" + +mkdir -p $TMP + +# ffmpeg -i $INPUT $OUTPUT + +# exit + +FPS=15 +WIDTH=1000 +ffmpeg -i $INPUT -vf fps=$FPS,scale=$WIDTH:-1:flags=lanczos,palettegen $TMP/tmp_palette.png +ffmpeg -y -i $INPUT -i $TMP/tmp_palette.png -loop 0 -filter_complex "fps=$FPS,scale=$WIDTH:-1:flags=lanczos[x];[x][1:v]paletteuse" $OUTPUT + +# cleanup +rm -r $TMP diff --git a/images/videos/.gitignore b/images/videos/.gitignore new file mode 100644 index 0000000..a68d087 --- /dev/null +++ b/images/videos/.gitignore @@ -0,0 +1,2 @@ +/* +!/.gitignore diff --git a/insert-data.py b/insert-data.py index 5691b39..5986391 100644 --- a/insert-data.py +++ b/insert-data.py @@ -1,9 +1,14 @@ -from selenium import webdriver -import pandas as pd +import sys +import time import datetime import re import argparse -import sys + +from selenium import webdriver +import pandas as pd +from selenium.webdriver.common.desired_capabilities import DesiredCapabilities +from urllib3.exceptions import MaxRetryError + # UTILS @@ -39,10 +44,16 @@ class DataInserter: def __init__(self, data): self.data = data + self.driver = None def navigate_to_page(self): sport_db_url = 'https://www.sportdb.ch' - self.driver = webdriver.Firefox() + try: + self.driver = webdriver.Remote("http://localhost:4444/wd/hub", DesiredCapabilities.FIREFOX) + print('Successfully opened sportdb') + except MaxRetryError: + print('Standalone docker image is not running. Trying to run firefox locally...') + self.driver = webdriver.Firefox() self.driver.get(sport_db_url) def login(self, username, password): @@ -106,7 +117,8 @@ def to_previous(self): return False def __del__(self): - self.driver.close() + if self.driver is not None: + self.driver.close() def run(data_file, username, password, course_id): @@ -116,6 +128,9 @@ def run(data_file, username, password, course_id): # navigate ins = DataInserter(data) ins.navigate_to_page() + input("""We recommend you watch the progress of sportDB Helper by running +$ vncviewer 127.0.0.1:5901 +Press enter to continue...""") ins.login(username, password) ins.to_awk(course_id) diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..d8f8e2a --- /dev/null +++ b/run.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +########### +# PURPOSE # +########### +# Convenient wrapper for running SportDP Helper + +BASEDIR="$( dirname "$0")" +cd "$BASEDIR" + +# sudo docker run --expose=4444 sportdb-helper "$@" + + +sudo docker run \ + -rm \ + -p 5901:5900 \ + -v /dev/shm:/dev/shm \ + -e VNC_NO_PASSWORD=1 \ + --name $(CONTAINER) \ + sportdb-helper "$@" \ No newline at end of file diff --git a/setup.sh b/setup.sh index d4888d7..f81520a 100644 --- a/setup.sh +++ b/setup.sh @@ -17,6 +17,9 @@ # Any subsequent commands which fail will cause the shell script to exit immediately set -e +BASEDIR="$( dirname "$0")" +cd "$BASEDIR" + ENVNAME=env ###############