Skip to content

The Economist Magazine #101

The Economist Magazine

The Economist Magazine #101

Workflow file for this run

name: The Economist Magazine
on:
push:
branches:
- main
schedule:
- cron: '0,30 13-16 * * 4' # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule
- cron: '0 0 * * 6,1'
env:
REPLACEMENT_DATE: '2021-11-06' # For past editions, set date to, for example, '2023-01-07' || format:YYYY-MM-DD (Saturday)
# https://www.economist.com/weeklyedition/archive
ENABLE_REPLACE: 'false' # Set to 'true' to retrieve the past edition; 'false' to fetch the latest one
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Dependencies
run: |
sudo apt-get install -y xdg-utils wget xz-utils python3
sudo apt-get install -y libxcb-cursor0 libxcb-xinerama0 libegl1 libopengl0
- name: Install Calibre
run: |
sudo -v && wget -nv -O- https://download.calibre-ebook.com/linux-installer.sh | sudo sh /dev/stdin
- name: Fetch Magazine Epub
run: |
wget https://raw.githubusercontent.com/kovidgoyal/calibre/master/recipes/economist.recipe -O economist.recipe
if [[ "$ENABLE_REPLACE" == "true" ]]; then
sed -i "s/edition_date = None/edition_date = '$REPLACEMENT_DATE'/" economist.recipe
else
echo "Replacement is disabled."
fi
ebook-convert economist.recipe output.epub
ebook-meta output.epub > epub_metadata.txt
ebook-meta output.epub --get-cover=cover.jpg
- name: Extract and Print Published Date
run: |
full_published_date=$(grep "Published" epub_metadata.txt | awk -F ":" '{print $2}' | tr -d '[:space:]')
date_only=$(echo $full_published_date | cut -d'T' -f1)
echo "$date_only" > published_date.txt
- name: Convert EPUB to PDF
run: |
ebook-convert output.epub output.pdf \
--pdf-page-margin-top 30 \
--pdf-page-margin-bottom 40 \
--base-font-size 13 \
--extra-css "styles.css"
- name: Compress PDF
run: |
pip install pdf-compressor
pdf-compressor --set-api-key ${{ secrets.PDF_COMPRESSOR_API_KEY }}
pdf-compressor --compression-level low -i output.pdf
env:
PDF_COMPRESSOR_API_KEY: ${{ secrets.PDF_COMPRESSOR_API_KEY }}
- name: Create The_Economist folder
run: |
folder_name=$(cat published_date.txt)
mkdir -p The_Economist/"$folder_name"
- name: Move files to The_Economist folder
run: |
folder_name=$(cat published_date.txt)
mv output.epub The_Economist/"$folder_name"/TE_"$folder_name".epub
mv output.pdf The_Economist/"$folder_name"/TE_"$folder_name".pdf
mv cover.jpg The_Economist/"$folder_name"/
mv epub_metadata.txt The_Economist/"$folder_name"/
- name: Commit and Push changes
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add The_Economist/*
git commit -m "Add latest TE in EPUB format with cover and metadata"
git push