Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#49 2010-05-23 02:28:12

nardo
Member
From: tuvalahiti
Registered: 2004-04-22
Posts: 741

Re: smd_xml : extract data from XML feeds

hey bloke, recently got a PHP error on my site (didn’t record at the time) but it was due to the data feed not being available (the server it was on was undergoing maintenance) – does the plugin have a way to die quietly if the data is not available?

(if it does, maybe there’s a more local reason for the error I got)

Offline

#50 2010-05-23 08:05:18

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,568
Website GitHub

Re: smd_xml : extract data from XML feeds

nardo wrote:

does the plugin have a way to die quietly if the data is not available?

Not explicitly but I set a timeout of 10 seconds in there so, in theory (it’s difficult to test) it’s supposed to give up after that length of time and return nothing. If I can find a way to verify this is actually working — by making a local feed and putting the site in maintenance mode for example — I’ll see what the plugin does. And if it falls over for whatever reason I’ll see what I can do to fix it. Thanks for bringing this to my attention.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#51 2010-06-05 07:49:01

nardo
Member
From: tuvalahiti
Registered: 2004-04-22
Posts: 741

Re: smd_xml : extract data from XML feeds

Manage to hit another level of 503 error today Stef!

  • Called a Google Spreadsheet in which I’d chucked a Textpattern image tag, just to see what would happen > got whirring cursor on webpage, then finally 503 error
  • Updated spreadsheet (i.e. removed tag!), tried to clear cache, etc … still 503 … went into PHPMyAdmin and deleted the two smd_xml rows in preferences table … still 503

What to try next?

Update fixed – I’d managed to set line_length attribute to “1” when I meant to change the cache_time attribute

Last edited by nardo (2010-06-05 07:50:59)

Offline

#52 2010-06-29 03:12:52

kevinpotts
Member
From: Kansas City
Registered: 2004-12-07
Posts: 366
Website

Re: smd_xml : extract data from XML feeds

Stef —

I have a good handle of XML and how your plugin works, but I am stuck. I want to pull in the time of sunset using Yahoo! Weather RSS feeds. This is the RSS feed for Benson, AZ. They display sunset as an attribute of a field, like this:

<yweather:astronomy sunrise="5:21 am"   sunset="7:31 pm" />

I’ve tried all kinds of combos with your plugin, but mostly it’s just epic fail across the board. Can you help?

Offline

#53 2010-06-29 07:32:48

net-carver
Archived Plugin Author
Registered: 2006-03-08
Posts: 1,648

Re: smd_xml : extract data from XML feeds

Kevin

slightly off topic, but php5 has functions to find the sunrise/sunset times given a location and date if that helps you. Something like…

$latitude  = 55.27; # -ve is south of Equator, +ve is north
$longitude = -22.35; # -ve is west of Grenwich meridian, +ve is east.
$sunset = date_sunset ( time(), SUNFUNCS_RET_TIMESTAMP, $latitude, $longitude);
echo date( 'H:i', $sunset );

…should display the sunset time for you. Just remember to supply your latitude and longitude and you should be all set.

Edited to add longitude & latitude to example code


Steve

Offline

#54 2010-06-29 08:11:50

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,568
Website GitHub

Re: smd_xml : extract data from XML feeds

kevinpotts wrote:

I’ve tried all kinds of combos with your plugin, but mostly it’s just epic fail across the board. Can you help?

The current plugin is unfortunately a bit lame in the way it handles subfields and compound tags. The next version that I’m about, ummm what, 70% of the way through(ish) handles the feed you gave above natively with this tag:

<txp:smd_xml data="http://weather.yahooapis.com/forecastrss?w=2362700" record="channel" fields="yweather">
Sunrise: {yweather:astronomy|sunrise}
Sunset: {yweather:astronomy|sunset}
</txp:smd_xml>

Although the plugin isn’t finished, if you were desperate (i.e. net-carver’s PHP didn’t fit the bill) and didn’t use it for much more complicated stuff than the above, I could tidy it up a bit and let you have the dev version with no warranty implied :-)

Drop me a mail if you’d like a copy.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#55 2010-06-29 15:13:42

kevinpotts
Member
From: Kansas City
Registered: 2004-12-07
Posts: 366
Website

Re: smd_xml : extract data from XML feeds

net-carver — This code worked perfectly. However, because I am a PHP moron, how would you format the time? By default it’s “military” time (like 19:31 instead of 7:31 PM). I looked around php.net at this function, but I can’t seem to figure it out. Again, I am a moron.

Bloke — Your work on this plugin is amazing, and I’ve used it elsewhere, but if I can grab this data via native PHP without relying on the overhead of parsing RSS from Yahoo that’s derived from weather.com data, the world will be a lot easier. But thank you regardless — your next version looks awesome.

Offline

#56 2010-06-29 15:34:31

net-carver
Archived Plugin Author
Registered: 2006-03-08
Posts: 1,648

Re: smd_xml : extract data from XML feeds

Kevin

just change the last line to…

echo date( 'g:i A', $sunset );

The format codes are here.


Steve

Offline

#57 2010-06-29 15:36:18

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,568
Website GitHub

Re: smd_xml : extract data from XML feeds

kevinpotts

No worries. The PHP version is far simpler anyway.

For the reformatting of dates, look at the date function. The last line of Steve’s code has "H:i" in it. That’s H=24-hour ‘hour’, then a colon, then the minutes with leading zeros. If you want to alter it, change the stuff in quotes to something like "g:iA" for 7:31AM.

EDIT: Steve be faster, Steve be quick…

Last edited by Bloke (2010-06-29 15:37:20)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#58 2010-06-29 16:19:18

net-carver
Archived Plugin Author
Registered: 2006-03-08
Posts: 1,648

Re: smd_xml : extract data from XML feeds

Kevin

if you want a lowercase am/pm then use…

echo date( 'g:i a', $sunset );

As Stef posted, you can also get rid of the space between the ‘i’ and ‘a’ if you need to.


Steve

Offline

#59 2010-06-29 18:07:55

kevinpotts
Member
From: Kansas City
Registered: 2004-12-07
Posts: 366
Website

Re: smd_xml : extract data from XML feeds

You guys are so awesome it hurts. I was messing with the time() function to see if I could use the same variables as date(), but, alas, I am not so smart. Seriously — thanks both. Makes me love being part of this community. Wordpress can go to hell.

Offline

#60 2010-07-05 21:15:41

kevinpotts
Member
From: Kansas City
Registered: 2004-12-07
Posts: 366
Website

Re: smd_xml : extract data from XML feeds

Not sure if you guys are looking for extra credit, but I am trying to take this concept to a new level via AJAX. Any help at all would be really, um, helpful.

Offline

Board footer

Powered by FluxBB