Пример #1
0
def add_one_tracker_to_submitted_deque(url):
    try:
        ip_address(urlparse(url).hostname)
        logger.info(f"Tracker {url} denied, hostname is IP")
        return
    except ValueError:
        pass
    with deque_lock:
        for tracker_in_deque in submitted_trackers:
            if urlparse(tracker_in_deque.url).netloc == urlparse(url).netloc:
                logger.info(f"Tracker {url} denied, already in the queue")
                return
    with list_lock:
        for tracker in db.get_all_data():
            if tracker.host == urlparse(url).hostname:
                logger.info(f"Tracker {url} denied, already being tracked")
                return
    try:
        tracker_candidate = Tracker.from_url(url)
    except (RuntimeError, ValueError) as e:
        logger.info(f"Tracker {url} preprocessing failed, reason: {str(e)}")
        return
    all_ips_tracked = get_all_ips_tracked()
    exists_ip = set(tracker_candidate.ip).intersection(all_ips_tracked)
    if exists_ip:
        logger.info(
            f"Tracker {url} denied, IP of the tracker is already in the list")
        return
    with deque_lock:
        submitted_trackers.append(tracker_candidate)
    logger.info(f"Tracker {url} added to the submitted queue")
Пример #2
0
def get_all_data():
    conn = sqlite3.connect(db_file)
    conn.row_factory = dict_factory
    c = conn.cursor()
    trackers_from_db = []
    for row in c.execute("SELECT * FROM STATUS ORDER BY uptime DESC"):
        tracker_in_db = Tracker(
            url=row.get("url"),
            host=row.get("host"),
            ip=json.loads(row.get("ip")),
            latency=row.get("latency"),
            last_checked=row.get("last_checked"),
            interval=row.get("interval"),
            status=row.get("status"),
            uptime=row.get("uptime"),
            country=json.loads(row.get("country")),
            country_code=json.loads(row.get("country_code")),
            historic=deque(json.loads((row.get("historic"))), maxlen=1000),
            added=row.get("added"),
            network=json.loads(row.get("network")),
            last_downtime=row.get("last_downtime"),
            last_uptime=row.get("last_uptime"),
        )
        trackers_from_db.append(tracker_in_db)
    conn.close()
    return trackers_from_db