Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#171 2013-01-31 22:29:04

piyashrija
Member
Registered: 2012-05-17
Posts: 30

Re: etc_query: all things Textpattern

Hi,
I have been using this plugin to read a json feed from the url as below…

<txp:etc_query name="json_data_incident" url="http://livetraffic.rta.nsw.gov.au/traffic/hazards/incident.json" markup="raw"></txp:etc_query>
	<txp:etc_query data='<txp:variable name="json_data_incident" />' markup="json" query="//geometry[coordinates/row[@index='0']<{?max_long} and coordinates/row[@index='0']>{?min_long} and coordinates/row[@index='1']>{?max_lat}and coordinates/row[@index='1']<{?min_lat}]" break=""  functions="strftime,htmlspecialchars,htmlspecialchars_decode,substr">

xpath code for manipulate...
</txp:etc_query>

it works fine.. there are also other feed like roadwork, event etc..

<txp:etc_query name="json_data_incident" url="http://livetraffic.rta.nsw.gov.au/traffic/hazards/roadworks.json" markup="raw"></txp:etc_query>
	<txp:etc_query data='<txp:variable name="json_data_incident" />' markup="json" query="//geometry[coordinates/row[@index='0']<{?max_long} and coordinates/row[@index='0']>{?min_long} and coordinates/row[@index='1']>{?max_lat}and coordinates/row[@index='1']<{?min_lat}]" break=""  functions="strftime,htmlspecialchars,htmlspecialchars_decode,substr">

xpath code for manipulate...
</txp:etc_query>

json feed for each url is in same format and i have have to grab exact same node for each feed.

How do i change url in etc_query after reading feed so that i can remove code duplication.

something like if there is way to add feed from each url in an array ???

{Edited to add Textile’s bc..s to not let @s swallow code. – Uli}

Last edited by uli (2013-01-31 23:43:01)

Offline

#172 2013-02-01 11:48:57

etc
Developer
Registered: 2010-11-11
Posts: 3,780
Website

Re: etc_query: all things Textpattern

That’s a good question, I have thought of merging feeds, but it has no much sense if they are not in same format. To avoid code duplication, you could try to retrieve them separately, and combine into json array:

<txp:etc_query data='[<txp:variable name="json_data_incident" />,<txp:variable name="json_data_roadworks" />]' markup="json" ...>

You could also merge them within <txp:php /> block, if that’s what you need:

<txp:php>
	global $variable;
	$res = array_merge_recursive(  json_decode( $variable["json_data_incident"], true ), json_decode( $variable["json_data_roadworks"], true ) );
	$variable["json_data"] = json_encode( $res );
</txp:php>

Then pass <txp:variable name="json_data" /> to etc_query. I can not try it on your feeds, sorry, the second one is offline.

Offline

#173 2013-02-03 22:11:36

piyashrija
Member
Registered: 2012-05-17
Posts: 30

Re: etc_query: all things Textpattern

Grt thanks..:)

Offline

#174 2013-02-04 02:41:39

piyashrija
Member
Registered: 2012-05-17
Posts: 30

Re: etc_query: all things Textpattern

Hi Again,

I have been doing this to grab data from roadwork(sorry it was roadwork not roadworks in url)

<txp:etc_query name="json_data_road" url="http://livetraffic.rta.nsw.gov.au/traffic/hazards/roadwork.json" markup="raw"></txp:etc_query>


	<txp:etc_query data='<txp:variable name="json_data_road" />' markup="json" query="//geometry[coordinates/row[@index='0']<{?max_long} and coordinates/row[@index='0']>{?min_long} and coordinates/row[@index='1']>{?max_lat}and coordinates/row[@index='1']<{?min_lat}]" break=""  functions="strftime,htmlspecialchars,htmlspecialchars_decode,substr">	

	{strftime('%A %e %B %Y', substring(string(following-sibling::properties[1]/start),1,10))}

	</txp:etc_query>

while it works with other url.
I also made check with data feed representative if there is any thing wrong but got replied back that data feed should work fine. Is there any thing wrong with my query.

Thanks

