LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Auto reload webpage in Conky (https://www.linuxquestions.org/questions/linux-newbie-8/auto-reload-webpage-in-conky-844835/)

GJQ 11-17-2010 09:17 AM

Auto reload webpage in Conky
 
Dear LQ members,
I have just install conky to my Linux Mint 9 system.I like to know if I can set up conky to auto reload a webpage.FYI, the webpage do not have rss feed therefore I cannot set conky to use rss.Any other method are appreciated to get conky to do as per my wish

Thanks

Snark1994 11-17-2010 03:34 PM

Quote:

Originally Posted by GJQ (Post 4161931)
Dear LQ members,
I like to know if I can set up conky to auto reload a webpage.

I'm not sure if I'm misunderstanding you, but when I used conky it just displayed a list of my computer's statistics (ie. CPU usage; processes using it; current time, day and date; / disk usage; swap usage; etc.)

What are you trying to do with yours? Do you have it set up to display part of a webpage? All the statistics I had on my old conky setup updated automatically, so either I'm misunderstanding what you're trying to do, what you're trying to do works differently to what I was doing, or you've messed up your ~/.conkyrc file :P

GJQ 11-18-2010 01:03 AM

Hi Snark1994,
I have set up my conky to display things like system name,kernel,cpu and ram usage and local ip.But I have seen others displaying things like songs details and web pages using conky.Therefore I would like to know the steps needed to display information from a webpage which automatically refresh at 5 mins interval.I will search again and paste the picture,this may help in understanding what I wanted

By the way,my conky does not start automatically each time I start my pc.I do not know why,I have follow instructions from some other forum members but still not working.I will need to use terminal to call it out and each time the below error will appear in terminal

oem@oem-desktop ~ $ conky
Conky: forked to background, pid is 17876
oem@oem-desktop ~ $
Conky: desktop window (18000aa) is subwindow of root window (103)
Conky: window type - normal
Conky: drawing to created window (0x4000001)
Conky: drawing to double buffer



Appreciate all the help
Thanks

Snark1994 11-19-2010 02:06 PM

Quote:

But I have seen others displaying things like songs details and web pages using conky.
Ah right, I've done song details - I did that using the 'exec' command. The associated part of my .conkyrc is
Code:

${if_running rhythmbox}
  Track:$alignr${exec rhythmbox-client --print-playing-format %tt --no-start}
  Artist:$alignr${exec rhythmbox-client --print-playing-format %ta --no-start}
  Album:$alignr${exec rhythmbox-client --print-playing-format %at --no-start}
  Time:$alignr${exec rhythmbox-client --print-playing-format "%te / %td" -- no-start}
  ${execbar ~/coding/bash/trackElapsed}
$endif

Not sure if that helps, but that's the basic idea for adding more functionality to Conky.

Quote:

Therefore I would like to know the steps needed to display information from a webpage which automatically refresh at 5 mins interval. I will search again and paste the picture,this may help in understanding what I wanted.
Ahhh... Are you just looking for a bit of the text, then? I thought you meant showing the webpage as you would see it in your browser. Displaying part of the text from a site could be done with a batch script - use "wget" to download the website's HTML, then you can do more processing on it with the rest of the script to get what you actually want. Then finally you can use the "exec" command in your .conkyrc to display the information in your conky.

Quote:

By the way,my conky does not start automatically each time I start my pc.
Have you added it to your list of startup applications? I haven't been on Mint in a while but as far as I remember the menu layout is the same as in Ubuntu. System -> Preferences -> Startup Applications, then click 'Add' and type 'conky' as the command. That should just run the command 'conky' exactly as if you ran it in the terminal, every time you log on. It works for me!

Quote:

Each time the below error will appear in terminal

oem@oem-desktop ~ $ conky
Conky: forked to background, pid is 17876
oem@oem-desktop ~ $
Conky: desktop window (18000aa) is subwindow of root window (103)
Conky: window type - normal
Conky: drawing to created window (0x4000001)
Conky: drawing to double buffer
These aren't errors :) they're just messages telling you what it's doing. 'conky -q' will stop them printing, but it's possible it may also suppress error messages. But long story short, you don't need to worry about them, those messages occur on my machine and indicate Conky is working normally.

GJQ 11-20-2010 12:02 AM

Hi Snark1994,
Thank you for replying.

I try pasting the below code into my conky and it is working well.A few problems that I have is that I cannot close rhythmbox even when I am not using due to conky.When I take away the code from conky,then I can close rhythmbox completely.Another problem is when rhythmbox is playing,terminal show errors as per attach file.

${if_running rhythmbox}
Track:$alignr${exec rhythmbox-client --print-playing-format %tt --no-start}
Artist:$alignr${exec rhythmbox-client --print-playing-format %ta --no-start}
Album:$alignr${exec rhythmbox-client --print-playing-format %at --no-start}
Time:$alignr${exec rhythmbox-client --print-playing-format "%te / %td" -- no-start}
${execbar ~/coding/bash/trackElapsed}
$endif

Ahhh... Are you just looking for a bit of the text, then? I thought you meant showing the webpage as you would see it in your browser. Displaying part of the text from a site could be done with a batch script - use "wget" to download the website's HTML, then you can do more processing on it with the rest of the script to get what you actually want. Then finally you can use the "exec" command in your .conkyrc to display the information in your conky.

Yes,information I need is display as webpage but not all of them I need.There are only part of the information I want that hopefully can be display on conky with auto update interval of 5 mins.I do not know how to extrach the information as no knowledge of programming.Maybe if u can assist in the config and give me a step by step.Attach is link of the site http://www.onemotoring.com.sg/publis...ffic_news.html with screenshot of information I want.

As for the start up after reboot,I have added the information in Start Up.Please refer attachment.

Thank you

Snark1994 11-21-2010 09:06 AM

Quote:

Originally Posted by GJQ (Post 4165054)
I cannot close rhythmbox even when I am not using due to conky.

Sorry, I've no idea why that would be... Especially the thing about it now working even if you aren't running conky :/ does it give you an error message? Perhaps you could try running rhythmbox from a terminal, then you could see what it complains about...

Quote:

Another problem is when rhythmbox is playing,terminal show errors as per attach file.
Ah, that's 'cos I only attached the code as an example. As the error says, it can't find "~/coding/bash/trackElapsed", which is a custom bash script that I wrote to find how much of the track has played, so I can have a progress-bar-type effect.

Here it is, if you want it (I'm no bash expert, I dislike it as a language - in particular, this script has problems if the track is longer than 10 mins...):
Code:

#!/bin/bash
# ~/coding/bash/trackElapsed
timeE=$(rhythmbox-client --print-playing-format %te --no-start)
Eseconds=`expr substr $timeE 3 2`
Eseconds=${Eseconds#"0"}
Emins=`expr substr $timeE 1 1`
let "Enum=$Emins*60+$Eseconds"
timeD=$(rhythmbox-client --print-playing-format %td --no-start)
Dseconds=`expr substr $timeD 3 2`
Dseconds=${Dseconds#"0"}
Dmins=`expr substr $timeD 1 1`
let "Dnum=$Dmins*60+$Dseconds"
let "perc=100*$Enum/$Dnum"
echo $perc


Quote:

As for the start up after reboot,I have added the information in Start Up.
No idea again, sorry... I assume that if you run '/usr/bin/conky' then it does actually launch conky, but other than that I can't begin to guess what's going on. Maybe looking through the files in /var/log might help...

Quote:

I do not know how to extrach the information as no knowledge of programming.Maybe if u can assist in the config and give me a step by step.
Hm. Normally, I don't like to just write stuff for people, but if you have absolutely no knowledge of programming then it might be a bit of a tall order to ask you to learn just to do this ;) but it's a very useful skill to have, so I would consider it if I were you.


Okay, I've written something. However, I've discovered that you can't easily use conky to do what you want it to - it cuts off the output at a certain limit. So you can view the first couple of items, but not the entire list. Perhaps you need to find another programme which is designed for more heavy scripting? Anyway, I'll post what I wrote anyway, for you to see how it's done. It's written in Python v3, which you may have to install if you haven't done so already. It's not written in a brilliant way (or an ideal language for what it's doing), but was trying to make it as simple as possible so you could 'get' what it's doing.

Here goes:

Code:

#!/usr/bin/python3

from urllib.request import urlopen

webText = ""
#Open up the website into a file we can read from
filehandle = urlopen('http://www.onemotoring.com.sg/publish/onemotoring/en/on_the_roads/traffic_news.html')
#Read through each line in this file
for line in filehandle.readlines():
#Add each line to the end of our "string", webText
        webText += str(line)
#Close the file
filehandle.close()

#Remove everything before it says "S/No."
webText = webText[webText.index("S/No."):]
#Remove everything up to and including the first "<img" tag
webText = webText[webText.index("<img")+4:]
#Change it into a list of text phrases, with the text "<img" telling the
#computer to start a new phrase
webTextList = webText.split("<img")
#For each phrase in the list
for eventText in webTextList:
        try:
                #Remove everything up to and including the first "</td>"
                eventText = eventText[eventText.index("</td>")+5:]
                #We're only interested in the text between <td> and </td>
                eventText = eventText[eventText.index("<td>")+4:eventText.index("</td>")]
                #Replace the "&nbsp;" with a space.
                eventText = eventText.replace("&nbsp;"," ")
                #Output the text
                print(eventText)
        except:
                #In the case that an error occurs, it probably means
#that we've reached the end of the bit we're interested in, so we should
#quit the programme.
                break

It should work fine in the terminal, but if you try to put it into your .conkyrc with the line "${execi 300 /path/to/file.py}", then it will only display the first few items (at least, it does on my computer).

Welp, we tried ;)

GJQ 11-21-2010 10:00 AM

Dear Snark1994,
I would wish to pick up that knowledge but just do not know where to start after extensive of searching in google.

Code:

#!/usr/bin/python3

from urllib.request import urlopen

webText = ""
#Open up the website into a file we can read from
filehandle = urlopen('http://www.onemotoring.com.sg/publish/onemotoring/en/on_the_roads/traffic_news.html')
#Read through each line in this file
for line in filehandle.readlines():
#Add each line to the end of our "string", webText
        webText += str(line)
#Close the file
filehandle.close()

#Remove everything before it says "S/No."
webText = webText[webText.index("S/No."):]
#Remove everything up to and including the first "<img" tag
webText = webText[webText.index("<img")+4:]
#Change it into a list of text phrases, with the text "<img" telling the
#computer to start a new phrase
webTextList = webText.split("<img")
#For each phrase in the list
for eventText in webTextList:
        try:
                #Remove everything up to and including the first "</td>"
                eventText = eventText[eventText.index("</td>")+5:]
                #We're only interested in the text between <td> and </td>
                eventText = eventText[eventText.index("<td>")+4:eventText.index("</td>")]
                #Replace the "&nbsp;" with a space.
                eventText = eventText.replace("&nbsp;"," ")
                #Output the text
                print(eventText)
        except:
                #In the case that an error occurs, it probably means
#that we've reached the end of the bit we're interested in, so we should
#quit the programme.
                break

It should work fine in the terminal, but if you try to put it into your .conkyrc with the line "${execi 300 /path/to/file.py}", then it will only display the first few items (at least, it does on my computer).

Welp, we tried ;)[/QUOTE]




I have saved the script in my /oem/home/file.py but do I need to allow it to run as program in the permission?

A big thanks to your help.
:newbie:

Snark1994 11-21-2010 10:10 AM

First, check if you have python by running '/usr/bin/python3'
If you get a shell prompt, then it's good, if it gives an error then you need to install python (just use 'sudo apt-get install python3'). Then you can either run 'python3 /path/to/file.py' (doesn't need executable permissions) or just '/path/to/file.py' (does need executable permissions).

GJQ 11-21-2010 10:31 AM

Dear Snark1994,
It is working. Thank you so much.Attach is a screenshot of the message.Which line do I have to change if I would like to display more than 3 lines of updates.Currently only 3 lines of updates appear, I like to have around 5-10 lines of updates.As u can see from the screenshots,conky appear big when displaying the message.Is there any way to make the message display within a standard size frame?

Thanks

Snark1994 11-22-2010 11:13 AM

Quote:

Originally Posted by Snark1994 (Post 4166096)
It should work fine in the terminal, but if you try to put it into your .conkyrc with the line "${execi 300 /path/to/file.py}", then it will only display the first few items (at least, it does on my computer). Welp, we tried ;)

Like I said a few posts back, I'm very sorry, but I don't think you'll be able to get it to work with conky. Conky appears to cut text short after you've printed out a certain number of characters; this seems to be an in-built limitation. It's possible (even probable) that you could download and edit the source code of conky, then re-compile your own version of it that would allow you to use longer bits of text, but I suspect you would find it difficult to do this if you're not confident with programming.

However, with regards to the second problem, that's just because you're sending very long lines of text to Conky, so it stretches the window to include the text. You can cut a line short using python by typing:
Code:

lineOfText = lineOfText[:10]
This will cut it down to the first 10 characters. Obviously, you should change this value so that it prints enough for you to get the gist of what the line says, but not so much that it covers up your screen.

Sorry I couldn't be of more help :)

GJQ 11-23-2010 12:19 AM

Dear Snark1994,
Thanks for the reply and sorry that I have requested more from you. Anyway u have helped a lot.

Thank you


All times are GMT -5. The time now is 04:44 AM.