Last active
May 22, 2019 05:03
-
-
Save cwells/ad49eb91dd21b2947209583dd29db20f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import dbus | |
from dbus.mainloop.glib import DBusGMainLoop | |
from gi.repository import GLib | |
GEOCLUE = 'org.freedesktop.GeoClue2' | |
DBUS_PROPERTIES = 'org.freedesktop.DBus.Properties' | |
GCLUE_ACCURACY_LEVEL_COUNTRY = dbus.UInt32(1) | |
GCLUE_ACCURACY_LEVEL_CITY = dbus.UInt32(4) | |
GCLUE_ACCURACY_LEVEL_NEIGHBORHOOD = dbus.UInt32(5) | |
GCLUE_ACCURACY_LEVEL_STREET = dbus.UInt32(6) | |
GCLUE_ACCURACY_LEVEL_EXACT = dbus.UInt32(8) | |
def location_updated(old_path, new_path): | |
global bus | |
location_object = bus.get_object(GEOCLUE, new_path) | |
location_properties = dbus.Interface(location_object, DBUS_PROPERTIES) | |
latitude = location_properties.Get(f'{GEOCLUE}.Location', 'Latitude') | |
longitude = location_properties.Get(f'{GEOCLUE}.Location', 'Longitude') | |
# accuracy = location_properties.Get(f'{GEOCLUE}.Location', 'Accuracy') | |
url = f'https://maps.google.com/maps?q={latitude},{longitude}' | |
print(url) | |
dbus_loop = DBusGMainLoop(set_as_default=True) | |
bus = dbus.SystemBus(mainloop=dbus_loop) | |
manager_proxy = bus.get_object(GEOCLUE, f'/{GEOCLUE.replace(".", "/")}/Manager') | |
manager_iface = dbus.Interface(manager_proxy, f'{GEOCLUE}.Manager') | |
client_path = manager_iface.CreateClient() | |
client_proxy = bus.get_object(GEOCLUE, client_path) | |
client_iface = dbus.Interface(client_proxy, f'{GEOCLUE}.Client') | |
client_props_iface = dbus.Interface(client_iface, DBUS_PROPERTIES) | |
client_props = client_props_iface.GetAll(f'{GEOCLUE}.Client') | |
client_props_iface.Set(f'{GEOCLUE}.Client', 'DesktopId', 'geolocation.desktop') | |
client_props_iface.Set(f'{GEOCLUE}.Client', 'RequestedAccuracyLevel', GCLUE_ACCURACY_LEVEL_EXACT) | |
client_iface.Start() | |
client_iface.connect_to_signal('LocationUpdated', location_updated) | |
loop = GLib.MainLoop() | |
GLib.timeout_add(10000, loop.quit) | |
loop.run() | |
client_iface.Stop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment