XPath Xpression for XML-RPC - xpath

I have following XMLRPC response
<value><struct>
<member><name>dedicatedAccountID</name><value><i4>1</i4></value></member>
<member><name>dedicatedAccountValue1</name><value><string>0</string></value></member>
<member><name>expiryDate</name><value><dateTime.iso8601>99991231T00:00:00+1200</dateTime.iso8601></value></member>
</struct></value>
<value><struct>
<member><name>dedicatedAccountID</name><value><i4>2</i4></value></member>
<member><name>dedicatedAccountValue1</name><value><string>15635</string></value></member>
<member><name>expiryDate</name><value><dateTime.iso8601>99991231T00:00:00+1200</dateTime.iso8601></value></member>
</struct></value>
<value><struct>
<member><name>dedicatedAccountID</name><value><i4>3</i4></value></member>
<member><name>dedicatedAccountValue1</name><value><string>0</string></value></member>
<member><name>expiryDate</name><value><dateTime.iso8601>99991231T00:00:00+1200</dateTime.iso8601></value></member>
</struct></value>
I want to get value of dedicatedAccountValue1 where member name is dedicatedAccountID its value is 1.
Regards,
imran

//value/struct[member[name = 'dedicatedAccountID' and value/* = '1']]/member[name = 'dedicatedAccountValue1']/value/*

//Struct[member/name='dedicatedAccountID' and
member/value/i4='1']/member[name='dedicatedAccountValue1']/value
Try this. Not tested

Related

AttributeError: 'DataFrame' object has no attribute 'as_matrix'

I am getting the following error:
AttributeError: 'DataFrame' object has no attribute 'as_matrix'
The code that produces the error:
def plot_fruit_knn(X, y, n_neighbors, weights):
X_mat = X[['height', 'width']].as_matrix()
y_mat = y.as_matrix()
Can anyone help me spot the problem?
as_matrix() is depreceated you can use Dataframe.to_numpy() instead
y_mat = y.to_numpy()
I had the same issue, and I used .to_numpy()
Use
y_mat = y.to_numpy()
instead

send binary with sendDocument in python-telegram-bot

