Hi.

I would like to use conky to display EPG on me desktop.

I found a cool website: http://nazham.com/2009/07/26/how-to-enhance-your-linux-desktop-with-conky/
and the owner, Mahzan Musa was very kind to provide his code. THANK YOU
Unfortunately his html epg source is completely different from mine and the code was not so easy to understand for a 1st starter.

After a week of reading and googling I was able to make my first python code:

import urllib

texto = urllib.urlopen('http://192.168.1.6:8008/schedule.html?channel=120').read()
index = texto.find('<td class="topaligned "><div class="withmargin nowrap"')
h1 = index+55
index = texto[h1:].find('><span class="title">')
pi1 = h1 + index + 21
index = texto[pi1:].find('</span><br')
pf1 = pi1 + index
index = texto[pf1:].find('<td class="topaligned "><div class="withmargin nowrap"')
h2 = pf1+index+55
index = texto[h2:].find('><span class="title">')
pi2 = h2 + index + 21
index = texto[pi2:].find('</span><br')
pf2 = pi2 + index
print texto[h1:h1+19]+'   '+texto[pi1:pf1]+'\n'+texto[h2:h2+19]+'   '+texto[pi2:pf2]

this is the output

08:00 PM - 08:30 PM   As Princesas GÚmeas do Planeta Maravilha T.1 Ep.2
08:30 PM - 09:00 PM   As Princesas GÚmeas do Planeta Maravilha T.1 Ep.3

It reads the html and print the 1st 2 shows, time and name. It's what I was looking for, now I can display this info with conky.

Now, I have a problem, I want more the one channel( 120 in the url on my code). I could copy paste and change the channel number and save n copies of it, but it's not the best option.

I would like to use a argument when running the py, like python epg.py channel number .

What do I have to change/implement to achieve this?

Use a function.

def download_url(channel_num):
    url = 'http://192.168.1.6:8008/schedule.html?channel=%s' % (channel_num)
    texto = urllib.urlopen(url).read()
    index = texto.find('<td class="topaligned "><div class="withmargin nowrap"')
    h1 = index+55
    index = texto[h1:].find('><span class="title">')
    pi1 = h1 + index + 21
    index = texto[pi1:].find('</span><br')
    pf1 = pi1 + index
    index = texto[pf1:].find('<td class="topaligned "><div class="withmargin nowrap"')
    h2 = pf1+index+55
    index = texto[h2:].find('><span class="title">')
    pi2 = h2 + index + 21
    index = texto[pi2:].find('</span><br')
    pf2 = pi2 + index
    print texto[h1:h1+19]+'   '+texto[pi1:pf1]+'\n'+texto[h2:h2+19]+'   '+texto[pi2:pf2]

if __name__ == '__main__':
    download_url("120")
    download_url("121")

Edited 6 Years Ago by woooee: n/a

Thnak you for the quick reply.

after adding import urlib before the code, it works.

The output will come just as one, and I wont be able to give a different position per channel in conky.
I need to get one output per channel so that it can be independently positioned.

If the code is called epg i need to use it like this

python epg 120

then

python epg 150, etc

I hope you can help me on this. sorry for all the trouble.

thx in advance,

cheers

Looking at woooee i was able to understand how def worked and then I took a look at Mahzan Musa code and gto what I was looking for:

import sys
import urllib

def download_url(channel_num):
    url = 'http://192.168.1.6:8008/schedule.html?channel=%s' % (channel_num)
    texto = urllib.urlopen(url).read()
    index = texto.find('<td class="topaligned "><div class="withmargin nowrap"')
    h1 = index+55
    index = texto[h1:].find('><span class="title">')
    pi1 = h1 + index + 21
    index = texto[pi1:].find('</span><br')
    pf1 = pi1 + index
    index = texto[pf1:].find('<td class="topaligned "><div class="withmargin nowrap"')
    h2 = pf1+index+55
    index = texto[h2:].find('><span class="title">')
    pi2 = h2 + index + 21
    index = texto[pi2:].find('</span><br')
    pf2 = pi2 + index
    print texto[h1:h1+19]+'   '+texto[pi1:pf1]+'\n'+texto[h2:h2+19]+'   '+texto[pi2:pf2]+'\n'+'\n'
 
if __name__ == '__main__':    
    if len(sys.argv) == 2:
	param = str(sys.argv[1]).strip()
	download_url(param)
    else:
	print 'No channel specified.'

Thank you very much for all the help!!!!

Cheers

This question has already been answered. Start a new discussion instead.