LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-30-2016, 09:18 PM   #1
jakfish
Member
 
Registered: Aug 2016
Posts: 52

Rep: Reputation: Disabled
Send Results of Curl Command to Notify-Send?


This is a weather script I successfully use in conky. It produces a simple weather read-out (e.g. "84F Sunny").

#!/bin/sh
#AccuWeather (r) RSS weather tool for conky
#
#USAGE: weather.sh <locationcode>
#
#(c) Michael Seiler 2007

METRIC=0 #Should be 0 or 1; 0 for F, 1 for C

if [ -z $1 ]; then
echo
echo "USAGE: weather 20902"
echo
exit 0;
fi

curl -s http://rss.accuweather.com/rss/liveweather_rss.asp\?metric\=${METRIC}\&locCode\=$1 \
| sed -n '/Currently:/ s/.*: \(.*\): \([0-9]*\)\([CF]\).*/\2°\3 \1/p'

Is it possible to use this output with notify-send? A keystroke producing a notify-send balloon with the weather read-out?

Thanks,
Jake
 
Old 08-31-2016, 10:29 AM   #2
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,491
Blog Entries: 2

Rep: Reputation: Disabled
Seems like...

Code:
#!/bin/bash

while [ 1 ]; do
     notify-send "Current Temp"    \
     "`curl -s http://rss.accuweather.com/rss/liveweather_rss.asp\?metric\=${METRIC}\&locCode\=$1     \
     | sed -n '/Currently:/ s/.*: \(.*\): \([0-9]*\)\([CF]\).*/\2°\3 \1/p'`"    \
     sleep 5m
done
would work

Last edited by dijetlo; 08-31-2016 at 10:31 AM.
 
1 members found this post helpful.
Old 08-31-2016, 11:10 AM   #3
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634

Rep: Reputation: 316Reputation: 316Reputation: 316Reputation: 316
I just wrapped the curl in a command substitution
Code:
notify-send "$(
  curl -s http://rss.accuweather.com/rss/liveweather_rss.asp\?metric\=${METRIC}\&locCode\=$1 \
  | sed -n '/Currently:/ s/.*: \(.*\): \([0-9]*\)\([CF]\).*/\2°\3 \1/p'
)"

