Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: fix parsing #142

Merged
merged 1 commit into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions .github/workflows/url2pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,20 @@ jobs:
with:
python-version: "3.12.4"
- name: Install scripts with mise
id: scraper
run: |
curl https://mise.jdx.dev/install.sh | sh
echo "$HOME/.local/share/mise/bin" >> $GITHUB_PATH
echo "$HOME/.local/share/mise/shims" >> $GITHUB_PATH
# mise trust
# mise i
mise run recipe-scrapers:install
echo "PARSED=$(mise run recipe-scrapers:run ${{ fromJson(steps.parse.outputs.payload).Lenke }} | jq)" >> $GITHUB_ENV
echo "$PARSED"
python -m pip install recipe-scrapers
echo "PARSED=$(python ./.mise/tasks/recipe-scrapers/run ${{ fromJson(steps.parse.outputs.payload).Lenke }} | jq -c)" >> $GITHUB_ENV
- name: Set up environment variables
run: |
echo "DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
echo "ISSUEUSER=$(curl -s ${{ github.event.issue.user.url }} | jq -r '.name')" >> $GITHUB_ENV
echo "ISSUEUSER_ID=$(curl -s ${{ github.event.issue.user.url }} | jq -r '.id')" >> $GITHUB_ENV
if [[ "${{ fromJson(env.PARSED).author.name }}" == "" ]]; then echo "CREATOR=$ISSUEUSER" >> $GITHUB_ENV; else echo "CREATOR=${{ fromJson(env.PARSED).author.name }}" >> $GITHUB_ENV; fi
if [[ "${{ fromJson(env.PARSED).author.name }}" == "" ]]; then echo "CREATOR=${{env.ISSUEUSER}}" >> $GITHUB_ENV; else echo "CREATOR=${{ fromJson(env.PARSED).author.name }}" >> $GITHUB_ENV; fi
echo "CREATORTITLE=Person" >> $GITHUB_ENV
if [[ "${{ fromJson(env.PARSED).author.name }}" == "" ]]; then echo "CREATORURL=${{ github.event.issue.html_url }}" >> $GITHUB_ENV; else echo "CREATORURL=${{ fromJson(env.PARSED).author.url }}" >> $GITHUB_ENV; fi
echo "CATEGORY=${{ fromJson(steps.parse.outputs.payload).Kategori }}"
CATEGORY=${{ fromJson(steps.parse.outputs.payload).Kategori }}
echo "CATEGORY=${{ fromJson(steps.parse.outputs.payload).Kategori }}" >> $GITHUB_ENV
echo "TMPDIR=/tmp/src/$CATEGORY" >> $GITHUB_ENV
echo "TMPFILE=/tmp/src/$CATEGORY/${{ fromJson(env.PARSED).pattern }}.md" >> $GITHUB_ENV
echo "FILE_REL_TO_ROOT=src/$CATEGORY/${{ fromJson(env.PARSED).pattern }}.md" >> $GITHUB_ENV
Expand Down Expand Up @@ -108,7 +104,7 @@ jobs:
EOF
while IFS= read -r ingredient; do
echo "- $ingredient" >>"$TMPFILE"
done < <(echo "${{ fromJson(env.PARSED).recipeIngredient }}")
done < <(echo $PARSED | jq -r '.recipeIngredient[]')
cat << EOF >> "$TMPFILE"

## Steg
Expand All @@ -118,11 +114,13 @@ jobs:
while IFS= read -r step; do
echo "$count. $step">>"$TMPFILE"
((count ++))
done < <(echo "${{ fromJson(env.PARSED).recipeInstructions }}" | jq '.[][].["text"]')
done < <(echo "$PARSED" | jq -r '.recipeInstructions[].text')
cat << EOF >> "$TMPFILE"

<script type="application/ld+json">
"${{ fromJson(env.PARSED) }}"
EOF
echo "$PARSED" | jq >>"$TMPFILE"
cat << EOF >> "$TMPFILE"
</script>
EOF
cat "$TMPFILE"
Expand Down
4 changes: 3 additions & 1 deletion .mise/tasks/recipe-scrapers/run
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from recipe_scrapers import scrape_me
import argparse
import json
import re


# Get the first CLI argument
Expand Down Expand Up @@ -101,15 +102,16 @@ def update_keys(recipe: dict, key: str) -> dict:
recipe["recipeYield"] = recipe.pop(key)
return recipe


def to_kebab_case(s: str) -> str:
s = s.lower().replace(" ", "-")
# Replace æ, ø, and å with ae, o, and a
import re
s = re.sub(r"æ", "ae", s)
s = re.sub(r"ø", "o", s)
s = re.sub(r"å", "a", s)
return s


for m in methods:
recipe = print_info(m)
recipe["@context"] = "https://schema.org"
Expand Down
Loading