Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

How to parse the payload ?

If you have a question or need help, this is the place to be.
Post Reply
Kleriker
Posts: 14
Joined: Mon Jan 03, 2011 5:39 pm

How to parse the payload ?

Post by Kleriker »

Hey guys,

i am not new to eventghost but i am new to scripting with python :lol:. The last days i worked hard on my home-automation and i am now at the point, where i want to get my call monitor (janrufmonitor) involved. I am now able the get this data sent to EG as payload: "MSN / Callername / Callernumer / time / date". But now i reached the end of my skills, because i have no idea how to parse the payload to assign each information to its own variable.

Therefore i really hope for your help.

Best regards,
Alex

PS: Sorry for my bad english skills - it is not my native language :mrgreen:
miljbee
Experienced User
Posts: 146
Joined: Fri Mar 27, 2009 1:29 pm
Location: Orl├®ans, France

Re: How to parse the payload ?

Post by miljbee »

eg.event.payload will give you the payload. You can then parse it with str.find or str.split, 
miljbee
TCP Events : A Better Network Event Sender/Receiver Plugin.
The Network Event Sender/Receiver in C#
Get events in EG from Google Calendar.
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: How to parse the payload ?

Post by krambriw »

A sample code I believe should work
Best regards

Code: Select all

# "MSN / Callername / Callernumer / time / date"

p = eg.event.payload
p = p.split('/')
caller_msn = p[0].strip()
caller_name = p[1].strip()
caller_nbr = p[2].strip()
caller_time = p[3].strip()
caller_date = p[4].strip()
Kleriker
Posts: 14
Joined: Mon Jan 03, 2011 5:39 pm

Re: How to parse the payload ?

Post by Kleriker »

Thank you very much for your help :)

The Final Script looks like this (a friend was able to help me):

Code: Select all

s = eg.event.payload
res = s[0].split(',')
msn = res[0].split('/')[0]
name = res[1].strip()
phone = res[2].split('/')[1].strip()
date = res[2].split('/')[2]
time = res[2].split('/')[3]
Best regards,
Alex
Kleriker
Posts: 14
Joined: Mon Jan 03, 2011 5:39 pm

Re: How to parse the payload ?

Post by Kleriker »

Hi krambriw,

i have noticed that your script is working a bit better, so i want to use it. But there is one problem, because the actual payload looks like this:

Code: Select all

[u'MSN/Name/Number/Date/Time']
The problem are the "[ ]". How do i get rid of them with your script ?

Best regards,
Alex
miljbee
Experienced User
Posts: 146
Joined: Fri Mar 27, 2009 1:29 pm
Location: Orl├®ans, France

Re: How to parse the payload ?

Post by miljbee »

[] is for python lists
["test"] is a list containing one string (which is also a list, but that's another story)

Code: Select all

myList=["test"]
myString=myList[0]
u'test' is a unicode string
you can switch between both if needed :
str(u'myUnicodeString')
unicode("myString")
miljbee
TCP Events : A Better Network Event Sender/Receiver Plugin.
The Network Event Sender/Receiver in C#
Get events in EG from Google Calendar.
Kleriker
Posts: 14
Joined: Mon Jan 03, 2011 5:39 pm

Re: How to parse the payload ?

Post by Kleriker »

Hi miljbee,

thank you for your help, but obviously i am to stupid, to bring your explaination into my script. Can you help me please ?
I want to get rid off the [] and " u' " and the " ' " at the end.


Best regards,
Alex

EDIT:

Never mind - it worked :) Thank you !

Code: Select all

z = eg.event.payload
p = z[0]
p = p.split('/')
msn = p[0].strip()
name = p[1].strip()
phone = p[2].strip()
date = p[3].strip()
time = p[4].strip()
Post Reply