summaryrefslogtreecommitdiffstats
path: root/HTML/Final/sneed/purchase/mkpages.sh
blob: 63e56a7c52b645d761f70dc195ad7f07aad213f6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
cp ../store.html.orig ../store.html
cp ../purchase-form.html.orig ../purchase-form.html
while IFS= read -r line
do
    name=$(echo "$line"|jq .name|tr -d '"')
    AI=$(echo "$line"|jq .ai|tr -d '"')
    imageLocation=$(echo "$line"|jq .location|tr -d '"')
    imageName=$(echo "$line"|jq .image|tr -d '"')
    #imageName=$(echo "$name"|tr ' ' '-'|sed -e 's/$/.webp/g')
    pageName=$(echo "$name"|tr ' ' '-'|tr -d "'"|sed -e 's/$/.html/g')
    price=$(echo "$line"|jq .price|tr -d '"')
    desc=$(echo "$line"|jq .desc|tr -d '"')
    if [ "$AI" = "true" ]
        #if [ "false" = "true" ]
    then
        aitext=$(./textgen.py 200 "$desc")

        while [[ pass -eq 0 ]]
        do
            aitext=$(./textgen.py 200 "$desc")
            if [[ "$aitext" == *"/"* ]]
            then
                echo "detected a slash"
                pass=0
            elif [[ "$aitext" == "" ]]
            then
                echo "text was empty"
                pass=0
            elif [[ "$aitext" = *"http"* ]]
            then
                echo "detected an http url"
                pass=0
            else
                pass=1
            fi
        done

        desc="<span class=ai title='This text is generated by a bot to cut down on development time! Any mistakes or insanity in the text should be taken with that fact in mind. See the About section for more information.'>$aitext<\/span>"
        echo "$desc"
    fi
    cp -v "template.html" "$pageName"
    sed -i -e "s/;IMG;/..\/assets\/$imageLocation\/$imageName/g" "$pageName"
    sed -i -e "s/;TITLE;/$name/g" "$pageName"
    sed -i -e "s/;PRICE;/$price/g" "$pageName"
    #sed -i -e "s/;DESC;/$desc/g" "$pageName"
    perl -pe "s/;DESC;/$desc/" -i "$pageName" || sed -i -e "s/;DESC;/$desc/g" "$pageName" || sed -i -e "s/;DESC;/$name/g" "$pageName"

    sed -i -e "/<!--Items-->/a <a href=\"purchase/$pageName\">\n        <figure>\n            <img alt=\"an image of $name\" src=\"assets/$imageLocation/$imageName\">\n            <figcaption>$name<\/figcaption>\n        <\/figure>\n    <\/a>\n    " ../store.html
    sed -i -e "/<!--Items-->/a <option value=\"$name\"><\/option>\n " ../purchase-form.html

done < "entries.json"