Exemplo n.º 1
0
 def text(self):
     if 'html_text' in self.object_dict:
         parser = HTMLTextParser()
         parser.feed(self.object_dict['html_text'])
         parser.close()
         return parser.get_formatted_text()
     else:
         return [self.object_dict['text']]
Exemplo n.º 2
0
def dehtml(text):
    try:
        parser = _DeHTMLParser()
        parser.feed(str(text))
        parser.close()
        return parser.text()
    except:
        from traceback import print_exc
        print_exc(file=sys.stderr)
        return text
Exemplo n.º 3
0
 def description(self):
     if 'html_notes' in self.object_dict:
         parser = HTMLTextParser()
         parser.feed(self.object_dict['html_notes'])
         parser.close()
         text = parser.get_formatted_text()
         if (len(text) > 0):
             return text
         else:
             return ""
     elif 'notes' in self.object_dict:
         return self.object_dict['notes']
     else:
         return ""
Exemplo n.º 4
0
def parse_revisions(filename):
    parser = xml.sax.make_parser(["xml.sax.IncrementalParser"])
    ready = deque()
    def deliver(x):
        ready.append(x)
    handler = DocumentHandler()
    handler.callback = deliver
    parser.setContentHandler(handler)
    with gzip.GzipFile(filename, "r") as raw_f:
        f = codecs.EncodedFile(raw_f, "utf8")
        for line in f:
            parser.feed(line)
            while ready:
                yield ready.popleft()
        parser.close()
        while ready:
            yield ready.popleft()
Exemplo n.º 5
0
def grab_songs_from_session(session):
	"""Downloads the songs from the session it's handed"""
	
	print "grabbing", session.title, "-", session.updated, "..."
	sock = urllib.urlopen(session.link)
	html = sock.read()
	sock.close()
	
	parser = DaytrotterParser()
	parser.parse(html)
	parser.close()
	
	urls = parser.get_song_urls()
	
	for url in urls:
		encoded_filename = url.split("/")[-1]
		filename = urllib.unquote(encoded_filename)
		print "\tgrabbing", filename
		urllib.urlretrieve(url, filename)
Exemplo n.º 6
0
 def _parse_xml_string_to_dom(self, xml_string: str) -> ETree.Element:
     try:
         parser = ETree.XMLParser(target=ETree.TreeBuilder(), encoding=self.DEFAULT_ENCODING)
         parser.feed(xml_string)
         root = parser.close()
     except ETree.ParseError as e:
         raise RequestParserError(
             "Unable to parse request (%s), invalid XML received:\n%s" % (e, xml_string)
         )
     return root
Exemplo n.º 7
0
 def _parse_xml_string_to_dom(xml_string: str) -> ETree.Element:
     try:
         parser = ETree.XMLParser(target=ETree.TreeBuilder())
         parser.feed(xml_string)
         root = parser.close()
     except ETree.ParseError as e:
         raise ProtocolParserError(
             "Unable to parse request (%s), invalid XML received:\n%s" % (e, xml_string)
         ) from e
     return root
    parser = argparse.ArgumentParser(description='Get RSS list or Zabbix LLD format output from AWS Service Health Dashboard page.')
    parser.add_argument('-b', '--block', default="AP", help='set AWS region block(e.g.:NA or SA or EU or AP)')
    parser.add_argument('-i', '--interval', type=int, help='set interval time (seconds)')
    parser.add_argument('-m', '--send-mode', default='False', help='set True if you send AWS Service Health Dashboard status information. set False if you want to get lld format service list. (e.g.: True or False)')
    parser.add_argument('-p', '--zabbix-port', type=int, default=10051, help='set listening port number for Zabbix server')
    parser.add_argument('-z', '--zabbix-host', default='localhost', help='set listening IP address for Zabbix server')

    block_list = ["NA", "SA", "EU", "AP"]
    args = parser.parse_args()
    
    if args.block not in block_list:
        print "please set block name. :" + " or ".join(map(str, block_list))

    base_url = "http://status.aws.amazon.com/"
    socket.setdefaulttimeout(30) 
    htmldata = urllib2.urlopen(base_url)
    
    parser = AWSSHDParser(base_url, args.block, args.zabbix_host, args.zabbix_port)
    parser.feed(htmldata.read())

    if args.send_mode.upper() == "TRUE":
        for url in parser.url_list:
            get_rss_th = threading.Thread(target=parser.get_rss,name="get_rss_th", args=(url,))
            get_rss_th.start()

    if args.send_mode.upper() == "FALSE":
        print json.dumps(parser.lld_json)
        
    parser.close()
    htmldata.close()