LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs > peonuser
User Name
Password

Notices


Rate this Entry

Scraping the barrel....

Posted 05-29-2011 at 09:03 AM by peonuser
Updated 05-31-2011 at 09:22 AM by peonuser

Some code snippets to play with:

#1
----------------------------------------------------------------
Code:
#!/bin/sh
# Determine the current U.S. Terrorist Threat Advisory level, and output it to
# a serial device
#
# Written by Matt Mets in 2008
# Modified by Computothought in 2011
# This code is released into the public domain, attribution is appreciated

#### Configuration Options ##############################################

# Location of the threat alert level XML document
SRC_URL="http://www.dhs.gov/dhspublic/getAdvisoryCondition"

# Left for compatibility to original use of this code
# Serial device to output the result to (not used at this time)
# TTY_DEV="/dev/ttyS1"

#########################################################################

# Retrieve the current threat level
# We are expecting something like:
# <?xml version="1.0" encoding="UTF-8" ?>
# <THREAT_ADVISORY CONDITION="ELEVATED" />
ALERT_DOC=`wget ${SRC_URL} -q -O -`

# Do some rudimentary parsing using regular expressions to isolate the current
# threat level
# TODO: can this be done in one pass?
TMP=${ALERT_DOC#*CONDITION\=\"}
ALERT_LEVEL=${TMP%\" *}

# Convert the output into a serial command
# (The current system expects just a number 1-5)
case ${ALERT_LEVEL} in
    SEVERE)     COMMAND=5 ;;
    HIGH)       COMMAND=4 ;;
    ELEVATED)   COMMAND=3 ;;
    GUARDED)    COMMAND=2 ;;
    LOW)        COMMAND=1 ;;
esac

# If a threat level was retrieved, output it to the device
if [ -n ${COMMAND} ]
then
    # Send the command to the serial port (-n supresses the newline character)
    echo -n "Threat level is: "
    echo  ${COMMAND} ${ALERT_LEVEL} # > ${TTY_DEV}
    echo  Threat level is: ${COMMAND} ${ALERT_LEVEL} > tl
    twidge update < tl
    exit 0
else
    exit 1
fi
$ ./tlp
Threat level is: 1 LOW


#2
----------------------------------------------------------------

gwp:
Code:
# Get today's weather
ZIP=77331
elinks "http://www.weather.com/weather/print/$ZIP" > weather ; cat weather | grep Today
$ ./gwp
Today Partly Cloudy / Wind 93°/71° 10 %


#3
---------------------------------------------------------------
ghp:
Code:
# Get today's horoscope
hsign="VIRGO"
lynx -width 1000   -dump "http://www.creators.com/lifestylefeatures/horoscopes/horoscopes-by-holiday.html" > hscope ; cat hscope | grep $hsign
$ ./ghp
VIRGO (Aug. 23-Sept. 22). Pride of ownership applies to all of your possessions, and you'll take care that they sparkle, shine and really work. Tonight, you'll be reminded how much you cherish and need plenty of space to do your thing.
Posted in Uncategorized
Views 1020 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 05:17 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration