Simple question about events.

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
eirik226
Experienced User
Posts: 142
Joined: Wed Nov 07, 2012 5:22 pm

Simple question about events.

Post by eirik226 » Wed Oct 21, 2015 2:52 pm

Hello,

I've tried to search but I can't seem to figure this out, and I assume this should be really easy to do, but with my experience with python I'm just clueless.

I have sickbeard send an event to eventghost with pushbullet. The event shows up like this:

Code: Select all

    PushBullet.Note.DownloadFinished.****** (***** = the name of the show, episode and season number etc)
Now what I want is a python script that extract the episode information and displays only that in an OSD or send it to me as an event.

What I really wish to accomplish if possible is to use the information from the event to publish it on my webserver in a list over completed downloads or something like that. Is this possible to do, and if so, how would I go about doing it?

Thanks in advance!

Sem;colon
Experienced User
Posts: 609
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: Simple question about events.

Post by Sem;colon » Wed Oct 21, 2015 3:26 pm

Code: Select all

eg.event.suffix
in a script that is triggered by this Event will return Note.DownloadFinished.****** as string.
You can use

Code: Select all

 eg.event.suffix.split(".")[-1]
to get ****** only. (if there's not another dot in ******)

eirik226
Experienced User
Posts: 142
Joined: Wed Nov 07, 2012 5:22 pm

Re: Simple question about events.

Post by eirik226 » Wed Oct 21, 2015 3:48 pm

Thanks for your quick reply, but I tried all this yesterday with no luck - maybe I'm writing it wrong in my python script, will this do?

Code: Select all

Serie = eg.event.suffix

sjekk = Serie.split(".")[-1]
    
print sjekk 

I can't seem to get this to work, and would this be easy to pass on to the webserver and update a list?

Sem;colon
Experienced User
Posts: 609
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: Simple question about events.

Post by Sem;colon » Wed Oct 21, 2015 7:20 pm

Yes, well, it depends how good you are with html/javascrips

eirik226
Experienced User
Posts: 142
Joined: Wed Nov 07, 2012 5:22 pm

Re: Simple question about events.

Post by eirik226 » Thu Oct 22, 2015 1:34 pm

It seems like the code you gave me gives me the wrong information, I've tried increasing the number (1) to -1, -2, 0, 1 and 2 - and it does not work. I've googled around a bit and still unsure how to do it.

Code: Select all

PushBullet.Note.DownloadFinished [u'White Collar - 5x11 - Shot Through the Heart', None, u'ujAdLjXAeDksjAdxAd0gbA', '', '2015-10-22 01:17:17']
This is the complet event I get, and i'd like to extract White collar 5x11 and the name of the episode (The above is just an example).

Thanks for your time and help!

User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Simple question about events.

Post by Pako » Thu Oct 22, 2015 1:49 pm

eirik226 wrote:It seems like the code you gave me gives me the wrong information
eirik226 wrote:I have sickbeard send an event to eventghost with pushbullet. The event shows up like this:

Code: Select all

    PushBullet.Note.DownloadFinished.****** (***** = the name of the show, episode and season number etc)
eirik226 wrote:

Code: Select all

PushBullet.Note.DownloadFinished [u'White Collar - 5x11 - Shot Through the Heart', None, u'ujAdLjXAeDksjAdxAd0gbA', '', '2015-10-22 01:17:17']
This is the complet event I get, and i'd like to extract White collar 5x11 and the name of the episode (The above is just an example).
Incorrect information does not come from Sem;colon, but from you.
Contents of brackets, it is no event suffix, but the event payload.
You can get individual parts as eg.event.payload[0], eg.event.payload[1], and so on.

Pako

eirik226
Experienced User
Posts: 142
Joined: Wed Nov 07, 2012 5:22 pm

Re: Simple question about events.

Post by eirik226 » Thu Oct 22, 2015 2:26 pm

To be fair I didn't say he sent me the wrong information, don't get me wrong, I am very thankful for the help. I'll take a look at the payload and see what I can do.

Is it possible to "fake create" an event like that? Because this event is triggered every time a download is finished and that is usually once or twice per day, really annoying to sit and wait for it and then check if it's right or wrong.

Sem;colon
Experienced User
Posts: 609
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: Simple question about events.

Post by Sem;colon » Thu Oct 22, 2015 2:52 pm

:) Next time, please copy and past the whole event from the beginning
Sure, use:

Code: Select all

eg.TriggerEvent(prefix="PushBullet",suffix="Note.DownloadFinished",payload=[u'White Collar - 5x11 - Shot Through the Heart', None, u'ujAdLjXAeDksjAdxAd0gbA', '', '2015-10-22 01:17:17'])

eirik226
Experienced User
Posts: 142
Joined: Wed Nov 07, 2012 5:22 pm

Re: Simple question about events.

Post by eirik226 » Mon Oct 26, 2015 7:01 pm

I'll keep on asking here since I see no reason to start a new thread.

I finally got everything working (Not that hard when I got help from you guys) - the payload was the right thing to use. Now, lets say I want to use the information in that payload to populate a list or something of that sort in my webserver, how would I go about doing so?

Maybe if I save the payload to a .txt and the webserver picks up the information from there? Or is there any other "better" way to do so? Keep in mind my python skills are quite low.

Thanks in advance to you all.

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Simple question about events.

Post by krambriw » Mon Oct 26, 2015 7:42 pm

Do you need dynamic update of data or is it enough if you have to refresh/reload the html-document?


1) If you are looking for dynamic updates,i.e. the list in the web page is changed automatically without any need for reload, websocket is the right thing

2) If ok to refresh, you can update the html document directly with a python script and next refresh, you will see the new list

Unfortunately, both will require python skills, maybe the 1) would be easier since you have already touched base with some websocket stuff

eirik226
Experienced User
Posts: 142
Joined: Wed Nov 07, 2012 5:22 pm

Re: Simple question about events.

Post by eirik226 » Mon Oct 26, 2015 10:39 pm

Based on my setup at the moment, the dynamic way would be the best. I never refresh the site actually, don't think I've done it in several months (manual anyway).

I tried google and searching around this forum, but found little that could help me get started. Do you have any ideas?

As always, thanks in advance!

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Simple question about events.

Post by krambriw » Tue Oct 27, 2015 9:13 am

This is an example:

1) Add the webserver plugin to your EG config

2) Add the attached simple_list.html to the webservers 'Html documents root'

3) Create a macro and add events you like to have forwarded to your webpage like in this example
Skärmklipp.JPG
4) Now open the simple_list.html in a webbrowser and you should see the list getting populated as the events are happening (the latest is colored yellow)
Skärmklipp1.JPG
If you like to maintain another type of list, you may do it in the javascript code or you can do it in a python script before sending it to the webpage via websockets. The principal is anyway the same
simple_list.zip
(1.43 KiB) Downloaded 110 times
Last edited by krambriw on Wed Oct 28, 2015 4:57 am, edited 1 time in total.

eirik226
Experienced User
Posts: 142
Joined: Wed Nov 07, 2012 5:22 pm

Re: Simple question about events.

Post by eirik226 » Tue Oct 27, 2015 10:52 am

krambriw wrote:This is an example:

1) Add the webserver plugin to your EG config

2) Add the attached simple_list.html to the webservers 'Html documents root'

3) Create a macro and add events you like to have forwarded to your webpage like in this example
Skärmklipp.JPG
4) Now open the simple_list.html in a webbrowser and you should see the list getting populated as the events are happening (the latest is colored yellow)
Skärmklipp1.JPG
If you like to maintain another type of list, you may do it in the javascript code or you can do it in a python script before sending it to the webpage via websockets. The principal is anyway the same
simple_list.zip

God damn bro, you are the real deal! Thanks for this, I was spending my time with http://www.maraschinoproject.com/ to see if I could learn/take some code from there, the short answer: I couldn't figure out anything.

I'll take a look at this and see what I can make of it! Thanks yet again Krambriw for your awesome support. You're the best kind of people.

Post Reply