Jump to content

redesigner

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

redesigner's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. That seems like it'll be a good start. The XML file in question lives at http://www.ryanean.es/crontwitter.xml ... here's a dump of it from today: <?xml version="1.0" encoding="UTF-8"?> <statuses type="array"> <status> <created_at>Mon Nov 22 17:05:32 +0000 2010</created_at> <id>6755168032923648</id> <text>It can be difficult to work when a cat that thinks it's a dog insists on sitting directly between you and your iPad.</text> <source><a href="http://twitterrific.com" rel="nofollow">Twitterrific</a></source> <truncated>false</truncated> <favorited>false</favorited> <in_reply_to_status_id></in_reply_to_status_id> <in_reply_to_user_id></in_reply_to_user_id> <in_reply_to_screen_name></in_reply_to_screen_name> <retweet_count></retweet_count> <retweeted>false</retweeted> <user> <id>14820502</id> <name>Ryan Eanes</name> <screen_name>eaners</screen_name> <location>Brooklyn, NY</location> <description>Eccentric, entertaining and critical, or your money back.</description> <profile_image_url>http://a0.twimg.com/profile_images/1164214368/image_normal.jpg</profile_image_url> <url>http://www.ryanean.es</url> <protected>false</protected> <followers_count>273</followers_count> <profile_background_color>F34D13</profile_background_color> <profile_text_color>000000</profile_text_color> <profile_link_color>530606</profile_link_color> <profile_sidebar_fill_color>E9E8C6</profile_sidebar_fill_color> <profile_sidebar_border_color>000000</profile_sidebar_border_color> <friends_count>231</friends_count> <created_at>Sun May 18 13:17:52 +0000 2008</created_at> <favourites_count>161</favourites_count> <utc_offset>-18000</utc_offset> <time_zone>Eastern Time (US & Canada)</time_zone> <profile_background_image_url>http://s.twimg.com/a/1290023717/images/themes/theme1/bg.png</profile_background_image_url> <profile_background_tile>false</profile_background_tile> <profile_use_background_image>false</profile_use_background_image> <notifications>false</notifications> <geo_enabled>true</geo_enabled> <verified>false</verified> <following>true</following> <statuses_count>4080</statuses_count> <lang>en</lang> <contributors_enabled>false</contributors_enabled> <follow_request_sent>false</follow_request_sent> <listed_count>13</listed_count> <show_all_inline_media>false</show_all_inline_media> </user> <geo/> <coordinates/> <place/> <contributors/> </status> <status> <created_at>Mon Nov 22 00:00:23 +0000 2010</created_at> <id>6497183310290944</id> <text>Um, old guy in first class? You don't have to TIP THE GATE AGENT. It isn't going to make the in-flight experience any better. #whatthecrap</text> <source><a href="http://twitter.com/" rel="nofollow">Twitter for iPhone</a></source> <truncated>false</truncated> <favorited>false</favorited> <in_reply_to_status_id></in_reply_to_status_id> <in_reply_to_user_id></in_reply_to_user_id> <in_reply_to_screen_name></in_reply_to_screen_name> <retweet_count></retweet_count> <retweeted>false</retweeted> <user> <id>14820502</id> <name>Ryan Eanes</name> <screen_name>eaners</screen_name> <location>Brooklyn, NY</location> <description>Eccentric, entertaining and critical, or your money back.</description> <profile_image_url>http://a0.twimg.com/profile_images/1164214368/image_normal.jpg</profile_image_url> <url>http://www.ryanean.es</url> <protected>false</protected> <followers_count>274</followers_count> <profile_background_color>F34D13</profile_background_color> <profile_text_color>000000</profile_text_color> <profile_link_color>530606</profile_link_color> <profile_sidebar_fill_color>E9E8C6</profile_sidebar_fill_color> <profile_sidebar_border_color>000000</profile_sidebar_border_color> <friends_count>231</friends_count> <created_at>Sun May 18 13:17:52 +0000 2008</created_at> <favourites_count>161</favourites_count> <utc_offset>-18000</utc_offset> <time_zone>Eastern Time (US & Canada)</time_zone> <profile_background_image_url>http://s.twimg.com/a/1290023717/images/themes/theme1/bg.png</profile_background_image_url> <profile_background_tile>false</profile_background_tile> <profile_use_background_image>false</profile_use_background_image> <notifications>false</notifications> <geo_enabled>true</geo_enabled> <verified>false</verified> <following>false</following> <statuses_count>4079</statuses_count> <lang>en</lang> <contributors_enabled>false</contributors_enabled> <follow_request_sent>false</follow_request_sent> <listed_count>13</listed_count> <show_all_inline_media>false</show_all_inline_media> </user> <geo/> <coordinates/> <place/> <contributors/> </status> <status> <created_at>Sun Nov 21 23:57:04 +0000 2010</created_at> <id>6496347918176257</id> <text>is wondering why the gate agent here at the airport is wearing what appears to be an ill-fitting lab coat. Utterly bizarre. #fb</text> <source><a href="http://twitter.com/" rel="nofollow">Twitter for iPhone</a></source> <truncated>false</truncated> <favorited>false</favorited> <in_reply_to_status_id></in_reply_to_status_id> <in_reply_to_user_id></in_reply_to_user_id> <in_reply_to_screen_name></in_reply_to_screen_name> <retweet_count></retweet_count> <retweeted>false</retweeted> <user> <id>14820502</id> <name>Ryan Eanes</name> <screen_name>eaners</screen_name> <location>Brooklyn, NY</location> <description>Eccentric, entertaining and critical, or your money back.</description> <profile_image_url>http://a0.twimg.com/profile_images/1164214368/image_normal.jpg</profile_image_url> <url>http://www.ryanean.es</url> <protected>false</protected> <followers_count>274</followers_count> <profile_background_color>F34D13</profile_background_color> <profile_text_color>000000</profile_text_color> <profile_link_color>530606</profile_link_color> <profile_sidebar_fill_color>E9E8C6</profile_sidebar_fill_color> <profile_sidebar_border_color>000000</profile_sidebar_border_color> <friends_count>231</friends_count> <created_at>Sun May 18 13:17:52 +0000 2008</created_at> <favourites_count>161</favourites_count> <utc_offset>-18000</utc_offset> <time_zone>Eastern Time (US & Canada)</time_zone> <profile_background_image_url>http://s.twimg.com/a/1290023717/images/themes/theme1/bg.png</profile_background_image_url> <profile_background_tile>false</profile_background_tile> <profile_use_background_image>false</profile_use_background_image> <notifications>false</notifications> <geo_enabled>true</geo_enabled> <verified>false</verified> <following>false</following> <statuses_count>4078</statuses_count> <lang>en</lang> <contributors_enabled>false</contributors_enabled> <follow_request_sent>false</follow_request_sent> <listed_count>13</listed_count> <show_all_inline_media>false</show_all_inline_media> </user> <geo/> <coordinates/> <place/> <contributors/> </status> <status> <created_at>Sun Nov 21 23:10:33 +0000 2010</created_at> <id>6484640038653952</id> <text>has seen at least a half-dozen children under the age of five at the Continental President's Club today. IS NOTHING SACRED?! #fb</text> <source>web</source> <truncated>false</truncated> <favorited>false</favorited> <in_reply_to_status_id></in_reply_to_status_id> <in_reply_to_user_id></in_reply_to_user_id> <in_reply_to_screen_name></in_reply_to_screen_name> <retweet_count></retweet_count> <retweeted>false</retweeted> <user> <id>14820502</id> <name>Ryan Eanes</name> <screen_name>eaners</screen_name> <location>Brooklyn, NY</location> <description>Eccentric, entertaining and critical, or your money back.</description> <profile_image_url>http://a0.twimg.com/profile_images/1164214368/image_normal.jpg</profile_image_url> <url>http://www.ryanean.es</url> <protected>false</protected> <followers_count>274</followers_count> <profile_background_color>F34D13</profile_background_color> <profile_text_color>000000</profile_text_color> <profile_link_color>530606</profile_link_color> <profile_sidebar_fill_color>E9E8C6</profile_sidebar_fill_color> <profile_sidebar_border_color>000000</profile_sidebar_border_color> <friends_count>231</friends_count> <created_at>Sun May 18 13:17:52 +0000 2008</created_at> <favourites_count>161</favourites_count> <utc_offset>-18000</utc_offset> <time_zone>Eastern Time (US & Canada)</time_zone> <profile_background_image_url>http://s.twimg.com/a/1290023717/images/themes/theme1/bg.png</profile_background_image_url> <profile_background_tile>false</profile_background_tile> <profile_use_background_image>false</profile_use_background_image> <notifications>false</notifications> <geo_enabled>true</geo_enabled> <verified>false</verified> <following>true</following> <statuses_count>4077</statuses_count> <lang>en</lang> <contributors_enabled>false</contributors_enabled> <follow_request_sent>false</follow_request_sent> <listed_count>13</listed_count> <show_all_inline_media>false</show_all_inline_media> </user> <geo/> <coordinates/> <place/> <contributors/> </status> <status> <created_at>Sun Nov 21 22:28:16 +0000 2010</created_at> <id>6473998447673344</id> <text>@jrpettet Same here. It scares me. Will have to hit the treadmill hard when I get back from Thanksgiving.</text> <source>web</source> <truncated>false</truncated> <favorited>false</favorited> <in_reply_to_status_id>6471299132039168</in_reply_to_status_id> <in_reply_to_user_id>14825977</in_reply_to_user_id> <in_reply_to_screen_name>jrpettet</in_reply_to_screen_name> <retweet_count></retweet_count> <retweeted>false</retweeted> <user> <id>14820502</id> <name>Ryan Eanes</name> <screen_name>eaners</screen_name> <location>Brooklyn, NY</location> <description>Eccentric, entertaining and critical, or your money back.</description> <profile_image_url>http://a0.twimg.com/profile_images/1164214368/image_normal.jpg</profile_image_url> <url>http://www.ryanean.es</url> <protected>false</protected> <followers_count>274</followers_count> <profile_background_color>F34D13</profile_background_color> <profile_text_color>000000</profile_text_color> <profile_link_color>530606</profile_link_color> <profile_sidebar_fill_color>E9E8C6</profile_sidebar_fill_color> <profile_sidebar_border_color>000000</profile_sidebar_border_color> <friends_count>231</friends_count> <created_at>Sun May 18 13:17:52 +0000 2008</created_at> <favourites_count>161</favourites_count> <utc_offset>-18000</utc_offset> <time_zone>Eastern Time (US & Canada)</time_zone> <profile_background_image_url>http://s.twimg.com/a/1290023717/images/themes/theme1/bg.png</profile_background_image_url> <profile_background_tile>false</profile_background_tile> <profile_use_background_image>false</profile_use_background_image> <notifications>false</notifications> <geo_enabled>true</geo_enabled> <verified>false</verified> <following>true</following> <statuses_count>4076</statuses_count> <lang>en</lang> <contributors_enabled>false</contributors_enabled> <follow_request_sent>false</follow_request_sent> <listed_count>13</listed_count> <show_all_inline_media>false</show_all_inline_media> </user> <geo/> <coordinates/> <place/> <contributors/> </status> <status> <created_at>Sun Nov 21 22:16:07 +0000 2010</created_at> <id>6470942507139072</id> <text>Attention spans are dwindling & grades are declining, thanks to overstimulation from technology. I've seen it first-hand. http://is.gd/hyjj5</text> <source>web</source> <truncated>false</truncated> <favorited>false</favorited> <in_reply_to_status_id></in_reply_to_status_id> <in_reply_to_user_id></in_reply_to_user_id> <in_reply_to_screen_name></in_reply_to_screen_name> <retweet_count></retweet_count> <retweeted>false</retweeted> <user> <id>14820502</id> <name>Ryan Eanes</name> <screen_name>eaners</screen_name> <location>Brooklyn, NY</location> <description>Eccentric, entertaining and critical, or your money back.</description> <profile_image_url>http://a0.twimg.com/profile_images/1164214368/image_normal.jpg</profile_image_url> <url>http://www.ryanean.es</url> <protected>false</protected> <followers_count>274</followers_count> <profile_background_color>F34D13</profile_background_color> <profile_text_color>000000</profile_text_color> <profile_link_color>530606</profile_link_color> <profile_sidebar_fill_color>E9E8C6</profile_sidebar_fill_color> <profile_sidebar_border_color>000000</profile_sidebar_border_color> <friends_count>231</friends_count> <created_at>Sun May 18 13:17:52 +0000 2008</created_at> <favourites_count>161</favourites_count> <utc_offset>-18000</utc_offset> <time_zone>Eastern Time (US & Canada)</time_zone> <profile_background_image_url>http://s.twimg.com/a/1290023717/images/themes/theme1/bg.png</profile_background_image_url> <profile_background_tile>false</profile_background_tile> <profile_use_background_image>false</profile_use_background_image> <notifications>false</notifications> <geo_enabled>true</geo_enabled> <verified>false</verified> <following>true</following> <statuses_count>4075</statuses_count> <lang>en</lang> <contributors_enabled>false</contributors_enabled> <follow_request_sent>false</follow_request_sent> <listed_count>13</listed_count> <show_all_inline_media>false</show_all_inline_media> </user> <geo/> <coordinates/> <place/> <contributors/> </status> </statuses> I'll work with my existing script a bit later to see if I can tweak it.
  2. Hi all. I'm using a cron job to pull the XML feed of my last five tweets, and using simplexml to parse and display the feed on my website. Here's the PHP I'm using--it works just fine, and displays exactly as I want it to: <?php $xml = simplexml_load_file('crontwitter.xml'); foreach ($xml->status as $status) { print "<p><span class=\"twittertext\">{$status->text}</span><br />"; print "<a class=\"twittertime\" href=\"http://twitter.com/#!/eaners/status/{$status->id}\" target=\"_blank\">"; echo date("j M Y, g:i A",strtotime($status->created_at)); print "</a></span></p>"; } ?> I'd like to add a touch more "intelligence" to this script, though. Namely, there are three things I'd also like to have this script do: [*]I'd like to append "I" to any tweets that include the #fb hashtag, so that things display correctly (e.g., "I did such and such today" instead of just "did such and such today") [*]I'd like to link to any other Twitter users mentioned (they would always be mentioned using the @username format) [*]I'd like to link to a search for any other hash tag mentioned aside from #fb (they would always be included using the #tag format) I guess I'm not sure how exactly to further parse the XML file. I'll admit to being a relative newbie when it comes to PHP, so any assistance would be greatly appreciated!
  3. Solved it! For some reason, including the 'current_observation' node was causing the problem. This is the code that worked: <?php $xml = simplexml_load_file('current_obs.xml'); print "<span id=\"temp_f\">{$xml->temp_f}</span><span id=\"fahrenheit\"> °F</span><br />"; print "<span id=\"currently\">{$xml->weather}</span><br />"; print "<span id=\"relative_humidity\">{$xml->relative_humidity} relative humidity</span>"; ?>
  4. I think I've made some progress here. The cURL portion of my page still seems to be working just fine: <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,'http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=LGA'); $fp = fopen('current_obs.xml', 'w'); curl_setopt($ch, CURLOPT_FILE, $fp); curl_exec ($ch); curl_close ($ch); fclose($fp); ?> Also, I've replaced all that JavaScript nonsense with SimpleXML commands written in PHP that should, as far as I can tell, anyway, work: <?php $xml = simplexml_load_file('current_obs.xml'); print "<span id=\"temp_f\">{$xml->current_observation[0]->temp_f}</span><span id=\"fahrenheit\"> °F</span><br />"; print "<span id=\"currently\">{$xml->current_observation[0]->weather}</span><br />"; print "<span id=\"relative_humidity\">{$xml->current_observation[0]->relative_humidity} relative humidity</span>"; ?> However, something isn't quite working right. The script runs and outputs this: <span id="temp_f"></span><span id="fahrenheit"> °F</span><br /> <span id="currently"></span><br /> <span id="relative_humidity"> relative humidity</span> So the print command is working but for some reason the XML values aren't being inserted. Any idea what could be going awry?
  5. I'm having some difficulty figuring out how to use PHP to parse an XML file and display certain values from the XML. I've had no trouble using cURL to copy the particular XML feed in question to my server. I'm doing that using this bit of PHP in the <head> section of my index.php file: <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,'http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=LGA'); $fp = fopen('current_obs.xml', 'w'); curl_setopt($ch, CURLOPT_FILE, $fp); curl_exec ($ch); curl_close ($ch); fclose($fp); ?> I've tried using JavaScript to pull the data from the weather, temp_f and relative_humidity nodes of the XML file. This is the script in the body section of index.php: <script type="text/javascript"> if (window.XMLHttpRequest) { xhttp=new XMLHttpRequest() } else { xhttp=new ActiveXObject("Microsoft.XMLHTTP") } xhttp.open("GET","current_obs.xml",false); xhttp.send(""); xmlDoc=xhttp.responseXML; document.getElementById("temp_f").innerHTML=xmlDoc.getElementsByTagName("temp_f")[0].childNodes[0].nodeValue; document.getElementById("weather").innerHTML=xmlDoc.getElementsByTagName("weather")[0].childNodes[0].nodeValue; document.getElementById("relative_humidity").innerHTML=xmlDoc.getElementsByTagName("relative_humidity")[0].childNodes[0].nodeValue; </script> When I try and call the values using this bit of HTML, nothing happens: <div id="weatherblock"> <span id="weatherheader">Currently in Brooklyn</span><br /> <span id="temp_f"></span> °F<br /> <span id="weather"></span><br /> <span id="relative_humidity"></span>% humidity </div> There are no errors--just no output when the browser renders index.php (aside from the "ºF" and "% humidity" bits appearing). Can anyone tell me where I'm going wrong, or suggest a better (simple) way to do this?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.