Skip to content

Commit

Permalink
add scraper.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
sborms committed Oct 25, 2023
1 parent e74fe1b commit 8a7c7b8
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 13 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/cicd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Run CI/CD pipeline

on:
push:
branches: [ "main" ]
# branches-ignore:
# - "main"
# branches: [ "main" ]
branches-ignore:
- "main"
pull_request:
branches: [ "main" ]
# allow manual trigger
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/scraper.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Run scraper and update SQLite database

on:
push:
branches: [ "main" ]
schedule:
- cron: "45 02 * * SAT" # at 02:45 every Saturday

permissions:
actions: write
contents: write

jobs:
scrape:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v3
with:
python-version: "3.9"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r scraper/requirements.txt
- name: Scrape data
run: make scrape
- name: Commit changes
run: |
git config --local user.name ${{ secrets.USER_NAME }}
git config --local user.email ${{ secrets.EMAIL }}
make push message="Scrape baby scrape"
6 changes: 4 additions & 2 deletions scraper/config/config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"url_base": "https://www.lzvcup.be",
"steps": {
"historical_players": true
"historical_players": true,
"csv": true
},
"areas": {
"ANTWERPEN": "results/1",
Expand All @@ -22,5 +23,6 @@
"standings": [["area", "region", "competition", "team"], []],
"palmares": [["team", "seizoen", "reeks", "positie"], ["area", "region", "competition"]]
},
"database": "database/futsalfriend.db"
"database": "database/futsalfriend.db",
"dir_last_updated_date": "webapp/last_updated_date.txt"
}
15 changes: 12 additions & 3 deletions scraper/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
from scraper.parsers.lzvcup import LZVCupParser
from scraper.utils.base import DataStorage
from scraper.utils.logger import Logger
from scraper.utils.utils import add_coordinates, create_levels_table, postproces_df, ymd
from scraper.utils.utils import (
add_coordinates,
create_levels_table,
postproces_df,
write_current_date_to_file,
ymd,
)

DIR_LOGS = f"{DIR_SCRIPT}/logs/{ymd()}/" # subdivide logs by day of script execution

Expand Down Expand Up @@ -130,11 +136,11 @@ def process_data(config, dict_tables, log_main):
return dict_tables


def store(config, dict_tables, log_main, csv=True):
def store(config, dict_tables, log_main):
# refresh SQLite database
refresh_database(dict_tables, path2db=config["database"], logger=log_main)

if csv:
if config["steps"]["csv"]:
# additionally store all tables as csv files
root = config["dir_output"]
for data_name, data in dict_tables.items():
Expand Down Expand Up @@ -163,3 +169,6 @@ def store(config, dict_tables, log_main, csv=True):

store(config, dict_tables, log_main=log)
log.info("Data stored")

write_current_date_to_file(config["dir_last_updated_date"])
log.info("Refresh date updated.")
7 changes: 7 additions & 0 deletions scraper/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pandas==2.1.1
requests==2.31.0
beautifulsoup4==4.12.2
lxml==4.9.3
structlog==23.2.0
sqlalchemy==2.0.22
geopy==2.4.0
6 changes: 6 additions & 0 deletions scraper/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ def ymdhms():
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")


def write_current_date_to_file(dir):
"""Writes away current date as DD-MM-YYYY in a text file."""
with open(dir, "w") as f:
f.write(datetime.now().strftime("%d-%m-%Y"))


def chunks(lst, n):
"""Yields successive n-sized chunks from input list."""
for i in range(0, len(lst), n):
Expand Down
11 changes: 8 additions & 3 deletions webapp/01_Home.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import streamlit as st
from utils import add_socials_to_navbar
from utils import add_socials_to_sidebar

st.set_page_config(page_title="Futsal Friend", page_icon="⚽", layout="wide")

##################
########## UI ##
##################

add_socials_to_navbar()
add_socials_to_sidebar()

with st.sidebar:
with open("webapp/last_updated_date.txt", "r") as f:
last_updated = f.read()
st.markdown(f"**Last updated:** {last_updated}")

st.markdown(
"""# ⚽ Futsal Friend <span style=color:#030080><font size=4>Beta</font></span>""",
Expand All @@ -22,7 +27,7 @@
with st.expander("OK but what can I do with it?"):
st.markdown(
"""
There are four things you can do: (1) scout a potential **opponent** for a
There are four things you can do: (1) score a potential **opponent** for a
friendly match, (2) find a **team** to join as a player, (3) compare your
game **stats** to those of others, and (4) get jolly **advice** for your
team or yourself as a player. Check out the separate pages in the sidebar
Expand Down
1 change: 1 addition & 0 deletions webapp/last_updated_date.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
25-10-2023
2 changes: 1 addition & 1 deletion webapp/pages/02_🏆_Friendly_Finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
##################

st.title("Friendly Finder")
st.markdown("### Scout an opponent for a friendly")
st.markdown("### Score an opponent for a friendly")

# ask for inputs
levels = {"Courtois 💪💪💪": 1, "Casteels 💪💪": 2, "Mignolet 💪": 3}
Expand Down
2 changes: 1 addition & 1 deletion webapp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def style_table(df, drop_cols=[]):
return df


def add_socials_to_navbar():
def add_socials_to_sidebar():
"""Adds social media buttons to the Streamlit sidebar."""
st.markdown(
"""
Expand Down

0 comments on commit 8a7c7b8

Please sign in to comment.