[CentralOH] Hurlama: Python Embedded in Shell Script

jep200404 at columbus.rr.com jep200404 at columbus.rr.com
Wed Mar 25 17:47:29 CET 2015


Check out the redacted shell script below 
for how it has Python code embedded in it.
A sample invocation could be:

    foo 'http://wx.com/data/{year:04d}/xyz-{year:04d}{month:02d}/.zip'

#!/usr/bin/env bash
...
ymd=`date '+%Y %m %d'`
# ymd='2013 06 03'

echo "$ymd:" | tr -d '\n'
for arg in "$@"; do
    echo -n " '$arg'"
done
echo
url_format="$1"
...
year=`echo $ymd | awk '{print $1}'`
# echo $year
month=`echo $ymd | awk '{print $2}'`
# echo $month
day=`echo $ymd | awk '{print $3}' | sed -e 's/^0//'`
...
url=`python - "$url_format" "$year" "$month" "$day" <<EOF
from __future__ import print_function

import sys

url_format, year, month, day = sys.argv[1:]
print(url_format.format(year=int(year), month=int(month), day=int(day)))
EOF
`
echo "url='$url'"
wget -O - "$url" 2>wget.stderr | md5sum >"$day"
...

Are you hurling yet? 


More information about the CentralOH mailing list