Code:
   Command Substitution
       Command substitution allows the output of a command to replace the com‐
       mand name.  There are two forms:

              $(command)
       or
              `command`

       Bash performs the expansion by executing command and replacing the com‐
       mand substitution with the standard output of  the  command,  with  any
       trailing newlines deleted.  Embedded newlines are not deleted, but they
       may be removed during word splitting.  The command  substitution  $(cat
       file) can be replaced by the equivalent but faster $(< file).

       When  the  old-style  backquote form of substitution is used, backslash
       retains its literal meaning except when followed by $, `,  or  \.   The
       first backquote not preceded by a backslash terminates the command sub‐
       stitution.  When using the $(command) form, all characters between  the
       parentheses make up the command; none are treated specially.

       Command substitutions may be nested.  To nest when using the backquoted
       form, escape the inner backquotes with backslashes.

       If the substitution appears within double quotes,  word  splitting  and
       pathname expansion are not performed on the results.

Last edited by Sefyir; 08-31-2016 at 11:12 AM.
 
1 members found this post helpful.
Old 08-31-2016, 12:09 PM   #4
jakfish
Member
 
Registered: Aug 2016
Posts: 52

Original Poster
Rep: Reputation: Disabled
Many thanks for both of your quick responses. Before I start playing with dijetlo's suggestion, I tried Sefyir's in terminal:
notify-send "$(
curl -s http://rss.accuweather.com/rss/liveweather_rss.asp\?metric\=${METRIC}\&locCode\=$1 \
| sed -n '/Currently:/ s/.*: \(.*\): \([0-9]*\)\([CF]\).*/\2°\3 \1/p'
)"

I've also tried notify-send "$(curl -s http://rss.accuweather.com/rss/liveweather_rss.asp\?metric\=${METRIC}\&locCode\=$1 \ | sed -n '/Currently:/ s/.*: \(.*\): \([0-9]*\)\([CF]\).*/\2°\3 \1/p')"

as one command but no balloon comes up and I have to kill the curl process.

As an aside, I'm using Ubuntu Hardy 8.04 on an ancient HTC Shift X9500. That alone may make you lose all interest

Jake

Last edited by jakfish; 08-31-2016 at 12:21 PM.
 
Old 08-31-2016, 01:13 PM   #5
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634

Rep: Reputation: 316Reputation: 316Reputation: 316Reputation: 316
Quote:
I tried Sefyir's in terminal:
Which wasn't the original presentation. It was originally in a script, relying on a variable passed to it

Code:
notify-send "$(curl -s http://rss.accuweather.com/rss/liveweather_rss.asp\?metric\=${METRIC}\&locCode\=$1 \ | sed -n '/Currently:/ s/.*: \(.*\): \([0-9]*\)\([CF]\).*/\2°\3 \1/p')"
If you want to use it as a standard command, you'll need to switch that.

Code:
notify-send "$(curl -s http://rss.accuweather.com/rss/liveweather_rss.asp\?metric\=${METRIC}\&locCode\=20902 \ | sed -n '/Currently:/ s/.*: \(.*\): \([0-9]*\)\([CF]\).*/\2°\3 \1/p')"
Quote:
As an aside, I'm using Ubuntu Hardy 8.04 on an ancient HTC Shift X9500.
Using Bash version 4.3.42(1)-release, you may need to do some debugging (or upgrade)
 
1 members found this post helpful.
Old 08-31-2016, 03:32 PM   #6
jakfish
Member
 
Registered: Aug 2016
Posts: 52

Original Poster
Rep: Reputation: Disabled
The standard command worked! Bash version 3.2.39 still does the job. Many thanks to both of you. Ubuntu's weather indicator has recently stopped working for most legacy versions (NOAH has ceased support), and this old hardware couldn't take on a newer OS.

I could've run it in a conky but would've had to go back to desktop to see it. Plus, I learned much from your suggestions. The syntax remains a large mystery--I don't know how you guys do it.

Thanks for sticking with the thread and advising on antiques.

Jake
 
Old 08-31-2016, 07:03 PM   #7
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634

Rep: Reputation: 316Reputation: 316Reputation: 316Reputation: 316
Quote:
The syntax remains a large mystery--I don't know how you guys do it.
I presume you mean the sed syntax?
Best way to do that is to break up the command. Run the curl command by itself to see the output. Then, look for the output you want. In this case, it starts with a "Currently: "
I'm not great for regular expressions (which allows for refined control) but you can do a rudimentary start with grep

Code:
$ curl -s http://rss.accuweather.com/rss/liveweather_rss.asp\?metric\=${METRIC}\&locCode\=20902 | grep 'Currently: '
			<title>Currently: Partly Cloudy: 83F</title>
Feel free to look at additional weather cli commands here
https://www.commandlinefu.com/comman.../sort-by-votes

Quote:
this old hardware couldn't take on a newer OS.
Check out linux-mint mate or xfce? They may work on older / lower end hardware

https://linuxmint.com/download.php
 
Old 09-01-2016, 08:55 AM   #8
jakfish
Member
 
Registered: Aug 2016
Posts: 52

Original Poster
Rep: Reputation: Disabled
This is very helpful. I understand how the curl command calls the weather, but I'm still not certain why the grep command knows to put "Currently: " in front of the weather output.

For instance, what if you wanted to put a text output after the curl weather call, something like "So bundle up"

And is it possible to code a hard return in the notify-send balloon? Right now, my keystroke produces this output:

notify-send "$(curl -s http://rss.accuweather.com/rss/liveweather_rss.asp\?metric\=${METRIC}\&locCode\=20902 \ | sed -n '/Currently:/ s/.*: \(.*\): \([0-9]*\)\([CF]\).*/\2°\3 \1/p') uptime:`uptime | sed -re 's/^.+\up//' | sed -re 's/min.*//g'`" "`acpi 1`"

It's two lines of output and I simply put hard spaces between the weather forecast and uptime. But what if I wanted to put the forecast on one line, uptime on the second, and the battery info on a third?

Jake
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Expect script: 2 questions: Send ssh response to txt, and send command with quotes Kgeil Linux - General 6 02-19-2015 12:52 PM
Notifications don't show up (notify-send notify-osd) michal017 Linux - Desktop 0 05-06-2014 03:44 PM
TCL - Expect -- IF results Are different Then send a command ritztech Programming 1 12-11-2010 04:55 PM
How to include command results to send to admins via mail deibertine Linux - Newbie 6 07-20-2010 07:28 PM
using notify-send ashikahamed Ubuntu 0 05-02-2008 06:09 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:50 PM.

Main Menu
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