SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2012-04-11 03:53:26

celebrimbor
#! Member
From: /India/Gujarat
Registered: 2012-04-07
Posts: 57

Live updates in Conky?

I am a #! newbie and beginning to love #! and especially conky. I wanted to ask if there is any way we can view live scores in Conky or news updates from a site?


The real problem is not whether machines think but whether men do.

Offline

Help fund CrunchBang, donate to the project!

#2 2012-04-11 04:23:09

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: Live updates in Conky?

yes, you can use the execi command in conky in conjunction with curl and some line editing to get anything you want out of a website
or write a bash script and run it using execi, or a lua script and load it up into conky

the tricky part is the data extraction
need some basic knowledge of grep sed awk... that kind of thing to get the bits you want out of the html

Offline

#3 2012-04-11 06:14:57

mad_dev
Member
From: Planet Earth
Registered: 2011-11-12
Posts: 42
Website

Re: Live updates in Conky?

^in addition to the languages mrpeachy mentioned, you could also use python(if there is an API) otherwise, use grep and bash/lua...it's the logical choice.

Python example:
Write a script in python that retrieves scores/news from an online service via their respected API's

.......................
if sys.argv[1]:
    command = sys.argv[1]
    
    # API Limit
    if command == "limit":
        lim = api.rate_limit_status()
        re = lim['remaining_hits']
        print "Requests Left: ", re
        ...................................

edit .conkyrc to include the aforementioned line.
<name of script> is the name of your script

E X A M P L E
${hr}
${exec python <name of script> limit}

Crunch Out

Offline

#4 2012-04-12 07:35:38

celebrimbor
#! Member
From: /India/Gujarat
Registered: 2012-04-07
Posts: 57

Re: Live updates in Conky?

Thanks both of you! Not much familiar with grep sed awk or Python but will try. smile


The real problem is not whether machines think but whether men do.

Offline

#5 2012-04-12 17:31:04

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: Live updates in Conky?

celebrimbor wrote:

Thanks both of you! Not much familiar with grep sed awk or Python but will try. smile

those little programs can be as complicated as you want to make them
but they can also be quite easy to use, depending on what you want...

go to the page your interested in and view the page source
then work out where the info you want is
so say i wanted to keep an eye on david freese's batting average for 2012

i have this website: http://espn.go.com/mlb/player/_/id/29694/david-freese

the line in the code that i am interested in is this

