<commit_before>#!/usr/bin/env python
# Copyright: 2016, Wasylews
# Author: Wasylews
# License: MIT

"""hilink-tray - display signal level for HiLink modems in a tray

Usage:
    hilink-tray.py [--timeout=N] [--ip=IP] [--log=LOGFILE]
    hilink-tray.py -h | --help
    hilink-tray.py -v | --version

Options:
    -t N --timeout=N  download icon each N seconds
                      [default: 5]
    --ip=IP           modem ip
                      [default: 192.168.8.1]
    --log=LOGFILE     write logs to this file
                      [default: err.log]
    -v --version      show version
    -h --help         show this message and exit
"""

from __future__ import print_function
import docopt
import sys
import logging
import os.path as path
from PySide import QtGui, QtCore
from xml.etree import ElementTree
import socket
from collections import OrderedDict

try:
    import urllib2 as urllib
    from urlparse import urljoin
except ImportError:  # >= 3.x
    import urllib
    from urllib.parse import urljoin


class ModemSignalChecker(QtCore.QThread):
    """Class for monitoring some modem parameters and send to gui"""
    levelChanged = QtCore.Signal(int, dict)

    def __init__(self, ip, timeout):
        super(ModemSignalChecker, self).__init__()
        self._url = "http://{}".format(ip)
        self._timeout = timeout
        self._running = True

    def stop(self):
        self._running = False

    def _getXml(self, opener, section):
        response = opener.open(urljoin(self._url, section), timeout=1)
        return ElementTree.fromstring(response.read())

    def getCookie(self, opener):
        try:
            xml = self._getXml(opener, "/api/webserver/SesTokInfo")
        except urllib.URLError:
            return ""
        else:
            return xml.find("SesInfo").text

    def getSignalLevel(self, xml):
        return int(xml.find("SignalIcon").text)

    def getNetworkType(self, xml):
        types = {"0": "No Service", "1": "GSM", "2": "GPRS", "3": "EDGE",
                 "41": "WCDMA", "42": "HSDPA", "43": "HSUPA", "44": "HSPA",
                 "45": "HSPA+", "46": "DC-HSPA+", "101": "LTE"}

        return types[xml.find("CurrentNetworkTypeEx").text]<commit_msg>use default timeout<commit_after>#!/usr/bin/env python
# Copyright: 2016, Wasylews
# Author: Wasylews
# License: MIT

"""hilink-tray - display signal level for HiLink modems in a tray

Usage:
    hilink-tray.py [--timeout=N] [--ip=IP] [--log=LOGFILE]
    hilink-tray.py -h | --help
    hilink-tray.py -v | --version

Options:
    -t N --timeout=N  download icon each N seconds
                      [default: 5]
    --ip=IP           modem ip
                      [default: 192.168.8.1]
    --log=LOGFILE     write logs to this file
                      [default: err.log]
    -v --version      show version
    -h --help         show this message and exit
"""

from __future__ import print_function
import docopt
import sys
import logging
import os.path as path
from PySide import QtGui, QtCore
from xml.etree import ElementTree
import socket
from collections import OrderedDict

try:
    import urllib2 as urllib
    from urlparse import urljoin
except ImportError:  # >= 3.x
    import urllib
    from urllib.parse import urljoin


class ModemSignalChecker(QtCore.QThread):
    """Class for monitoring some modem parameters and send to gui"""
    levelChanged = QtCore.Signal(int, dict)

    def __init__(self, ip, timeout):
        super(ModemSignalChecker, self).__init__()
        self._url = "http://{}".format(ip)
        self._timeout = timeout
        self._running = True

    def stop(self):
        self._running = False

    def _getXml(self, opener, section):
        response = opener.open(urljoin(self._url, section))
        return ElementTree.fromstring(response.read())

    def getCookie(self, opener):
        try:
            xml = self._getXml(opener, "/api/webserver/SesTokInfo")
        except urllib.URLError:
            return ""
        else:
            return xml.find("SesInfo").text

    def getSignalLevel(self, xml):
        return int(xml.find("SignalIcon").text)

    def getNetworkType(self, xml):
        types = {"0": "No Service", "1": "GSM", "2": "GPRS", "3": "EDGE",
                 "41": "WCDMA", "42": "HSDPA", "43": "HSUPA", "44": "HSPA",
                 "45": "HSPA+", "46": "DC-HSPA+", "101": "LTE"}

        return types[xml.find("CurrentNetworkTypeEx").text]
{'fraction_non_alphanumeric': 0.12683367185736855, 'fraction_numerical': 0.015572105619498984, 'mean_word_length': 2.403993855606759, 'pattern_counts': {'":': 22, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '862495', 'n_tokens_mistral': 1466, 'n_tokens_neox': 1401, 'n_words': 400}