Last edited by uli (2013-02-04 13:54:51)

Offline

#175 2013-02-04 14:01:48

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,225

Re: etc_query: all things Textpattern

piyashrija, please have a look at how I changed your posting by adding bc.. and p. so your pasted code doesn’t get textilized and thus swallowed in portions (there are some unintended Textile commands in your code). Edit: To do so simply click the “Quote” link at the bottom of your own posting.

Also, there are Textile help links at the bottom of each page, and there’s a FAQ about how to post code here.
Thanks!

Last edited by uli (2013-02-04 20:52:33)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#176 2013-02-04 19:18:02

etc
Developer
Registered: 2010-11-11
Posts: 3,780
Website

Re: etc_query: all things Textpattern

Thank you, Uli.

piyashrija wrote:

I also made check with data feed representative if there is any thing wrong but got replied back that data feed should work fine.

It is fine, except for some weird non-ascii characters that somehow break echo and other output. So, you’d better remove them when importing feed:

<txp:etc_query name="json_data_road" url="http://livetraffic.rta.nsw.gov.au/traffic/hazards/roadwork.json" markup="raw">
	{$preg_replace(/[^(\x20-\x7F)]+/||$)}
</txp:etc_query>

Is there any thing wrong with my query.

query="//geometry[coordinates/row[@index='0']<{?max_long} and coordinates/row[@index='0']>{?min_long} and coordinates/row[@index='1']>{?max_lat}and coordinates/row[@index='1']<{?min_lat}]"

I suppose that you have set max_long and other <txp:variable /> if it works with other feed. After inserting a space between {?max_lat} and and it should work, but check if the inequalities >{?max_lat} and <{?min_lat} can be satisfied.

Hope it helps.

Offline

#177 2013-02-04 22:02:42

piyashrija
Member
Registered: 2012-05-17
Posts: 30

Re: etc_query: all things Textpattern

Thanks etc..
It works perfect

Offline

#178 2013-02-05 13:01:35

etc
Developer
Registered: 2010-11-11
Posts: 3,780
Website

Re: etc_query: all things Textpattern

The latest (1.2.4) version of etc_query will try to remove invalid characters automatically if you pass it encoding="UTF-8:UTF-8" or encoding="UTF-8:*" attribute.

Offline

#179 2013-08-18 16:35:13

juanjo
Member
From: A Coruña, Spain
Registered: 2005-08-01
Posts: 55
Website

Re: etc_query: all things Textpattern

Hi!

I ‘m trying to use this awesome plugin to handle a JSON array consisting of a series of data representing a forecast for specific timeframes, looking like this (http://magicseaweed.com/api/ubgA1h7B6qwgNP9C7x882q78zH5J0956/forecast/?spot_id=2968):

[{
timestamp: 1366902000,
localTimestamp: 1366902000,
issueTimestamp: 1366848000,
fadedRating: 0,
solidRating: 0,
swell: {
    minBreakingHeight: 1,
    absMinBreakingHeight: 1.06,
    maxBreakingHeight: 2,
    absMaxBreakingHeight: 1.66,
    unit: "ft"
}
}
{another timestamp, etc…}
]

I tried this query to get a specific timeframe data from the array, but without success…

<txp:etc_query url="http://magicseaweed.com/api/ubgA1h7B6qwgNP9C7x882q78zH5J0956/forecast/?spot_id=2968"
                        markup="json"
                        query="//localTimestamp[. ='1366902000']"
                        limit="1"                      
                        context='{"http":{"method":"GET","header":"User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/22.0\r\n"}}'
                      >
some code 
</txp:etc_query>

Thanks!

Offline

#180 2013-08-18 17:15:43

etc
Developer
Registered: 2010-11-11
Posts: 3,780
Website

Re: etc_query: all things Textpattern

Hi juanjo, your feed does not contain "localTimestamp":1366902000, try "//localTimestamp[. ='1376784000']", works for me. :) There is no need for context attribute here, the server does not seem to check User-Agent.

Last edited by etc (2013-08-18 17:17:20)

Offline

Board footer

Powered by FluxBB