this work :
mybot.sendDocument(chat_id=chatid, document=open('bla.pdf', rb'))
But if I did before :
with open('bla.pdf', 'rb') as fp:
b = fp.read()
I can't do :
mybot.sendDocument(chat_id=chatid, document=b)
The error is :
TypeError: Object of type 'bytes' is not JSON serializable
I use python 3.5.2 win or linux
Thanks for answer
sorry I didn't see your answer.
My trouble was I wanted to send a downloaded document, not a document on disk.
I resolved it like this :
mybot.sendDocument(chat_id=chatid,document=io.BytesIO(self.downloaded_file))
Try to send just a file object:
mybot.sendDocument(chat_id=chatid, document=open('bla.pdf', 'rb'))

Get total_rows from couchbase ruby library

When having a look to my couchbase view using the web api I got this result:
{
"total_rows": 18279385,
"rows": []
}
But I'm using the ruby couchbase gem like follows
require 'couchbase'
c = Couchbase.connect(...)
sources = c.design_docs['Data']
pp sources.All
#<Couchbase::View:47373151271840 #endpoint="_design/Data/_view/All" #params={:connection_timeout=>75000}>
But how do I get the total_rows from the view? I've found few documentation which relates to a Method "total_rows" but that doesn't seem to be present at this point.
The comment of Anthony solves the problem:
sources.All(limit: 0).fetch.total_rows
Use limit: 0 for speeding up the request.

Ruby Hash and Tumblr API

controller page, Json output from api
I'm trying to display posts from the users tumblr account on my view page using ruby. I have never done anything with api's before. I'm trying to use Hash tables. my controller code is as such:
#Posts = client.posts"zombieprocess1.tumblr.com"
on my view page using html I have
<%=Posts%>
the response is such
{"blog"=>{"title"=>"Untitled", "name"=>"zombieprocess1", "total_posts"=>1, "posts"=>1, "url"=>"URL", "updated"=>1478191052, "description"=>"", "is_nsfw"=>false, "ask"=>false, "ask_page_title"=>"Ask me anything", "ask_anon"=>false, "followed"=>false, "can_send_fan_mail"=>true, "is_blocked_from_primary"=>false, "share_likes"=>true, "likes"=>1, "twitter_enabled"=>false, "twitter_send"=>false, "facebook_opengraph_enabled"=>"N", "tweet"=>"N", "facebook"=>"N", "followers"=>0, "primary"=>true, "admin"=>true, "messages"=>0, "queue"=>0, "drafts"=>0, "type"=>"public", "reply_conditions"=>3, "subscribed"=>false, "can_subscribe"=>false}, "posts"=>[{"blog_name"=>"zombieprocess1", "id"=>152689921093, "post_url"=>"URL", "slug"=>"", "type"=>"photo", "date"=>"2016-11-03 16:37:32 GMT", "timestamp"=>1478191052, "state"=>"published", "format"=>"html", "reblog_key"=>"NCDqGTzW", "tags"=>[], "short_url"=>"URL", "summary"=>"", "recommended_source"=>nil, "recommended_color"=>nil, "followed"=>false, "liked"=>true, "note_count"=>1, "caption"=>"", "reblog"=>{"tree_html"=>"", "comment"=>""}, "trail"=>[], "image_permalink"=>"url", "photos"=>[{"caption"=>"", "alt_sizes"=>[{"url"=>"URL", "width"=>400, "height"=>544}, {"url"=>"URL", "width"=>250, "height"=>340}, {"url"=>"URL", "width"=>100, "height"=>136}, {"url"=>"URL", "width"=>75, "height"=>75}], "original_size"=>{"url"=>"URL", "width"=>400, "height"=>544}}], "can_like"=>false, "can_reblog"=>true, "can_send_in_message"=>true, "can_reply"=>true, "display_avatar"=>true}], "total_posts"=>1}
I have tried many different formats and can't seem to just get the post url. My thought is to get the post_url and embed each of them so it shows as it would in tumblr on my webpage. Can anyone help me?
Try this:
#posts['posts'].first['post_url']
Or if your response contains more than one post you can return them all like this:
(0...#posts['total_posts']).map { |i| #posts['posts'][i]['post_url'] }
EDIT: Fixed capitalization in second line of code. I assume you are using lowercase variable as per Ruby convention, '#posts'. If not, you should change to a lowercase variable as this may be confusing something.

How to extract foursquare2 gem results (Hashie::Mash)

I'm facing a problem while trying to extract fields of foursquare2 gem response. Here's my code:
require 'foursquare2'
client = Foursquare2::Client.new(:client_id => 'XYZ', :client_secret => 'XYZ')
tips = client.venue_tips('4d169843b15cb1f7f4c4ae21')
And then I got the result:
#<Hashie::Mash count=8 items=[#<Hashie::Mash canonicalUrl="https://foursquare.com/item/4f689747e4b04ab624cce6d3" createdAt=1332254535 done=#<Hashie::Mash count=1> id="4f689747e4b04ab624cce6d3" lang="pt" likes=#<Hashie::Mash count=2 groups=[#<Hashie::Mash count=2 items=[#<Hashie::Mash bio="" contact=#<Hashie::Mash> firstName="Pedro" gender="male" homeCity="Recife, Brasil" id="19761425" lastName="T." photo="https://is1.4sqi.net/userpix_thumbs/G5R14BT031K2B2AX.jpg" tips=#<Hashie::Mash count=25>>, #<Hashie::Mash bio="" contact=#<Hashie::Mash> firstName="Nat\u00E1lia" gender="female" homeCity="Recife, Brasil" id="12706383" lastName="S."
photo="https://is0.4sqi.net/userpix_thumbs/UF0Q0OZFWNQLXRFG.jpg" tips=#<Hashie::Mash count=1>>] type="others">] summary="2 likes"> text="Nova padaria com bons produtos, destaque para as formadas de p\u00E3o \u00E0 tarde."
I'd like to have something as tips.firstName to get these values, but it doesn't work. Should I prefer the REST API?!
Thank you in advance, guys.
Edited after comments
The solution I did following the suggestion provided:
tips.groups[0].items.each{|i| puts i.firstName}
But it's not working. I just got the error: data_scraping_fq.rb:16:in <main>': undefined method[]' for nil:NilClass (NoMethodError)
tips.firstName won't work when you're using the venues/tips endpoint. Take a look at the JSON response when you use the Foursquare API explorer and you'll see that to get the tip submitter's first name, you need to look at `tips.items

Resources