Registration is disabled!

Inner working of MYO 6

Everything related to MYO6 is inside here
Post Reply
User avatar
rasputin007
Posts: 36
Joined: Mon Sep 28, 2015 6:27 pm

Inner working of MYO 6

Post by rasputin007 » Thu Oct 01, 2015 9:16 pm

This is a detailed description of how MYO 6 works!
After you installed MYO 6, you will find a new menu in Settings, called WUG Setup.

Image

In this WUG Setup menu you enter your WeatherUnderground API key and select your preferred language. These will be stored in /var/mobile/Library/Preferences/com.gps.wug.plist.
What you don't see is that with MYO 6 also comes a LaunchDaemons file which will run a shell script every 5 minutes. This shell script is actually a cycript script in an executable shell script.
This cycript script has this content

Code: Select all

#!/usr/bin/cycript -p SpringBoard
	var loc, key, lang;
	WPref = [WeatherPreferences sharedPreferences]; 
	WLocation = [WeatherLocationManager sharedWeatherLocationManager]; 
	WCity = [WPref localWeatherCity];
	LUpdate = [TWCLocationUpdater sharedLocationUpdater];
	[WLocation setDelegate:[[CLLocationManager alloc] init]];
	[WLocation setLocationTrackingReady:YES activelyTracking:NO watchKitExtension:NO];
	[WLocation setLocationTrackingActive:YES];
	[WPref setLocalWeatherEnabled:YES];
	[LUpdate updateWeatherForLocation:[WLocation location] city:WCity];
	loc = WCity.locationID;
	loc = loc.split(',');
	var settings = [NSDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/com.gps.wug.plist"];
       if(settings!=null){
			key=settings.api_key;
			lang=settings.language;
       }
  	url = 'http://api.wunderground.com/api/'+key+'/forecast/conditions/astronomy/hourly/lang:'+lang+'/q/'+loc[0]+','+loc[1]+'.xml'
  	url = [NSURL URLWithString:url];
  	var urlData = [NSData dataWithContentsOfURL:url];
    var filePath = 'var/mobile/Documents/wug.xml';
    [urlData writeToFile:filePath atomically:YES];
  	url = null;
  	urlData = null;
What happens here is that this cycript script will get the current GPS coordinates from the Weatherframework (just like WW2), then it will get the API key and language selection from the plist file. Next it will use the API key, the language selection, latitude and longitude to complete an url call to WeatherUnderground. Once it gets the xml response file it will save this as wug.xml in the /var/mobile/Documents folder on your device.
This happens every 5 minutes and takes seconds to do.

Now that cycript script is also part of the MYO 6 cydget, but slightly changed.

Code: Select all

<script type="text/cycript">
getDict = function(){
    return [NSDictionary dictionaryWithContentsOfFile: @"/var/mobile/Library/Preferences/com.gps.wug.plist"];
};

var loc, lati, longi;
	
getUpdate = function(){// full gps
	WPref = [WeatherPreferences sharedPreferences]; 
	WLocation = [WeatherLocationManager sharedWeatherLocationManager]; 
	WCity = [WPref localWeatherCity];
	LUpdate = [TWCLocationUpdater sharedLocationUpdater];
	[WLocation setDelegate:[[CLLocationManager alloc] init]];
	[WLocation setLocationTrackingReady:YES activelyTracking:NO watchKitExtension:NO];
	[WLocation setLocationTrackingActive:YES];
	[WPref setLocalWeatherEnabled:YES];
	[LUpdate updateWeatherForLocation:[WLocation location] city:WCity];
		loc = WCity.locationID;
		loc = loc.split(',');
		obj.latitude = loc[0];
		obj.longitude = loc[1];
		nextStep();
	}

saveFile=function(){
	var loc, key, lang;
	WPref = [WeatherPreferences sharedPreferences]; 
	WLocation = [WeatherLocationManager sharedWeatherLocationManager]; 
	WCity = [WPref localWeatherCity];
	LUpdate = [TWCLocationUpdater sharedLocationUpdater];
	[WLocation setDelegate:[[CLLocationManager alloc] init]];
	[WLocation setLocationTrackingReady:YES activelyTracking:NO watchKitExtension:NO];
	[WLocation setLocationTrackingActive:YES];
	[WPref setLocalWeatherEnabled:YES];
	[LUpdate updateWeatherForLocation:[WLocation location] city:WCity];
	loc = WCity.locationID;
	loc = loc.split(',');
	var settings = [NSDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/com.gps.wug.plist"];
       if(settings!=null){
			key=settings.api_key;
			lang=settings.language;
       }
  	url = 'http://api.wunderground.com/api/'+key+'/forecast/conditions/astronomy/hourly/lang:'+lang+'/q/'+loc[0]+','+loc[1]+'.xml'
  	url = [NSURL URLWithString:url];
  	var urlData = [NSData dataWithContentsOfURL:url];
    var filePath = 'var/mobile/Documents/wug.xml';
    [urlData writeToFile:filePath atomically:YES];
  	url = null;
  	urlData = null;
 }

</script>
It simply has been divided into functions, so it can work together with javascript. The reason is that the update feature on the MYO 6 lockscreen (just tap the “Updated: some time” text) will start this lot and not only update the current GPS coordinates and fetches the latest xml response file from WeatherUnderground, it also saves this one as the wug.xml file. This will benefit also the other 2 cydgets that come with MYO 6, the hour by hour forecast cydget and the 5 day/night/ text forecast, which will be in the language you selected.
Nothing is impossible, only miracles take a bit longer!

Post Reply