diff -Nru my-weather-indicator-0.9.0/debian/changelog my-weather-indicator-0.9.0/debian/changelog --- my-weather-indicator-0.9.0/debian/changelog 2017-11-09 18:43:18.000000000 +0000 +++ my-weather-indicator-0.9.0/debian/changelog 2017-11-09 19:08:25.000000000 +0000 @@ -1,10 +1,10 @@ -my-weather-indicator (0.9.0-0extras17.10.3) artful; urgency=medium +my-weather-indicator (0.9.0-0extras17.10.4) artful; urgency=medium * Updated location * Fixed some bugs * check_connection updated with two options - -- Lorenzo Carbonell Thu, 09 Nov 2017 19:43:18 +0100 + -- Lorenzo Carbonell Thu, 09 Nov 2017 20:08:25 +0100 my-weather-indicator (0.8.1-0extras16.04.1) xenial; urgency=medium diff -Nru my-weather-indicator-0.9.0/src/check_connection.py my-weather-indicator-0.9.0/src/check_connection.py --- my-weather-indicator-0.9.0/src/check_connection.py 2017-11-09 18:40:20.000000000 +0000 +++ my-weather-indicator-0.9.0/src/check_connection.py 2017-11-09 19:07:40.000000000 +0000 @@ -18,7 +18,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . - +import http.client import requests import socket import time @@ -29,6 +29,9 @@ '216.58.192.142', 'www.baidu.com'] for asocket in sockets: + if check_connectivity_with_httpconnection(asocket): + return True + for asocket in sockets: if check_connectivity_with_socket(asocket): return True urls = ['https://www.google.com', @@ -41,13 +44,14 @@ return False -def check_connectivity_with_reference(reference, timeout=2): +def check_connectivity_with_httpconnection(reference): try: - requests.get(reference, timeout=timeout, verify=False) - print('OK. Internet connection. Url: {0}'.format(reference)) + conn = http.client.HTTPConnection(reference) + conn.close() + print('OK. Internet connection. HTTPConnection: {0}'.format(reference)) return True except Exception as ex: - print('NO internet connection. Url: {0}'.format(reference)) + print('NO internet connection. HTTPConnection: {0}'.format(reference)) print('Error:', ex) print('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^') return False @@ -55,7 +59,8 @@ def check_connectivity_with_socket(reference, port=80): try: - socket.create_connection((reference, port)) + conn = socket.create_connection((reference, port)) + conn.close() print('OK. Internet connection. Socket: {0}'.format(reference)) return True except Exception as ex: @@ -65,6 +70,18 @@ return False +def check_connectivity_with_reference(reference, timeout=2): + try: + requests.get(reference, timeout=timeout, verify=False) + print('OK. Internet connection. Url: {0}'.format(reference)) + return True + except Exception as ex: + print('NO internet connection. Url: {0}'.format(reference)) + print('Error:', ex) + print('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^') + return False + + if __name__ == '__main__': atime = time.time() print(check_connectivity(), time.time() - atime) @@ -76,14 +93,19 @@ sockets = ['www.google.com', '216.58.192.142', 'www.baidu.com'] - print('======== URLS ========') - for index, url in enumerate(urls): + print('======== SOCKET ========') + for index, asocket in enumerate(sockets): atime = time.time() - print(index, check_connectivity_with_reference(url), url, + print(index, check_connectivity_with_httpconnection(asocket), asocket, time.time() - atime) print('======== SOCKET ========') for index, asocket in enumerate(sockets): atime = time.time() print(index, check_connectivity_with_socket(asocket), asocket, time.time() - atime) - ''' + print('======== URLS ========') + for index, url in enumerate(urls): + atime = time.time() + print(index, check_connectivity_with_reference(url), url, + time.time() - atime) + ''' \ No newline at end of file diff -Nru my-weather-indicator-0.9.0/src/geolocation.py my-weather-indicator-0.9.0/src/geolocation.py --- my-weather-indicator-0.9.0/src/geolocation.py 2017-07-04 14:55:26.000000000 +0000 +++ my-weather-indicator-0.9.0/src/geolocation.py 2017-11-09 18:50:00.000000000 +0000 @@ -50,7 +50,7 @@ if __name__ == '__main__': ip = get_external_ip() if ip is not None: - ll = get_latitude_longitude(ip) + ll = get_latitude_longitude_city(ip) if ll is not None: print(ll) exit(0)