</div></li></ul><div class="line-divider"></div><ul class="general-info"><li class="first">#23 3B</li><li>Bats: R, Throws: R</li><li class="last"><a href="http://espn.go.com/mlb/team/_/name/stl/st-louis-cardinals">St. Louis Cardinals</a></li></ul><ul class="player-metadata floatleft"><li><span>Birth Date</span>April 28, 1983 (Age: 28)</li><li><span>Birth Place</span>Corpus Christi, TX</li><li><span>Experience</span>3 years</li><li><span>College</span>South Alabama                 </li><li><span>Ht/Wt</span>6-2, 220 lbs.</li></ul></div><div class="player-stats"><p>2012 Season</p><table class="header-stats"><thead><th>AVG</th><th>HR</th><th>RBI</th><th>OBP</th></thead><tr><td>.429</td><td>3</td><td>10</td><td>.448</td></tr><tr class="title"><td colspan="4"><p>Career</p></td></tr><tr class="career"><td>.304</td><td>18</td><td>108</td><td>.358</td></table></div></div><div class="header-bg"></div><div class="field"></div><div class="header-overlay"></div></div><div class="player-select-header"><p>Go to</p><div class="mod-split-menu"><div class="split-select" id="24"><a class="btn-split-btn">David Freese</a></div></div></div><div class="mod-page-tabs mod-pagenav-tabs"><ul class="ui-tabs"><li class="active"><a href="http://espn.go.com/mlb/player/_/id/29694/david-freese">Player Profile</a></li><li><a href="http://espn.go.com/mlb/player/stats/_/id/29694/david-freese">Stats</a></li><li><a href="http://espn.go.com/mlb/player/splits/_/id/29694/david-freese">Splits</a></li><li><a href="http://espn.go.com/mlb/player/gamelog/_/id/29694/david-freese">Game Log</a></li><li><a href="http://espn.go.com/mlb/player/batvspitch/_/id/29694/david-freese">Bat vs Pitch</a></li><li><a href="http://insider.espn.go.com/mlb/player/scouting/_/id/29694/david-freese">Inside Edge<img style="padding-left: 3px;" src="http://a.espncdn.com/i/in.gif" alt="Insider"/></a></li><li><a href="http://espn.go.com/mlb/player/videos/_/id/29694/david-freese">Videos</a></li><li><a href="http://espn.go.com/mlb/player/photos/_/id/29694/david-freese">Photos</a></li></ul></div><div class="bg-opaque" id="my-players-table"><div class="span-6 last"><table class="player-profile-container"><tr><td class="profile-overview"><style type="text/css">.mod-game.matchup-splits.current .mod-content .overview .team .record { width: 100px !important; }.mod-game.matchup-splits.current .mod-content .game-details .venue, .mod-game.matchup-splits.current .mod-content .game-details .time{ width: 80px !important; }</style><div class="mod-container mod-game matchup-splits current mod-table mod-no-footer"><div class="mod-header"><h4>ST. LOUIS' NEXT GAME</h4></div><div class="mod-content"><div class="gradient-container"><div class="game-details"><div class="venue">Busch Stadium</div><div class="time">Fri, Apr 13<br/>3:15 PM ET</div><div class="overview"><div class="team team-away"><a href="http://espn.go.com/mlb/team/_/name/chc/chicago-cubs"><div class="logo logo-medium logo-mlb-medium mlb-medium-16"></div></a><div class="record"><h6>Chicago</h6><br/>(1-5)</div></div><div class="symbol">@</div><div class="team team-home"><a href="http://espn.go.com/mlb/team/_/name/stl/st-louis-cardinals"><div class="logo logo-medium logo-mlb-medium mlb-medium-24"></div></a><div class="record"><h6>St. Louis</h6><br/>(5-2)</div></div></div><p class="links"><a href="/mlb/conversation?gameId=320413124">Conversation &#187;</a><a href="http://www.stubhub.com/st-louis-cardinals-tickets/" onclick="this.href=this.href+'?gcid=C12289e888&keyword=David+Freese+Player+Card'" title="Tickets">Tickets &#187;</a></p></div></div><table cellspacing="1" cellpadding="3" class="tablehead"><tr class="colhead"><th>SPLITS</th><th style="text-align: right !important;">AB</th><th style="text-align: right !important;">R</th><th style="text-align: right !important;">H</th><th style="text-align: right !important;">2B</th><th style="text-align: right !important;">3B</th><th style="text-align: right !important;">HR</th><th style="text-align: right !important;">RBI</th><th style="text-align: right !important;">BB</th><th style="text-align: right !important;">AVG</th></tr><tr class="oddrow"><td>Last seven days</td><td class="textright">23</td><td class="textright">4</td><td class="textright">9</td><td class="textright">0</td><td class="textright">0</td><td class="textright">3</td><td class="textright">8</td><td class="textright">1</td><td class="textright">.391</td></tr><tr class="evenrow"><td>vs.  NL</td><td class="textright">28</td><td class="textright">5</td><td class="textright">12</td><td class="textright">0</td><td class="textright">0</td><td class="textright">3</td><td class="textright">10</td><td class="textright">1</td><td class="textright">.429</td></tr><tr class="oddrow"><td>April</td><td class="textright">28</td><td class="textright">5</td><td class="textright">12</td><td class="textright">0</td><td class="textright">0</td><td class="textright">3</td><td class="textright">10</td><td class="textright">1</td><td class="textright">.429</td></tr><tr class="evenrow player-10-29166"><td>vs. Samardzija (Car.)</td><td class="textright">2</td><td class="textright">0</td><td class="textright">0</td><td class="textright">0</td><td class="textright">0</td><td class="textright">0</td><td class="textright">1</td><td class="textright">0</td><td class="textright">.000</td></tr></table><p class="footer"><a href="/mlb/player/splits/_/id/29694/david-freese">Complete Splits &#187;</a></p></div></div></td><td class="profile-media"><style type="text/css">.videoplayer-show{ height: 217px !important; } .mod-inline.video-player.full-box { padding: 1px; }.mod-video-playlist {border-width: 0px; width: 384px; margin: 0 0 10px; 0; float: none; }.mod-video-playlist a, .mod-video-tags a { color: #225DB7; }.mod-inline.video-player.with-playlist #videoInfo { width:384px; }</style><div class="mod-inline video-player full-box with-playlist"><div class="videoplayer videoplayer-playercard_embed09" style="margin-top:0px !important;"><img src="http://a.espncdn.com/combiner/i?img=/media/motion/2012/0410/dm_120410_mlb_cardinals_reds.jpg&w=384&h=216" /></div><div id="videoInfo"></div><a id="videotoplay" style="display:none;" class="{playerType: 'playercard_embed09', playRelatedExternally: 'false'}" href="http://espn.go.com/video/clip?id=7798931">Freese, Beltran Fuel Cardinals Past Reds</a><div class="mod-video-playlist"><h6>VIDEO PLAYLIST <img width="15" height="8" alt="video" src="http://a.espncdn.com/icons/video2.png" /></h6><ul class="bulletlinks"><li class=" first active"><a class="{playerType: 'playercard_embed09', playRelatedExternally: 'false'}" href="http://espn.go.com/video/clip?id=7798931">Freese, Beltran Fuel Cardinals Past Reds</a><span style="display:none;"></span></li><li class=" next last"><a class="{playerType: 'playercard_embed09', playRelatedExternally: 'false'}" href="http://espn.go.com/video/clip?id=7599539">BBTN Express Tour - Cardinals</a><span style="display:none;"></span></li></ul></div></div>

