Example #1
0
    def get_geoip_lookup(self, ip_address=''):
        if not ip_address or not helpers.is_valid_ip(ip_address):
            return

        geoip_data = self.get_plextv_geoip(ip_address=ip_address, output_format='xml')

        try:
            xml_head = geoip_data.getElementsByTagName('location')
        except Exception as e:
            logger.warn(u"Tautulli PlexTV :: Unable to parse XML for get_geoip_lookup: %s." % e)
            return None

        for a in xml_head:
            coordinates = helpers.get_xml_attr(a, 'coordinates').split(',')
            latitude = longitude = None
            if len(coordinates) == 2:
                latitude, longitude = [helpers.cast_to_float(c) for c in coordinates]

            geo_info = {"code": helpers.get_xml_attr(a, 'code') or None,
                        "country": helpers.get_xml_attr(a, 'country') or None,
                        "region": helpers.get_xml_attr(a, 'subdivisions') or None,
                        "city": helpers.get_xml_attr(a, 'city') or None,
                        "postal_code": helpers.get_xml_attr(a, 'postal_code') or None,
                        "timezone": helpers.get_xml_attr(a, 'time_zone') or None,
                        "latitude": latitude,
                        "longitude": longitude,
                        "continent": None,  # keep for backwards compatibility with GeoLite2
                        "accuracy": None   # keep for backwards compatibility with GeoLite2
                        }

            return geo_info
Example #2
0
    def settings(self, getConfigVal=None, paramName=None, paramVal=None):
        if (not paramName is None) and (not paramVal is None):
            try:
                if not str(pacvert.CONFIG.__getattr__(paramName)) is paramVal:
                    if type(_CONFIG_DEFINITIONS[paramName][2]) is dict:
                        result = {}
                        if len(paramVal) > 0:
                            firstSplit = str(paramVal).split(",")
                            for elem in firstSplit:
                                secondSplit = elem.split(":")
                                result[secondSplit[0]] = str(secondSplit[1])
                            pacvert.CONFIG.__setattr__(paramName, result)
                    elif type(_CONFIG_DEFINITIONS[paramName][2]) is list:
                        pacvert.CONFIG.__setattr__(paramName, paramVal.split(","))
                    elif type(_CONFIG_DEFINITIONS[paramName][2]) is float:
                        pacvert.CONFIG.__setattr__(paramName, cast_to_float(paramVal))
                    elif type(_CONFIG_DEFINITIONS[paramName][2]) is int:
                        pacvert.CONFIG.__setattr__(paramName, cast_to_int(paramVal))
                    else:
                        pacvert.CONFIG.__setattr__(paramName, paramVal)
                pacvert.CONFIG.FIRST_RUN_COMPLETE = True
                return "OK."
            except:
                 return "Nope."
        if not getConfigVal is None:
            tempConfig = {'General': {}, 'CodecSettings': {}, 'Advanced': {}}
            for element in _CONFIG_DEFINITIONS:
                if type(_CONFIG_DEFINITIONS[element][2]) is str:
                    thistype = "str"
                elif type(_CONFIG_DEFINITIONS[element][2]) is int:
                    thistype = "int"
                elif type(_CONFIG_DEFINITIONS[element][2]) is float:
                    thistype = "float"
                elif type(_CONFIG_DEFINITIONS[element][2]) is dict:
                    thistype = "dict"
                elif type(_CONFIG_DEFINITIONS[element][2]) is bool:
                    thistype = "bool"
                elif type(_CONFIG_DEFINITIONS[element][2]) is list:
                    thistype = "list"
                else:
                    thistype = "unknown"
                tempConfig[_CONFIG_DEFINITIONS[element][1]][element] = {'value': pacvert.CONFIG.__getattr__(element), 'type': thistype}
                    

            return json.dumps(tempConfig)
        return "Nope."#serve_template(templatename="settings.html", title="Settings")