Skip to content
This repository has been archived by the owner on Dec 9, 2022. It is now read-only.

Commit

Permalink
Merge pull request #3 from viniciusgava/feature/refactor
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
viniciusgava authored Jul 3, 2018
2 parents 52947a8 + b1e18c6 commit 745a758
Show file tree
Hide file tree
Showing 15 changed files with 268 additions and 157 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,9 @@ venv.bak/

.DS_Store

downloads/
# Download folder
downloads/

# Sensitive information
src/local/credentials.py
src/local/settings.py
7 changes: 1 addition & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ RUN sudo apt-get update && sudo apt-get install -y --no-install-recommends \
RUN pip3 install selenium

COPY src/ /usr/workspace
COPY holerite-entry-point.sh /opt/bin

USER root
RUN chmod +x /opt/bin/holerite-entry-point.sh
USER seluser

WORKDIR /usr/workspace

CMD ["/opt/bin/holerite-entry-point.sh"]
CMD ["python3", "/usr/workspace/app-docker.py"]
22 changes: 21 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
build-docker:
build-docker:cleanup
docker build -t viniciusgava/portaldorh-holerite-download:latest .

publish-image:
docker push viniciusgava/portaldorh-holerite-download:latest

cleanup:
rm -rf src/local/credentials.py
rm -rf src/local/settings.py
find . -name "__pycache__" -exec rm -rf "{}" \;
find . -name "*.pyc" -exec rm -rf "{}" \;

validate-cleanup:
ls -la src/local/credentials.py
ls -la src/local/settings.py
find . -name "__pycache__"
find . -name "*.pyc"

prepare-local:
cp src/local/credentials.py.dist src/local/credentials.py
cp src/local/settings.py.dist src/local/settings.py
pip3 install selenium
32 changes: 21 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Portal do RH Download
Download holerite PDF using selenium, chrome and python
## Usage
Download holerite PDF using selenium, chrome and python at Portal do RH
## Usage - Docker

```
docker run -v $(pwd):/usr/workspace/downloads \
-e RH_USERNAME='YOUR USER NAME HERE' \
Expand All @@ -15,16 +16,25 @@ File name is the search date, ``MM-YYYY.pdf``.

``03-2018.pdf``

## ENV Variable availables
### Container ENV variables

| ENV VARIABLE | REQUIRED | DESCRIPTION | DEFAULT VALUE |
| ---------------- |:--------:|----------------------------|---------------------------------------------------------------|
| RH_SEARCHDATE | yes | Search date. eg(03/2018) | |
| RH_URL | no | Portal do RH login page | https://www.portaldorh.com.br/portal_rckt/Auto_Principal.aspx |
| DOWNLOAD_PATH | no | Where files will be saved. | /usr/workspace/downloads |
| RH_USERNAME | yes | Your username to login | |
| RH_PASSWORD | yes | Your password to login | |

# Usage - Local
Makefile and instruction bellow expected you uses python3.
It also expected you already have a chrome webdrive installed.

| ENV VARIABLE | REQUIRED | DEFAULT VALUE | DESCRIPTION |
| ---------------- |:--------:|---------------------------------------------------------------|----------------------------|
| RH_SEARCHDATE | yes | | Search date. eg(03/2018) |
| RH_URL | no | https://www.portaldorh.com.br/portal_rckt/Auto_Principal.aspx | Portal do RH login page |
| DOWNLOAD_PATH | no | /usr/workspace/downloads | Where files will be saved. |
| RH_USERNAME | yes | | Your username to login |
| RH_PASSWORD | yes | | Your password to login |
1. Clone repository
2. Run ``make prepare-local``
3. Edit both files ``src/local/credentials.py``and ``src/local/settings.py`` with your information.
4. Run ``python3 src/app-local.py``

## Links
- [GitHub](https://github.com/viniciusgava/portaldorh-holerite-download)
- [Docker Hub](https://hub.docker.com/r/viniciusgava/portaldorh-holerite-download/)
- [Docker Hub](https://hub.docker.com/r/viniciusgava/portaldorh-holerite-download/)
2 changes: 0 additions & 2 deletions holerite-entry-point.sh

This file was deleted.

9 changes: 9 additions & 0 deletions src/app-docker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from docker import credentials
from docker import settings
from downloader import *

docker_settings = settings
docker_settings.headless = True

downloader = Downloader(credentials, docker_settings)
downloader.run()
6 changes: 6 additions & 0 deletions src/app-local.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from local import credentials
from local import settings
from downloader import *

downloader = Downloader(credentials, settings)
downloader.run()
129 changes: 0 additions & 129 deletions src/app.py

This file was deleted.

Empty file added src/docker/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion src/credentials.py → src/docker/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
if os.environ.get('RH_PASSWORD') is None:
sys.exit("Missing ENV VARIABLE RH_PASSWORD")

# customer username
# Customer username
username = os.environ.get('RH_USERNAME')

# Customer Password
Expand Down
12 changes: 6 additions & 6 deletions src/input.py → src/docker/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
import sys

if os.environ.get('RH_SEARCHDATE') is None:
sys.exit("Missing ENV VARIABLE RH_USERNAME")
sys.exit("Missing ENV VARIABLE RH_SEARCHDATE")

searchDate = os.environ.get('RH_SEARCHDATE')
search_date = os.environ.get('RH_SEARCHDATE')

# Default portal do RH URL, if it is not configured by env variable
portalURL = os.environ.get(
portal_rh = os.environ.get(
"RH_URL",
"https://www.portaldorh.com.br/portal_rckt/Auto_Principal.aspx"
)

# Default download path, if it is not configured by env variable
defaultDownloadPath = os.environ.get(
default_download_path = os.environ.get(
"DOWNLOAD_PATH",
"/usr/workspace/downloads"
)

# Ensure downloads path exists
if os.path.exists(defaultDownloadPath) is False:
os.makedirs(defaultDownloadPath)
if os.path.exists(default_download_path) is False:
os.makedirs(default_download_path)
Loading

0 comments on commit 745a758

Please sign in to comment.