muhkuh0815 / SiriProxy-TV

Siriproxy Plugin which reads the Austrian TV-Programm - in german
5 stars 2 forks source link

French TV #1

Closed Doriginal closed 12 years ago

Doriginal commented 12 years ago

Good evening,

Your plugin is very interesting. I try to modify it to read the french TV program chains I modified as below code, but I get an error when I ask siri control

class SiriProxy::Plugin::TV < SiriProxy::Plugin

def initialize(config)
    #if you have custom configuration options, process them here!
end
def doc
end
def docs
end
def dob
end

def tvprogramm(doc) # reading whats playing now - Austrian channels begin doc = Nokogiri::XML(eat("http://www.texxas.de/tv/oesterreichJetzt.xml")) return doc rescue doc = "" end end

def tvprogrammabend(doc) # reading whats playing in the evening (20:15) - Austrian channels begin doc = Nokogiri::XML(eat("http://www.programme-television.org/programme-tv-journee.xml")) return doc rescue doc = "" end end

def tvprogrammsat(dob) # reading whats playing now - 3SAT begin dob = Nokogiri::XML(eat("http://www.texxas.de/tv/spartensenderJetzt.xml")) return dob rescue dob = "" end end

def tvprogrammsatabend(dob) # reading whats playing in the evening (20:15) - 3SAT begin dob = Nokogiri::XML(eat("http://www.programme-television.org/programme-tv-journee.xml")) return dob rescue dob = "" end end

def cleanup(doc) doc = doc.gsub(/<\/?[^>]*>/, "") return doc end

def dosund(dos) if dos["&"] dos["&"] = "&" end return dos end

TV Programm Abend - TV Programm Evening - all channels

listen_for /(TV|télé|spielers).*(prime Time|soirée|soir)/i do doc = tvprogrammabend(doc) dob = tvprogrammsatabend(dob) if doc == NIL or doc == "" say "Es gab ein Problem beim Einlesen des Fernsehprogramms!" elsif dob == NIL or dob == "" say "Es gab ein Problem beim Einlesen des Fernsehprogramms!" else doc.encoding = 'utf-8' dob.encoding = 'utf-8' docs = doc.xpath('//title')
dobs = dob.xpath('//title')
i = 1 while i < docs.length dos = docs[i].to_s dos = cleanup(dos) doss = dos[0,8] if doss == "France 2" dos = dosund(dos) fr2 = dos elsif doss == "France 3" dos = dosund(dos) fr3 = dos elsif doss == "Canal pl" dos = dosund(dos) canal = dos elsif doss == "France 5" dos = dosund(dos) fr5 = dos elsif doss == "France 4" dos = dosund(dos) fr4 = dos elsif doss == "Direct 8 " dos = dosund(dos) dir8 = dos elsif doss == "Direct S" dos = dosund(dos) dirs = dos else end i += 1 end i = 1 while i < dobs.length dos = dobs[i].to_s dos = cleanup(dos) doss = dos[0,3]

        if doss == "TF1"
            dos = dosund(dos)
            tf1 = dos
        else
        end
        i += 1
    end
        say "", spoken: "Es spielt gerade."

        object = SiriAddViews.new
        object.make_root(last_ref_id)
        answer = SiriAnswer.new("TV Programm - aktuell", [
            SiriAnswerLine.new(fr2), 
            SiriAnswerLine.new(fr3), 
            SiriAnswerLine.new(canal), 
            SiriAnswerLine.new(fr5),
            SiriAnswerLine.new(tf1), 
            SiriAnswerLine.new(dir8), 
            SiriAnswerLine.new(dirs),  
            SiriAnswerLine.new(fr4)
            ])
        object.views << SiriAnswerSnippet.new([answer])
        send_object object

    end    
request_completed

end

I have this error:

[Info - Plugin Manager] Plugin Crashed: Unknown class NilClass. Try using :convert_unknown_to_string if you want to use unknown object types!

Can you help me? Thanks

muhkuh0815 commented 12 years ago

your xml is different from the texxas one ....

so you need to search for the channel AND the right time, or display the whole day

in mine i just had one entry per channel so its a lot easier

and in what line was the error ?

Doriginal commented 12 years ago

The error is in terminal when I ask siri tv program.

So with my xml can not?

muhkuh0815 commented 12 years ago

yours

TF1 | 01:35 : Affaires non classées (0h50) Série policière TF1 | 02:25 : Météo (0h05) Météo TF1 | 02:30 : La preuve par quatre (0h45) Série humoristique TF1 | 03:15 : La preuve par quatre (0h50) Série humoristique

mine:

ARD: Das Frühlingsfest der Überraschungen ZDF: Das Duo SAT.1: Das Hundehotel
muhkuh0815 commented 12 years ago

when you find a xml which shows only the current films, it would be easier

Doriginal commented 12 years ago

ok thanks i try that

Doriginal commented 12 years ago

Thank you for your advice, I understand your code.

http://img11.hostingpics.net/pics/468072Photo180312002550.png

It is not easy to find RSS feed with a lot of info in "title" I have not found one for TV programs in French

thank you again

muhkuh0815 commented 12 years ago

you can use your xml and rewrite the parsing part to show every line, or make some time checks (probably not that easy) to show only one entry after the actual time. but im not that good in xml parsin ....

Doriginal commented 12 years ago

Me neither I'm a novice in the field.

how could your read two tag? title + description

I tried but without success

muhkuh0815 commented 12 years ago

http://lmgtfy.com/?q=xml+parsing+ruby :-)

i prefer json files so you need to google yourself ...

Doriginal commented 12 years ago

ok thanks i look that,

Yes I saw a plugin with .json files, but how to create them.

muhkuh0815 commented 12 years ago

same thing, you need to find them :-) some sites give you an option to get xml or json

Doriginal commented 12 years ago

good evening,

I found how to display the different times of my xml

http://img11.hostingpics.net/pics/173883Photo190312225051.png http://img11.hostingpics.net/pics/659756Photo190312225115.png

Will you look at the code that I modified? I just send it to you

Thank you again for your help.

Doriginal commented 12 years ago

One last question.

In the plugin code, it indicates the character was searching the xml. If characters are found, siri displays. But if the characters are not found, an error "invalid string ..." appears.

How would you add a code, which will allow to pass to the next line if it can not find the characters instead of the error "invalid string ..."

Thanks

muhkuh0815 commented 12 years ago

there are many ways, you can do a simple if str == nil.

or you probably can use the rescue command

Doriginal commented 12 years ago

Thank you i look that

Doriginal commented 12 years ago

i have tried different way, but no result :(

while i < docs.length dos = docs[i].to_s dos = cleanup(dos) doss = dos[0,14] if doss == NIL

No work

                         if doss == "France 2 | 19:" or doss == NIL
            dos = dosund(dos)
            fr2 = dos

no work

That not easy

Doriginal commented 12 years ago

hello,

Thank you for all the help you provided me, a friend helped me to finish, thank you to him.

The aim of the program tv is: . display programs of early evening (20h to 22h) . display programs of the second part of the evening (22h to 00h)

example:

http://img15.hostingpics.net/pics/970555Photo210312214100.png http://img15.hostingpics.net/pics/543696Photo210312214159.png

Plugin no longer crashes if no characters have found, it continues and displays what it finds.

Thank you again, your code base was very good, it helped me a lot.

moieza commented 12 years ago

Hi ! can you share your code Doriginal ?

moieza commented 12 years ago

or a little help..