User Tag List

  1. NewD's Avatar
    Ras,
    In the following block of text in the wug.xml how do I parse out the long weatherdescription in the <fcttext> entry?
    Code:
    <forecast>
         <txt_forecast>
    	<date>7:22 PM EST</date>
    		<forecastdays>
    							
    			<forecastday>
    				<period>0</period>
    				<icon>cloudy</icon>
    				<icon_url>http://icons.wxug.com/i/c/k/cloudy.gif</icon_url>
    				<title>Sunday</title>
    				<fcttext><![CDATA[Mostly cloudy. Lows overnight in the low 20s.]]></fcttext>
    				<fcttext_metric><![CDATA[Mostly cloudy. Low -6C.]]></fcttext_metric>
    				<pop>0</pop>
    				</forecastday>
    
    			<forecastday>
    				<period>1</period>
    				<icon>nt_cloudy</icon>
    				<icon_url>http://icons.wxug.com/i/c/k/nt_cloudy.gif</icon_url>
    				<title>Sunday Night</title>
    				<fcttext><![CDATA[Cloudy. Low 22F. Winds WNW at 5 to 10 mph.]]></fcttext>
    				<fcttext_metric><![CDATA[Overcast. Low -6C. Winds WNW at 10 to 15 km/h.]]></fcttext_metric>
    				<pop>0</pop>
    				</forecastday>
    I'm able to get to <icon> <icon_url> and <period> easily using $(data).find('forecastday').each( function(i, item) {

    But there's strange data in the fcttest field that looks like: <fcttext><![CDATA[Mostly cloudy. Lows overnight in the low 20s.]]></fcttext>

    I've never seen that <![CDATA[ syntax in an XML file before...

    How to I parse out the data: "Mostly cloudy. Lows overnight in the low 20s." from the xml data?
    2015-02-25 08:41 PM
  2. rasputin007's Avatar
    Click on the link in my previous post.
    And all will be revealed.
    Nothing is impossible only miracles take a bit longer!
    2015-02-25 09:14 PM
  3. NewD's Avatar
    Ah - missed that post. Thx!
    2015-02-25 09:31 PM
  4. NewD's Avatar
    Ras,
    The way you are parsing the forecast data from the mywug.xml is different than the way I'm used to from most of our widgets that are written that use an xml file. It got me a bit confused... And what complicated the matter was that the data in the mywug.xml IS DIFFERENT than what you used in your forecast.xml example from your site..... The mywug.xml on my phone was making my example widget fail...

    I eventually got my example widget working using your "forecast.xml" example file from your site. But sadly the forecast data in the mywug.xml file does NOT look like your forecast.xml from your site..

    And here's the way I parse an xml file with 'nested' values I need to get concurrent array values from.
    Code:
    var obj = new Array;
    jQuery.get("forecast.xml", function(data) {
        obj.period = [];
        obj.fcttext = [];
        obj.title = [];	
        $(data).find('forecastday').each( function(i, item) {
    	obj.period[i] = $(this).find('period').text();
    	obj.fcttext[i] = $(this).find('fcttext').text();
    	obj.title[i] = $(this).find('title').text();
    		
    	for (i=0; i < obj.period.length; i++) {
    	    if (obj.period[i].indexOf("0") > -1) {
    		obj.forecast0 = obj.fcttext[i];
    		obj.title0 = obj.title[i]; break;
    	    }
    	}
    	for (i=0; i < obj.period.length; i++) {
    	    if (obj.period[i].indexOf("1") > -1) {
    		obj.forecast1 = obj.fcttext[i];
    		obj.title1 = obj.title[i]; break;
    	    }
    	}
    	for (i=0; i < obj.period.length; i++) {
    	    if (obj.period[i].indexOf("2") > -1) {
    		obj.forecast2 = obj.fcttext[i];
    		obj.title2 = obj.title[i]; break;
    	    }
    	}				
        }); // closes $(data).find
    	
        document.getElementById("forecast").innerHTML =
        obj.title0 + ": "  + "<br>" + obj.forecast0 + "<p>" +
        obj.title1 + ": "  + "<br>" + obj.forecast1 + "<p>" +
        obj.title2 + ": "  + "<br>" + obj.forecast2;
    });
    But here's the problem... Your forecast.xml shows this for fcttext lines:
    <fcttext>Mostly cloudy. Lows overnight in the low 20s.</fcttext>

    BUT -- the mywug.xml in var/mobile/wug/ shows THIS as the fcttext line:
    <fcttext><![CDATA[Mostly cloudy. Lows overnight in the low 20s.]]></fcttext>

    That line is 'un-parse-able' by any methods I know.. and makes YOUR parse code example fail too for getting forecast data.. Can you make your WUG tweak ACTUALLY create this line ---
    <fcttext>Mostly cloudy. Lows overnight in the low 20s.</fcttext> in the mywug.xml?

    Again -- here's the mywug.xml file data on my phone - NOT like your example forecast.xml from your site on the fcttext line..
    Code:
    <forecast>
         <txt_forecast>
    	<date>7:22 PM EST</date>
    		<forecastdays>
    							
    			<forecastday>
    				<period>0</period>
    				<icon>cloudy</icon>
    				<icon_url>http://icons.wxug.com/i/c/k/cloudy.gif</icon_url>
    				<title>Sunday</title>
    				<fcttext><![CDATA[Mostly cloudy. Lows overnight in the low 20s.]]></fcttext>
    				<fcttext_metric><![CDATA[Mostly cloudy. Low -6C.]]></fcttext_metric>
    				<pop>0</pop>
    				</forecastday>
    
    			<forecastday>
    				<period>1</period>
    				<icon>nt_cloudy</icon>
    				<icon_url>http://icons.wxug.com/i/c/k/nt_cloudy.gif</icon_url>
    				<title>Sunday Night</title>
    				<fcttext><![CDATA[Cloudy. Low 22F. Winds WNW at 5 to 10 mph.]]></fcttext>
    				<fcttext_metric><![CDATA[Overcast. Low -6C. Winds WNW at 10 to 15 km/h.]]></fcttext_metric>
    				<pop>0</pop>
    				</forecastday>
    Last edited by NewD; 2015-02-26 at 05:41 AM.
    2015-02-25 09:38 PM
  5. rasputin007's Avatar
    The forecast.xml file in the example has these lines
    Code:
    <fcttext>
    <![CDATA[
    Partly cloudy. High 42F. Winds WNW at 5 to 10 mph.
    ]]>
    </fcttext>
    <fcttext_metric>
    <![CDATA[
    Partly cloudy. High 6C. Winds WNW at 10 to 15 km/h.
    ]]>
    </fcttext_metric>
    <pop>0</pop>
    </forecastday>
    <forecastday>
    <period>1</period>
    <icon>nt_snow</icon>
    <icon_url>http://icons.wxug.com/i/c/k/nt_snow.gif</icon_url>
    <title>Wednesday Night</title>
    <fcttext>
    <![CDATA[
    Snow developing overnight. Low 26F. Winds NE at 5 to 10 mph. Chance of snow 70%. Snow accumulations less than < 1 inch.
    ]]>
    </fcttext>
    If you open forecast.html you will see that the forecast text from the fcttext tags has been parsed, the
    Code:
    ![CDATA[
    has no influence at all.
    But I will try it with a mywug.xml and let you know.
    I quite don't understand why you declare an array as an object, e.g.obj.fcttext. I could understand if you declared an element of the array as an object in order to use it outside the function.
    Nothing is impossible only miracles take a bit longer!
    2015-02-26 07:30 AM
  6. rasputin007's Avatar
    OK, I just enabled Weather Forecast in the WUG Setup menu, then ran /usr/bin/wug.sh as I did not wanted to wait for 3 minutes for the next update. LOL
    So then I got forecast in my /var/mobile/Documents/mywug.xml
    Next I copied the forecast.html PLUS the js folder (forecast.html requires jquery!) from the example also into /var/mobile/Documents and changed line 40 of the forecast.html from
    Code:
    $.get("forecast.xml", {}, function (data) {
    into
    Code:
    $.get("mywug.xml", {}, function (data) {
    Then I opened forecast.html with Filza and iFile, to be sure and this is what I saw each time



    Works for me with forecast.html and mywug.xml.

    EDIT:
    I agree that the javascript looks different from what I am used to as well, but it took me a few hours to figure this one out.
    Last edited by rasputin007; 2015-02-26 at 08:02 AM.
    Nothing is impossible only miracles take a bit longer!
    2015-02-26 07:53 AM
  7. rasputin007's Avatar
    Attached is a quick basic forecast cydget.
    Copy the Forecast.cydget folder into your /System/Library/LockCydgets folder.
    Then select in Cydget->Lock Cydget Order!
    I have moved it to second place.
    I also set scrollable to YES in the Info.plist file in case there is more text that would fit on the screen.

    Screenshot of it in Vietnamese! (iPad)


    Screenshot from iPhone 5S in dutch


    or in Turkish

    Attached Files
    Last edited by rasputin007; 2015-02-26 at 12:22 PM.
    Nothing is impossible only miracles take a bit longer!
    2015-02-26 11:34 AM
  8. NewD's Avatar
    Strange.. But neither yours not my parsing js will get the contents of fcttext from a mywug.xml created on my phone. But both our Javascript parse methods work to get the contents of fcttext from the live url from WU.

    So you must have a "special phone" there bro.. .. When I look at the live xml response from the URL at WU in Firefox or Safari there is NO "CDATA" in the <fcttext> text blocks.

    So I'm stuck. Would love to be able to use the mywug.xml for forecast data- but I can't..

    Your forecast.xml at your website does NOT contain the CDATA, my friend. Let me get screenshots for proof of what I'm saying.
    Last edited by NewD; 2015-02-26 at 01:00 PM.
    2015-02-26 12:35 PM
  9. NewD's Avatar
    Here's my proof, Ras, that the muwug.xml contains different data than the WU live URL or your forecast.xml on your blog.

    Live from WU url:
    MYO5 Lockscreen cydget for iOS 8-fcttext-wu.jpg

    From YOUR forecast.xml on your blog:
    MYO5 Lockscreen cydget for iOS 8-fcttext-ras-xml.jpg

    From the mywug.xml created by your tweak on my phone:
    MYO5 Lockscreen cydget for iOS 8-mywugxml.jpg

    As you see - mywug.xml created on my phone has additional <!CDATA text that makes the parse code (both yours and mine) fail the widget. I will not be using a Cydget - so this has to work in a standard iWidget or LS/SB widget with GL/GB or iWidgets.. I'm doing my widget testing in my code editor with Live Preview.. And when the xml file I call from the js code is either yours from your blog or live from WU - the widget works. When I use mywug.xml it fails. You need to strip the <!CDATA text from the <fcttext></fcttext> code block when it prints to mywug.xml and then all will work properly.
    Last edited by NewD; 2015-02-26 at 01:01 PM.
    2015-02-26 12:52 PM
  10. rasputin007's Avatar
    OK, here is my proof!
    The forecast section of mywug.xml from my iPhone.
    Code:
    	<forecast>
    		<txt_forecast>
    			<date>12:44 PM GMT</date>
    			<forecastdays>
    				
    				
    
    			
    				<forecastday>
    					<period>0</period>
    					<icon>cloudy</icon>
    					<icon_url>http://icons.wxug.com/i/c/k/cloudy.gif</icon_url>
    					
    					<title>Thursday</title>
    					<fcttext><![CDATA[Cloudy. High 45F. Winds WNW at 15 to 25 mph.]]></fcttext>
    					<fcttext_metric><![CDATA[Cloudy. High 7C. Winds WNW at 25 to 40 km/h.]]></fcttext_metric>
    					<pop>0</pop>
    				</forecastday>
    
    				
    				<forecastday>
    					<period>1</period>
    					<icon>nt_clear</icon>
    					<icon_url>http://icons.wxug.com/i/c/k/nt_clear.gif</icon_url>
    					
    					<title>Thursday Night</title>
    					<fcttext><![CDATA[Generally clear. Scattered frost possible. Low 32F. Winds W at 10 to 15 mph.]]></fcttext>
    					<fcttext_metric><![CDATA[Generally clear. Scattered frost possible. Low 0C. Winds W at 15 to 25 km/h.]]></fcttext_metric>
    					<pop>0</pop>
    				</forecastday>
    				
    			
    				<forecastday>
    					<period>2</period>
    					<icon>clear</icon>
    					<icon_url>http://icons.wxug.com/i/c/k/clear.gif</icon_url>
    					
    					<title>Friday</title>
    					<fcttext><![CDATA[Generally clear. Turning cooler. High 48F. Winds WSW at 10 to 20 mph.]]></fcttext>
    					<fcttext_metric><![CDATA[Generally clear. Turning cooler. High 9C. Winds WSW at 15 to 30 km/h.]]></fcttext_metric>
    					<pop>0</pop>
    				</forecastday>
    
    				
    				<forecastday>
    					<period>3</period>
    					<icon>nt_chancerain</icon>
    					<icon_url>http://icons.wxug.com/i/c/k/nt_chancerain.gif</icon_url>
    					
    					<title>Friday Night</title>
    					<fcttext><![CDATA[Light rain developing late. Low 36F. Winds SSW at 15 to 25 mph. Chance of rain 40%.]]></fcttext>
    					<fcttext_metric><![CDATA[Light rain developing late. Low 2C. Winds SSW at 25 to 40 km/h. Chance of rain 40%.]]></fcttext_metric>
    					<pop>40</pop>
    				</forecastday>
    				
    			
    				<forecastday>
    					<period>4</period>
    					<icon>chancerain</icon>
    					<icon_url>http://icons.wxug.com/i/c/k/chancerain.gif</icon_url>
    					
    					<title>Saturday</title>
    					<fcttext><![CDATA[Afternoon showers. High 49F. Winds SSW at 15 to 25 mph. Chance of rain 50%.]]></fcttext>
    					<fcttext_metric><![CDATA[Afternoon showers. High 9C. Winds SSW at 25 to 40 km/h. Chance of rain 50%.]]></fcttext_metric>
    					<pop>50</pop>
    				</forecastday>
    
    				
    				<forecastday>
    					<period>5</period>
    					<icon>nt_chancerain</icon>
    					<icon_url>http://icons.wxug.com/i/c/k/nt_chancerain.gif</icon_url>
    					
    					<title>Saturday Night</title>
    					<fcttext><![CDATA[Windy, with showers. Low 43F. Winds SW at 25 to 35 mph. Chance of rain 80%.]]></fcttext>
    					<fcttext_metric><![CDATA[Windy, with showers. Low 6C. Winds SW at 40 to 55 km/h. Chance of rain 80%.]]></fcttext_metric>
    					<pop>80</pop>
    				</forecastday>
    				
    			
    				<forecastday>
    					<period>6</period>
    					<icon>partlycloudy</icon>
    					<icon_url>http://icons.wxug.com/i/c/k/partlycloudy.gif</icon_url>
    					
    					<title>Sunday</title>
    					<fcttext><![CDATA[Windy and partly cloudy. High 46F. Winds W at 25 to 35 mph.]]></fcttext>
    					<fcttext_metric><![CDATA[Windy and partly cloudy. High 8C. Winds W at 40 to 55 km/h.]]></fcttext_metric>
    					<pop>20</pop>
    				</forecastday>
    
    				
    				<forecastday>
    					<period>7</period>
    					<icon>nt_partlycloudy</icon>
    					<icon_url>http://icons.wxug.com/i/c/k/nt_partlycloudy.gif</icon_url>
    					
    					<title>Sunday Night</title>
    					<fcttext><![CDATA[Partly cloudy. Low 35F. Winds WSW at 15 to 25 mph.]]></fcttext>
    					<fcttext_metric><![CDATA[Partly cloudy. Low 2C. Winds WSW at 25 to 40 km/h.]]></fcttext_metric>
    					<pop>20</pop>
    				</forecastday>
    				
    			
    			</forecastdays>
    		</txt_forecast>
    and here my screenshot


    Compare the text of the fcttext_metric tags to the text in the screenshot.
    The
    Code:
    ![CDATA[
    is in mywug.xml and in forecast.xml.
    DO NOT open xml files in Safari. Safari takes out lots of tags and other stuff.
    Do open the guide in Chrome and then click on the link for the forecast.xml and tell me what do you see!

    EDIT: That is Chrome on the computer, not mobile Chrome, which also strips tags and other stuff.
    Bluefish on Mac also shows the ![CDATA[ in forecast.xml.
    They are in there and they do not matter.
    There is another reason why it does not work with the mywug.xml from your iPhone.
    Could be permission, don't know. Depends where you test, computer or iPhone, Windows or Mac. don't know.

    EDIT2:
    Try this.
    copy the forecast.html from the cydget (plus the js folder) onto your computer.
    Then edit this url
    Code:
    http://api.wunderground.com/api/YOUR_API_KEY/conditions/astronomy/forecast/lang:LI/q/38.898717,-77.035974.xml
    with your API key and paste the complete url in Chrome and see that you have the ![CDATA[ in it (you will have).
    Then replace the /var/mobile/Documents/mywug.xml in forecast.html
    Code:
    $.get("/var/mobile/Documents/mywug.xml", {}, function (data) {
    with the above url (with your api key) and open in Safari or Chrome and it works. The ![CDATA[ is not at fault!

    EDIT3:
    Just opened forecast.xml in Dreamweaver and the ![CDATA[ is in it. It is in any xml that has forecast.
    Last edited by rasputin007; 2015-02-26 at 02:54 PM.
    Nothing is impossible only miracles take a bit longer!
    2015-02-26 02:08 PM
  11. NewD's Avatar
    The
    Code:
    ![CDATA[
    is in mywug.xml and in forecast.xml.
    No it is NOT in forecast.xml on your blog. Not on my computer in Firefox of Chrome. CDATA is ONLY in mywug.xml. That's the problem.
    DO NOT open xml files in Safari. Safari takes out lots of tags and other stuff.
    I know. I never open in Safari for xml.
    Do open the guide in Chrome and then click on the link for the forecast.xml and tell me what do you see!
    I see NO <!CDATA, Ras. I already proved this!
    I don't know what more I can show you as proof, Ras. There is NO !CDATA entry in <fcttext></fcttetxt> when showing forecast.xml in Firefox or Chrome. And in WU's live URL it's not there either in Firefox of Chrome.. I proved that with a photo!!!!

    Your parse code and my parse code do NOT work on either of my phones 6 or 5S - nor any widget I've tried when using the mywug.xml on my phone created by your tweak. It DOES work with both our parse code - when pointing it to forecast.xml from your blog (which has NO CDATA) on computer or phone or pointing it to the live URL from WU (which has NO CDATA)..

    Again -- BOTH live URL response from WU and forecast.xml from your blog do NOT have <!CDATA... in them. I proved that conclusively by showing you the path name in my screenshots.

    Maybe the feeds come through differently in England than in America????.. But as of now - likely no one (in America?) will be able to parse the WU data from the mywug.xml on their phones with your code.. The fact that it may work in your 'ONE' test cydget above - doesn't mean it will work in other's widgets running in GL or GB or iWidgets. You could be using OTHER code in your Cydget to .split off the <!CDATA from <fcttext>. You haven't posted any of your forecast.html code..

    But the parse code you're using can NOT read past the <!CDATA - on my computer nor one my 2 phones. Permissions are all set correctly and can't be the reason for this issue. I'm confident of that.

    I really hoped this could be useful for other widgets outside of Cydget. But as of now I can't recommend it, bro. I'm sorry. If the data in mywug.xml doesn't work for me- it likely won't work for many others either. There's something you're(we're) missing, my friend. I'd like to work with you to resolve the issue. But I need you to accept my proof pictures (NO CDATA except in mywug.xml) as 'proof' and ask yourself the question - "How can Grant be retrieving an <fcttext> with NO CDATA in the tag?".. You can't just ignore my picture proof.. LOL! Please...
    Last edited by NewD; 2015-02-26 at 04:00 PM.
    2015-02-26 03:30 PM
  12. NewD's Avatar
    MORE PROOF:
    Forecast.xml does NOT contain CDATA in <fcttext></fcttext>

    2015-02-26 04:08 PM
  13. rasputin007's Avatar
    LOL

    It is the same url as you have in your screenshot, so we both use the forecast.xml on the MMUS server.
    But yet yours does NOT show the <!CDATA, whereas my screenshot shows that the <!CDATA are in it.
    Every xml file that has the forecast enabled, does not matter if forecast.xml, mywug.xml or live WU response xml file, they all have <!CDATA in them and it does not matter at all.
    Nothing is impossible only miracles take a bit longer!
    2015-02-26 04:27 PM
  14. NewD's Avatar
    More proof:
    With forecast.xml all works..

    With mywug.xml fcttext does not parse. If not for me - then no one (in US? using MAC code editors, Chrome, Firefox??.. .. The <!CDATA.. blocks the sub field because of the extra '
    Last edited by NewD; 2015-02-26 at 04:39 PM.
    2015-02-26 04:35 PM
  15. rasputin007's Avatar
    Even live WU xml files have <!CDATA in it
    Nothing is impossible only miracles take a bit longer!
    2015-02-26 04:37 PM
  16. NewD's Avatar
    Even live WU xml files have <!CDATA in it
    Nope. Not on my computer, sorry.. See my previous proof pics.
    2015-02-26 04:40 PM
  17. rasputin007's Avatar
    This is bizarre!
    All my xml file have <!CDATA in it and it does not matter a bit.
    But it does not seem to work for you.
    That's mind boggling. Same javascript, same source xml file and different results.
    Nothing is impossible only miracles take a bit longer!
    2015-02-26 04:42 PM
  18. NewD's Avatar
    Are you using Linux?

    Try a PC.. On my PC - no <!CDATA either in Firefox or Chrome.

    Basically if I can't build widgets on my Mac or PC using a code editor where the preview will show me my work - it will useless to me - even if it works on the phone.. In Cydget only.. Your forecast.html does NOT work in GroovyLock or Covergence when pointing to mywug.xml with CDATA - works perfectly when pointing to forecast.xml on your blog or Live URL from WU.
    2015-02-26 04:47 PM
  19. NewD's Avatar
    Do we possibly have different versions of the jquery.min.js??

    Could that be it?
    2015-02-26 04:51 PM
  20. rasputin007's Avatar
    Are you using Linux?

    Try a PC.. On my PC - no <!CDATA either in Firefox or Chrome.

    Basically if I can't build widgets on my Mac or PC using a code editor where the preview will show me my work - it will useless to me - even if it works on the phone.. In Cydget only.. Your forecast.html does NOT work in GroovyLock or Covergence when pointing to mywug.xml with CDATA - works perfectly when pointing to forecast.xml on your blog or Live URL from WU.
    I use Mac Yosemite and iOS8 on iPad and iPhone, maybe Windows 7.
    You said something important there, it works when it is NOT a local file.

    Attached is the mywug.xml from my iPad together with a screenshot that it works, despite having <!CDATA in the mywug.xml
    Attached Files
    Nothing is impossible only miracles take a bit longer!
    2015-02-26 04:58 PM
171 12345 ...
LINK TO POST COPIED TO CLIPBOARD