Mercurial > ec-dotfiles
comparison moefetch.sh @ 195:652d9e268cee
test migration to printf
author | edhoprima@gmail.com <edhoprima@gmail.com> |
---|---|
date | Mon, 29 Jun 2009 11:59:49 +0000 |
parents | a8da49424468 |
children | 4d28f3a957ee |
comparison
equal
deleted
inserted
replaced
194:a8da49424468 | 195:652d9e268cee |
---|---|
58 EOF | 58 EOF |
59 } | 59 } |
60 | 60 |
61 # fatal error handler | 61 # fatal error handler |
62 Err_Fatal() { | 62 Err_Fatal() { |
63 echo "Fatal error: ${1}" | 63 printf "\nFatal error: ${1}" |
64 exit 1 | 64 exit 1 |
65 } | 65 } |
66 | 66 |
67 # help message | 67 # help message |
68 Err_Help() { | 68 Err_Help() { |
81 exit 2 | 81 exit 2 |
82 } | 82 } |
83 | 83 |
84 # generate link by transforming xml | 84 # generate link by transforming xml |
85 Generate_Link() { | 85 Generate_Link() { |
86 cd "${BASE_DIR}/temp" | 86 printf "\nFetching xml file\n" |
87 echo | 87 wget "http://${SITE}/post/index.xml?tags=${TAGS}&offset=0&limit=100000" -O "${TEMP_PREFIX}-xml" -e continue=off |
88 echo "Fetching xml file" | 88 printf "Processing XML file..." |
89 wget "http://${SITE}/post/index.xml?tags=${TAGS}&offset=0&limit=100000" -O "${SITE_DIR}-${TARGET_DIR}-xml" -e continue=off | |
90 echo "Processing XML file..." | |
91 # xslt evilry | 89 # xslt evilry |
92 xsltproc - "${SITE_DIR}-${TARGET_DIR}-xml" <<EOF | sed 's/.*\(http.*\)\(\/[a-f0-9]\{32\}\).*\.\([jp][pn]g\)/\1\2.\3/g' | grep ^http > "${SITE_DIR}-${TARGET_DIR}-list" | 90 > "${TEMP_PREFIX}-list" |
91 xsltproc - "${TEMP_PREFIX}-xml" <<EOF | sed 's/.*\(http.*\)\(\/[a-f0-9]\{32\}\).*\.\([^\.]*\)/\1\2.\3/g' | grep ^http > "${TEMP_PREFIX}-list" 2>/dev/null | |
93 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> | 92 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> |
94 <xsl:output method="xml" indent="yes"/> | 93 <xsl:output method="xml" indent="yes"/> |
95 <xsl:template match="post"> | 94 <xsl:template match="post"> |
96 <xsl:value-of select="@file_url" /> | 95 <xsl:value-of select="@file_url" /> |
97 </xsl:template> | 96 </xsl:template> |
98 </xsl:stylesheet> | 97 </xsl:stylesheet> |
99 EOF | 98 EOF |
100 NUMFILES=$(echo $(wc -l < "${SITE_DIR}-${TARGET_DIR}-list")) | 99 NUMFILES=$(echo $(wc -l < "${TEMP_PREFIX}-list")) |
101 [ "${NUMFILES}" -gt 0 ] || Err_Fatal "Error in processing list or no files can be found with specified tag(s) or site" | 100 [ "${NUMFILES}" -gt 0 ] || Err_Fatal "Error in processing list or no files can be found with specified tag(s) or site" |
102 echo "${NUMFILES} file(s) available on server" | 101 echo "${NUMFILES} file(s) available on server" |
103 #output file: ${TARGET_DIR}-list | 102 #output file: ${TARGET_DIR}-list |
104 } | 103 } |
105 | 104 |
303 | 302 |
304 echo "Tags: ${TAGS}" | 303 echo "Tags: ${TAGS}" |
305 # slash is not wanted for folder name | 304 # slash is not wanted for folder name |
306 TARGET_DIR=$(echo "${TAGS}" | sed -e 's/\//_/g') | 305 TARGET_DIR=$(echo "${TAGS}" | sed -e 's/\//_/g') |
307 SITE_DIR=$(echo "${SITE}" | sed -e 's/\/$//g;s/\//_/g') | 306 SITE_DIR=$(echo "${SITE}" | sed -e 's/\/$//g;s/\//_/g') |
307 TEMP_PREFIX="${BASE_DIR}/temp/${SITE_DIR}-${TARGET_DIR}" | |
308 } | 308 } |
309 | 309 |
310 # initialization | 310 # initialization |
311 Msg_Welcome | 311 Msg_Welcome |
312 Init "$@" | 312 Init "$@" |