Skip to content

Commit

Permalink
use $GITHUB_WORKSPACE in gitub actions instead of $HOME
Browse files Browse the repository at this point in the history
  • Loading branch information
tholzheim committed Jul 16, 2024
1 parent 5bf265a commit 0510039
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 18 deletions.
13 changes: 12 additions & 1 deletion ceurws/ceur_ws.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import calendar
import datetime
import os
import re
from pathlib import Path
from typing import Optional
Expand All @@ -24,8 +25,18 @@ class CEURWS:
CEUR-WS
"""

@staticmethod
def get_home_path() -> Path:
"""
Get home path
"""
home = Path.home()
if "GITHUB_WORKSPACE" in os.environ:
home = Path(os.environ["GITHUB_WORKSPACE"])
return home

URL = "http://ceur-ws.org"
home = Path.home()
home = get_home_path()
CACHE_DIR = home.joinpath(".ceurws")
CACHE_FILE = CACHE_DIR.joinpath("ceurws.db")
CACHE_HTML = CACHE_DIR.joinpath("index.html")
Expand Down
51 changes: 34 additions & 17 deletions scripts/getData.py
Original file line number Diff line number Diff line change
@@ -1,58 +1,75 @@
import json
import logging
import os
from io import BytesIO
from pathlib import Path
from urllib.request import urlopen
from zipfile import ZipFile

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)


def download_index_pages():
print("Downloading ceur-ws volume index pages... ", end="", flush=True)
try:
url = "https://github.com/WolfgangFahl/pyCEURmake/releases/download/v0.4.0/volume_index_pages.zip"
logger.info(f"Downloading ceur-ws volume index pages from {url}...")
with urlopen(url) as resp:
zip_file = ZipFile(BytesIO(resp.read()))
target_location = Path.home().joinpath(".ceurws")
target_location = cache_path()
logger.info(f"Extracting ceur-ws volume index pages and storing them at {target_location}...")
target_location.mkdir(parents=True, exist_ok=True)
zip_file.extractall(target_location)
print("✅")
except Exception as e:
print("❌")
print(e)
logger.exception(e)


def download_volumes_json():
print("Downloading ceur-ws volumes json... ", end="", flush=True)
try:
url = "http://cvb.bitplan.com/volumes.json"
logger.info(f"Downloading ceur-ws volumes json from {url}...")
with urlopen(url) as resp:
data = json.load(resp)
target_location = Path.home().joinpath(".ceurws", "volumes.json")
target_location = cache_path() / "volumes.json"
logger.info(f"Extracting ceur-ws volumes json to {target_location}...")
target_location.parent.mkdir(parents=True, exist_ok=True)
with open(target_location, mode="w", encoding="utf-8") as fp:
json.dump(data, fp)
print("✅")
except Exception as e:
print("❌")
print(e)
logger.error(e)


def download_db():
db_file = Path.home().joinpath(".ceurws", "ceurws.db")
db_file = cache_path() / "ceurws.db"
if db_file.is_file() and db_file.exists():
print("ceurws.db already exists")
logger.info("ceurws.db already exists")
else:
print("ceurws.db missing → start download", end="", flush=True)
url = "https://github.com/WolfgangFahl/pyCEURmake/releases/download/v0.4.0/ceurws.db.zip"
logger.info(f"ceurws.db missing → start download from {url}")
try:
with urlopen(url) as resp:
zip_file = ZipFile(BytesIO(resp.read()))
target_location = Path.home().joinpath(".ceurws")
target_location = cache_path()
logger.info("Storing ceurws.db at {target_location}")
target_location.mkdir(parents=True, exist_ok=True)
zip_file.extractall(target_location)
print("✅")
except Exception as e:
print("❌")
print(e)
logger.error(e)


def get_home_path() -> Path:
"""
Get home path
"""
home = Path.home()
if "GITHUB_WORKSPACE" in os.environ:
home = Path(os.environ["GITHUB_WORKSPACE"])
return home


def cache_path() -> Path:
home = get_home_path()
return home / ".ceurws"


download_index_pages()
Expand Down

0 comments on commit 0510039

Please sign in to comment.