Skip to content

Commit

Permalink
ci: fix parsing (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
engeir authored Jun 23, 2024
1 parent 99b729a commit 9367f21
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
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

0 comments on commit 9367f21

Please sign in to comment.