grep is good for pulling out one specific line based on matching an expression

by doing some searching while looking at the page source i know that the above line is the only line that contains the text "general-info"

grep 'general-info'

will get just that line out of the code
but its a pretty big line... so you need to cut it up somehow

this bit of code comes right before the number i want and is unique

</thead><tr><td>

so i can use that with awk to cut the line at that point and print the second part (where the info is)

awk -F'</thead><tr><td>' '{print $2}'

then this comes straight after the number i want

</td><td>

it isnt unique but thats ok, can still use it as a place to cut the line and thsi time print the first part

awk -F'</td><td>' '{print $1}'

so in total this

curl 'http://espn.go.com/mlb/player/_/id/29694/david-freese' | grep 'general-info' | awk -F'</thead><tr><td>' '{print $2}' | awk -F'</td><td>' '{print $1}'
mcdowall@mcdowall-desktop:~$ curl 'http://espn.go.com/mlb/player/_/id/29694/david-freese' | grep 'general-info' | awk -F'</thead><tr><td>' '{print $2}' | awk -F'</td><td>' '{print $1}'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 79225  100 79225    0     0   130k      0 --:--:-- --:--:-- --:--:--  191k
.429
mcdowall@mcdowall-desktop:~$ 

.492 is the number i wanted

turned out that one wasnt too hard smile ... you have to watch out for quotes and other "magic" characters which might need escaping with \

one downside, you are relying on the website to maintain consistency in how it displays the info, redesigns usually break this kind of thing

Last edited by mrpeachy (2012-04-12 17:37:15)

Offline

#6 2012-04-30 19:23:14

celebrimbor
#! Member
From: /India/Gujarat
Registered: 2012-04-07
Posts: 57

Re: Live updates in Conky?

Hey mrpeachy,
You made it very very easy for someone nearly nescient with #! tweaking as me!
That works perfectly!


The real problem is not whether machines think but whether men do.

Offline

#7 2012-04-30 19:42:26

machinebacon
#! unstable
From: China
Registered: 2009-07-02
Posts: 6,825
Website

Re: Live updates in Conky?

It shall be possible to find a website that has a live scores RSS (same for news) and to add the line as follows to your conkyrc:

${rss http://LINKTOYOURFEED.xml 10 item_title 0}
${rss http://LINKTOYOURFEED.xml 10 item_title 1}
${rss http://LINKTOYOURFEED.xml 10 item_title 2}

Any RSS will do, you may have to play around with the item_title number, sometimes the 0 or 1 is a header.


Sweaty lads picking up the soap | I love the new "Ignore user" button

Offline

#8 2012-04-30 20:26:20

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: Live updates in Conky?

celebrimbor wrote:

Hey mrpeachy,
You made it very very easy for someone nearly nescient with #! tweaking as me!
That works perfectly!

no problem
i know that awk has line matching abilities too and im sure that it would be possible to do the same operation with just one call to awk (but im still learning how to do that smile )
didnt think about RSS feeds, would be quick and easy if you can find one with the info you want

Offline

#9 2012-04-30 22:22:55

machinebacon
#! unstable
From: China
Registered: 2009-07-02
Posts: 6,825
Website

Re: Live updates in Conky?

^ I think that's exactly the problem for live scores - it seems some of them require a subscription (how ridiculous!) though a bit of googling and collecting different RSS sources for different competitions will work out well wink

Example: german sports mag 'kicker' has a list of live scores for different competitions, separated: http://www.kicker.de/news/live-news/rss … feeds.html

So for celebrimbor the conkyrc lines for the European Champions League, updated every minute, would look somehow like this (untested) :

${rss http://rss.kicker.de/live/championsleague 1 item_title 0}
${rss http://rss.kicker.de/live/championsleague 1 item_title 1}
${rss http://rss.kicker.de/live/championsleague 1 item_title 2}
${rss http://rss.kicker.de/live/championsleague 1 item_title 3}
${rss http://rss.kicker.de/live/championsleague 1 item_title 4}

where probably the first line brings no output; or a tad easier - notice the change of item_title to item_titles to collect the first 4 most recent entries:

${rss http://rss.kicker.de/live/championsleague 1 item_titles 4}

Celebrimbor, you would just need to pick the competition in the overview (hover over RSS, then copy the link of "Direkt zum Feed") wink

Last edited by machinebacon (2012-04-30 22:28:56)


Sweaty lads picking up the soap | I love the new "Ignore user" button

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo