-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateawsproducts.sh
executable file
·67 lines (52 loc) · 2.09 KB
/
generateawsproducts.sh
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
# Define the URL
url='https://aws.amazon.com/api/dirs/items/search?item.directoryId=aws-products&sort_by=item.additionalFields.productCategory&sort_order=asc&size=500&item.locale=en_US&tags.id=!aws-products%23type%23feature&tags.id=!aws-products%23type%23variant'
# Use curl to fetch data from the URL and store it in a variable
data=$(curl -s "$url")
# Check if curl was successful
if [ $? -ne 0 ]; then
echo "Error: Failed to fetch data from the URL."
exit 1
fi
markdown_file="awsproducts.md"
markdown_content="<!--
marp: true
title: AWS Products
theme: default
class: invert
paginate: true
backgroundImage: 'linear-gradient(to bottom, #232f3e, #1a232e)'
-->
<style>
a { color: #f7a226 }
header,footer { color: #fff }
</style>
<!-- paginate: skip -->
# AWS Products
Generated from https://aws.amazon.com/products
[](https://github.com/peterneave/awsproducts)
<!-- footer: Last updated $(date) -->
---
<!-- paginate: true -->
<!-- footer: '' -->
"
echo -e "$markdown_content" > "$markdown_file"
# TOC
markdown_content="
<!-- header: '' -->
## Product Categories
"
echo -e "$markdown_content" >> "$markdown_file"
markdown_content=$(echo $data | \
jq -r '.items | group_by(.item.additionalFields.productCategory)[] | .[0] | "[\(.item.additionalFields.productCategory)](#\(.item.additionalFields.productNameLowercase | gsub(" ";"-") | gsub("\\(";"") | gsub("\\)";"") ))"' | \
sed '0~10 s/$/\n\n---\n\nProduct Categories (continued...)\n/g'
)
markdown_content+="\n\n---\n"
echo -e "$markdown_content" >> "$markdown_file"
# Data
markdown_content=$(echo $data | \
sed -e 's/\\u003cp\\u003e//g; s/\\u003c\/p\\u003e//g; s/\\r//g; s/\\n//g; s/\?[^"]*//g; s/\\u0026nbsp\;//g;' | \
jq -r '.items[] | "<!-- header: \(.item.additionalFields.productCategory) -->", "## \(.item.additionalFields.productName)","\(.item.additionalFields.productSummary)", "\(.item.additionalFields.productUrl)","\n_Launched \(.item.additionalFields.launchDate)_", "\n---" ' | \
sed '$d')
echo -e "$markdown_content" >> "$markdown_file"
echo "Markdown file '$markdown_file' has been created."