2020-03-26 23:48:48 +01:00
|
|
|
#!/usr/bin/env zsh
|
|
|
|
BLOCK_TIP_HEIGHT="$(curl -s https://mempool.space/electrs/mainnet/blocks/tip/height)"
|
2020-03-27 00:11:07 +01:00
|
|
|
BLOCK_HEIGHT=0
|
|
|
|
BLOCK_PER_FILE=1000
|
2020-03-26 23:48:48 +01:00
|
|
|
|
2020-03-27 00:11:07 +01:00
|
|
|
FILE_TOTAL="$(($BLOCK_TIP_HEIGHT / $BLOCK_PER_FILE))"
|
|
|
|
FILE_START="$(($FILE_TOTAL - 10))"
|
|
|
|
FILE_START=0 # initial index
|
|
|
|
FILE_STOP="${FILE_TOTAL}"
|
2020-03-26 23:48:48 +01:00
|
|
|
FILE="${FILE_START}"
|
|
|
|
|
|
|
|
echo "${BLOCK_TIP_HEIGHT} blocks"
|
2020-03-27 00:11:07 +01:00
|
|
|
echo "${BLOCK_PER_FILE} blocks per sitemap"
|
2020-03-26 23:48:48 +01:00
|
|
|
echo "${FILE_TOTAL} total sitemaps"
|
|
|
|
|
|
|
|
echo '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' > sitemap.xml
|
|
|
|
|
2020-03-27 00:11:07 +01:00
|
|
|
until [ "${FILE}" = "${FILE_STOP}" ];do
|
|
|
|
|
|
|
|
BLOCK_HEIGHT=$(($FILE * $BLOCK_PER_FILE))
|
2020-03-26 23:48:48 +01:00
|
|
|
BLOCK_HASH=$(curl -s https://mempool.space/electrs/mainnet/block-height/${BLOCK_HEIGHT})
|
|
|
|
BLOCK=$(curl -s https://mempool.space/electrs/mainnet/block/${BLOCK_HASH})
|
|
|
|
BLOCK_TIMESTAMP=$(echo "${BLOCK}"|sed -e 's/.*timestamp.://' -e 's/,.*//')
|
|
|
|
|
2020-03-27 00:11:07 +01:00
|
|
|
SITEMAP_FILE=$(printf "sitemap-%05d.xml" "${FILE}")
|
2020-03-26 23:48:48 +01:00
|
|
|
SITEMAP_LASTMOD=$(date -r "${BLOCK_TIMESTAMP}" +"%Y-%m-%dT%H:%M:%SZ")
|
|
|
|
echo "generating ${SITEMAP_FILE} from block ${BLOCK_HEIGHT}"
|
|
|
|
|
|
|
|
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">' > "${SITEMAP_FILE}"
|
|
|
|
|
2020-03-27 00:11:07 +01:00
|
|
|
BLOCK_STOP="$(($BLOCK_HEIGHT + ${BLOCK_PER_FILE}))"
|
2020-03-26 23:48:48 +01:00
|
|
|
until [ "${BLOCK_HEIGHT}" = "${BLOCK_STOP}" ];do
|
|
|
|
|
|
|
|
BLOCK_HASH=$(curl -s https://mempool.space/electrs/mainnet/block-height/${BLOCK_HEIGHT})
|
|
|
|
BLOCK=$(curl -s https://mempool.space/electrs/mainnet/block/${BLOCK_HASH})
|
|
|
|
BLOCK_TIMESTAMP=$(echo "${BLOCK}"|sed -e 's/.*timestamp.://' -e 's/,.*//')
|
|
|
|
BLOCK_LASTMOD=$(date -r "${BLOCK_TIMESTAMP}" +"%Y-%m-%dT%H:%M:%SZ")
|
|
|
|
|
|
|
|
echo '<url>' >> "${SITEMAP_FILE}"
|
|
|
|
echo "<loc>https://mempool.space/block/${BLOCK_HASH}</loc>" >> "${SITEMAP_FILE}"
|
|
|
|
echo "<lastmod>${BLOCK_LASTMOD}</lastmod>" >> "${SITEMAP_FILE}"
|
|
|
|
echo '</url>' >> "${SITEMAP_FILE}"
|
|
|
|
|
2020-03-27 00:11:07 +01:00
|
|
|
((BLOCK_HEIGHT++))
|
2020-03-26 23:48:48 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
echo '</urlset>' >> "${SITEMAP_FILE}"
|
2020-03-27 00:11:07 +01:00
|
|
|
gzip -f "${SITEMAP_FILE}"
|
|
|
|
SITEMAP_FILE="${SITEMAP_FILE}.gz"
|
2020-03-26 23:48:48 +01:00
|
|
|
|
|
|
|
echo '<sitemap>' >> sitemap.xml
|
|
|
|
echo "<loc>https://mempool.space/${SITEMAP_FILE}</loc>" >> sitemap.xml
|
|
|
|
echo "<lastmod>${SITEMAP_LASTMOD}</lastmod>" >> sitemap.xml
|
|
|
|
echo '</sitemap>' >> sitemap.xml
|
|
|
|
|
2020-03-27 00:11:07 +01:00
|
|
|
((FILE++))
|
2020-03-26 23:48:48 +01:00
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
echo '</sitemapindex>' >> sitemap.xml
|