SHARE
TWEET

Untitled

a guest Mar 25th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/local/bin/python3
  2. import sys
  3. import traceback
  4. import json
  5. import socket
  6. import requests
  7. import PySimpleGUIQt as sg
  8.  
  9.  
  10. def report_error(e, url=None):
  11.     tb = traceback.format_exc()
  12.  
  13.     if not internet() or url is None:
  14.         sg.PopupScrolled(f'The following error occured:\n{tb}')
  15.         sys.exit(1)
  16.  
  17.     data = json.dumps([sys.platform, sys.version, tb])
  18.     p = sg.PopupScrolled(f'The following error has occured:\n{tb}\nWould you like to report this error?', yes_no=True)
  19.     if p == 'Yes':
  20.         print(f'Sending post request to {url}')
  21.         requests.post(url, data=data)
  22.  
  23.     else:
  24.         print('User declined to report error')
  25.  
  26.     sys.exit(1)
  27.  
  28. def internet(host="8.8.8.8", port=53, timeout=3):
  29.     """
  30.     Host: 8.8.8.8 (google-public-dns-a.google.com)
  31.     OpenPort: 53/tcp
  32.     Service: domain (DNS/TCP)
  33.     """
  34.     try:
  35.         socket.setdefaulttimeout(timeout)
  36.         socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port))
  37.         return True
  38.  
  39.     except Exception as e:
  40.         return False
  41.  
  42. if __name__ == '__main__':
  43.     try:
  44.         print(f)
  45.  
  46.     except Exception as e:
  47.         report_error(e)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top