diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2015-05-03 00:41:45 +0200 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2015-05-04 02:13:04 +0200 |
commit | f3398b70d49e8146b33ff572ff7fe03d2dfa200c (patch) | |
tree | 7f3b58f036f3476f8390e21c426bca80520d0583 /iss_get_data.js | |
parent | 6cf5b918ad54b4d674b410c6ce27a4bcb704aa76 (diff) | |
download | ISS_Above-f3398b70d49e8146b33ff572ff7fe03d2dfa200c.tar.gz |
Trying to make the script working.
Diffstat (limited to 'iss_get_data.js')
-rw-r--r-- | iss_get_data.js | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/iss_get_data.js b/iss_get_data.js new file mode 100644 index 0000000..cf97015 --- /dev/null +++ b/iss_get_data.js @@ -0,0 +1,97 @@ +#!/usr/bin/gjs +/* global imports */ + +const Json = imports.gi.Json; +const GLib = imports.gi.GLib; +const Gio = imports.gi.Gio; +const Lang = imports.lang; +const Mainloop = imports.mainloop; + +const AccuracyLevel = { + COUNTRY: 1, + CITY: 4, + NEIGHBORHOOD: 5, + STREET: 6, + EXACT: 8 +}; + +const ManagerIface = '<node> \ + <interface name="org.freedesktop.GeoClue2.Manager"> \ + <method name="GetClient"> \ + <arg type="o" name="client" direction="out"/> \ + </method> \ + </interface> \ +</node>'; +const ManagerProxy = Gio.DBusProxy.makeProxyWrapper(ManagerIface); + +const ClientInterface = '<node> \ +<interface name="org.freedesktop.GeoClue2.Client"> \ + <property name="Location" type="o" access="read"/> \ + <property name="DesktopId" type="s" access="readwrite"/> \ + <property name="RequestedAccuracyLevel" type="u" access="readwrite"/> \ + <property name="DistanceThreshold" type="u" access="readwrite"/> \ + <property name="Active" type="b" access="read"/> \ + <method name="Start"/> \ + <method name="Stop"/> \ + <signal name="LocationUpdated"> \ + <arg name="old" type="o"/> \ + <arg name="new" type="o"/> \ + </signal> \ +</interface> \ +</node>'; +const ClientProxy = Gio.DBusProxy.makeProxyWrapper(ClientInterface); + +const LocationInterface = '<node> \ +<interface name="org.freedesktop.GeoClue2.Location"> \ + <property name="Latitude" type="d" access="read"/> \ + <property name="Longitude" type="d" access="read"/> \ + <property name="Accuracy" type="d" access="read"/> \ + <property name="Description" type="s" access="read"/> \ +</interface> \ +</node>'; +const LocationProxy = Gio.DBusProxy.makeProxyWrapper(LocationInterface); + +function get_ISS_coords() { + const API_URL = 'http://api.open-notify.org/iss-now.json'; + // let iss_api = Gio.file_new_for_uri(API_URL); + let iss_api = Gio.file_new_for_uri(API_URL); + print('filename: ' + iss_api + '\n---------------'); + iss_api.load_contents_async(null, function(data) { + print('data = ' + data); + let iss_coords = JSON.parse(data); + print(Object.keys(iss_coords)); + print(iss_coords.toSource()); + iss_api.load_contents_finish(data); + }); +} + +function onLocationUpdated(proxy, sender, [oldPath, newPath]) { + let geoclueLocation = new LocationProxy(Gio.DBus.system, + "org.freedesktop.GeoClue2", + newPath); + print('location:'); + print('\tlatitude = ' + geoclueLocation.Latitude); + print('\tlongitude = ' + geoclueLocation.Longitude); + print('\taccuracy = ' + geoclueLocation.Accuracy); + print('\tdescription = ' + geoclueLocation.Description); + //this._updateLocation(location); + Mainloop.quit(); +} + +const _managerProxy = new ManagerProxy(Gio.DBus.system, + 'org.freedesktop.GeoClue2', '/org/freedesktop/GeoClue2/Manager'); + +const [clientAddr] = _managerProxy.GetClientSync(); + +const clientProxy = new ClientProxy(Gio.DBus.system, + 'org.freedesktop.GeoClue2', clientAddr); +clientProxy.DesktopId = 'gnome-shell-ISS_Above'; +clientProxy.DistanceThreshold = 10000; +clientProxy.RequestedAccuracyLevel = AccuracyLevel.EXACT; +let updatedId = clientProxy.connectSignal('LocationUpdated', + onLocationUpdated); +clientProxy.StartRemote(); + +get_ISS_coords(); + +Mainloop.run(); |