Skip to content

Commit

Permalink
work
Browse files Browse the repository at this point in the history
  • Loading branch information
Beni Bichsel committed Dec 28, 2018
1 parent d208276 commit 44d0740
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 103 deletions.
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
50 changes: 35 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)
42 changes: 0 additions & 42 deletions docker/Dockerfile

This file was deleted.

30 changes: 0 additions & 30 deletions docker/Makefile

This file was deleted.

11 changes: 0 additions & 11 deletions docker/README.md

This file was deleted.

2 changes: 2 additions & 0 deletions images/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/*.ogv
/output_tmp
28 changes: 28 additions & 0 deletions images/to-gif.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions images/videos/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/*
!/.gitignore
25 changes: 20 additions & 5 deletions insert-data.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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)

Expand Down
20 changes: 20 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"
3 changes: 3 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

###############
Expand Down

0 comments on commit 44d0740

Please sign in to comment.