Skip to content

Commit

Permalink
Report location if allowed by settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
hsorby committed Sep 26, 2023
1 parent b78c18f commit e831efd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/mapclient/core/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ def error_occurred(self, plugin_name, error_type):

self._log_event(event)

def report_location(self):
event = {
"name": "location",
"params": _geolocate(),
}

self._log_event(event)

def _log_event(self, event):
if self._permission:
event_data = {
Expand All @@ -104,3 +112,21 @@ def _log_event(self, event):

def get_metrics_logger():
return metrics_logger


def _geolocate():
url = 'https://ipinfo.io/json'
response = requests.get(url)
if response.ok:
json_data = response.json()
location = {
'country': json_data.get('country', 'not-set'),
'city': json_data.get('city', 'not-set'),
}
else:
location = {
'country': 'unknown',
'city': 'unknown'
}

return location
3 changes: 2 additions & 1 deletion src/mapclient/view/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from mapclient import version
from mapclient.view.ui.ui_mainwindow import Ui_MainWindow
from mapclient.view.workflow.workflowwidget import WorkflowWidget
from mapclient.settings.general import unrestrict_plugins, settings_file_exists
from mapclient.settings.general import unrestrict_plugins
from mapclient.settings.info import DEFAULT_WORKFLOW_ANNOTATION_FILENAME
from mapclient.settings.definitions import WIZARD_TOOL_STRING, METRICS_PERMISSION, \
PMR_TOOL_STRING, PYSIDE_RCC_EXE, USE_EXTERNAL_RCC, PYSIDE_UIC_EXE, USE_EXTERNAL_UIC, \
Expand Down Expand Up @@ -252,6 +252,7 @@ def initialise_metrics_logger(self):
om.setOption(METRICS_PERMISSION, permission)
om.setOption(METRICS_PERMISSION_ATTAINED, permissions)
metrics_logger.initial_permission_status(permission)
metrics_logger.report_location()

self.apply_permission_settings()

Expand Down

0 comments on commit e831efd

Please sign in to comment.