def send_statistics(url): """Send the statistics to the remote at `url`""" import json import requests settings = QSettings() if not settings.value( "error-reporting/send-statistics", False, type=bool): log.info("Not sending usage statistics (preferences setting).") return if not UsageStatistics.is_enabled(): log.info("Not sending usage statistics (disabled).") return usage = UsageStatistics() data = usage.load() for d in data: d["Orange Version"] = d.pop("Application Version", "") try: r = requests.post(url, files={'file': json.dumps(data)}) if r.status_code != 200: log.warning( "Error communicating with server while attempting to send " "usage statistics.") return # success - wipe statistics file log.info("Usage statistics sent.") with open(usage.filename(), 'w', encoding="utf-8") as f: json.dump([], f) except (ConnectionError, requests.exceptions.RequestException): log.warning( "Connection error while attempting to send usage statistics.") except Exception: # pylint: disable=broad-except log.warning("Failed to send usage statistics.", exc_info=True)
def send_statistics(url): """Send the statistics to the remote at `url`""" import json import requests settings = QSettings() if not settings.value("reporting/send-statistics", False, type=bool): log.info("Not sending usage statistics (preferences setting).") return if not UsageStatistics.is_enabled(): log.info("Not sending usage statistics (disabled).") return if settings.contains('reporting/machine-id'): machine_id = settings.value('reporting/machine-id') else: machine_id = str(uuid.uuid4()) settings.setValue('reporting/machine-id', machine_id) is_anaconda = 'Continuum' in sys.version or 'conda' in sys.version data = UsageStatistics.load() for d in data: d["Orange Version"] = d.pop("Application Version", "") d["Anaconda"] = is_anaconda d["UUID"] = machine_id try: r = requests.post(url, files={'file': json.dumps(data)}) if r.status_code != 200: log.warning( "Error communicating with server while attempting to send " "usage statistics. Status code " + str(r.status_code)) return # success - wipe statistics file log.info("Usage statistics sent.") with open(UsageStatistics.filename(), 'w', encoding="utf-8") as f: json.dump([], f) except (ConnectionError, requests.exceptions.RequestException): log.warning( "Connection error while attempting to send usage statistics.") except Exception: # pylint: disable=broad-except log.warning("Failed to send usage statistics.", exc_info=True)