update big NGC

This commit is contained in:
2022-09-27 13:51:50 +00:00
parent 675bf1b2b9
commit 870e3125ad
122 changed files with 2945 additions and 768 deletions

View File

@ -1,20 +1,40 @@
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
import json
import urllib.request
import utils.util as util
from PyQt5 import QtNetwork, QtCore
try:
import requests
except ImportError:
requests = None
global LOG
import logging
LOG = logging.getLogger('app.'+__name__)
class ToxDns:
def __init__(self, settings):
def __init__(self, settings, log=None):
self._settings = settings
self._log = log
@staticmethod
def _send_request(url, data):
req = urllib.request.Request(url)
req.add_header('Content-Type', 'application/json')
response = urllib.request.urlopen(req, bytes(json.dumps(data), 'utf-8'))
res = json.loads(str(response.read(), 'utf-8'))
if requests:
LOG.info('send_request loading with requests: ' + str(url))
headers = dict()
headers['Content-Type'] = 'application/json'
req = requests.get(url, headers=headers)
if req.status_code < 300:
retval = req.content
else:
raise LookupError(str(req.status_code))
else:
req = urllib.request.Request(url)
req.add_header('Content-Type', 'application/json')
response = urllib.request.urlopen(req, bytes(json.dumps(data), 'utf-8'))
retval = response.read()
res = json.loads(str(retval, 'utf-8'))
if not res['c']:
return res['tox_id']
else:
@ -29,12 +49,25 @@ class ToxDns:
site = email.split('@')[1]
data = {"action": 3, "name": "{}".format(email)}
urls = ('https://{}/api'.format(site), 'http://{}/api'.format(site))
if not self._settings['proxy_type']: # no proxy
if requests:
for url in urls:
LOG.info('TOX nodes loading with requests: ' + str(url))
try:
headers = dict()
headers['Content-Type'] = 'application/json'
req = requests.get(url, headers=headers)
if req.status_code < 300:
result = req.content
return result
except Exception as ex:
LOG.error('ERROR: TOX DNS loading error with requests: ' + str(ex))
elif not self._settings['proxy_type']: # no proxy
for url in urls:
try:
return self._send_request(url, data)
except Exception as ex:
util.log('TOX DNS ERROR: ' + str(ex))
LOG.error('ERROR: TOX DNS ' + str(ex))
else: # proxy
netman = QtNetwork.QNetworkAccessManager()
proxy = QtNetwork.QNetworkProxy()
@ -60,6 +93,6 @@ class ToxDns:
if not result['c']:
return result['tox_id']
except Exception as ex:
util.log('TOX DNS ERROR: ' + str(ex))
LOG.error('ERROR: TOX DNS ' + str(ex))
return None # error