Browse Source

sde-create-package: began quest to parse freshmeat's xml

user/chris/old/ruby
Alejandro Mery 15 years ago
parent
commit
24a88dbce0
1 changed files with 22 additions and 3 deletions
  1. +22
    -3
      lib/sde-package/hives/freshmeat2

+ 22
- 3
lib/sde-package/hives/freshmeat2

@ -13,7 +13,6 @@
# GNU General Public License can be found in the file COPYING.
# --- SDE-COPYRIGHT-NOTE-END ---
#Description: Generates .desc files from the data in freshmeat
#Alias: fm2
@ -31,8 +30,14 @@ EOT
exit 2
}
clean_xml() {
sed -e 's,^[ \t]\+,,' |
tr -d '\r\n' |
sed -e 's,>,>\n,' -e 's,\(</[^>]\+>\),\1\n,g' -e 's,>\(<[^/]\),>\n\1,g'
}
fm_exists() {
local uri="http://freshmeat.net/projects/$name"
local uri="http://freshmeat.net/projects/$1"
local response="$(curl -s -I "$uri" | tr -d '\r' | head -n 1)"
if [ "$response" = "" ]; then
@ -47,6 +52,20 @@ fm_exists() {
return 1
}
fm_fetch_xml() {
local uri="http://freshmeat.net/projects/$1.xml?auth_code=$2"
curl -s "$uri" | clean_xml
}
fm_parse_xml() {
local l=
while read l; do
tag=$(echo "$l" | sed -e 's,<\([^ >]\+\)[ >].*,\1,' -e 's,/,-,')
value=$(echo "$l" | sed -n -e 's,.*>\([^<]*\)<.*,\1,p')
echo "$tag: $value"
done
}
shortopts='u:'
longopts=
options=$(getopt -o "$shortopts" -l "$longopts" -- "$@")
@ -72,7 +91,7 @@ done
name="$1"
if fm_exists "$name"; then
echo "$name: OK"
fm_fetch_xml "$name" "$authcode" | fm_parse_xml
else
echo "$name: NOT FOUND"
fi

Loading…
Cancel
Save