当前位置: 首页>>代码示例>>Python>>正文


Python Parser.parse_file方法代码示例

本文整理汇总了Python中Parser.Parser.parse_file方法的典型用法代码示例。如果您正苦于以下问题:Python Parser.parse_file方法的具体用法?Python Parser.parse_file怎么用?Python Parser.parse_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Parser.Parser的用法示例。


在下文中一共展示了Parser.parse_file方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: method

# 需要导入模块: from Parser import Parser [as 别名]
# 或者: from Parser.Parser import parse_file [as 别名]
    def method(self, operation, **kwargs):
        aws_conn = AWSQueryConnection(
            aws_access_key_id=self.aws_access_key_id,
            aws_secret_access_key=self.aws_secret_access_key, is_secure=False,
            host='ecs.amazonaws.com')

        aws_conn.SignatureVersion = '2'
        kwargs.update(dict(
            Service='AWSECommerceService',
            Version=Parser.version,
            SignatureVersion=aws_conn.SignatureVersion,
            AWSAccessKeyId=self.aws_access_key_id,
            AssociateTag=self.aws_associate_tag,
            Timestamp=time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime()),
            Operation=operation,
        ))
        verb = 'GET'
        path = '/onca/xml'
        qs, signature = aws_conn.get_signature(kwargs, verb, path)
        qs = path + '?' + qs + '&Signature=' + urllib.quote(signature)

        xml_response = StringIO(aws_conn._mexe(verb, qs, None, headers={
            'User-Agent': 'AWSECommerceClient.py',
        }).read())

        try:
            return Parser.parse_file(xml_response)
        except:
            # Log the original response and the exception.
            log.error("Error parsing response:\n"+xml_response.getvalue())
            raise
开发者ID:jgardner1,项目名称:PythonAWSECommerceClient,代码行数:33,代码来源:AWSECommerceClient.py

示例2: main

# 需要导入模块: from Parser import Parser [as 别名]
# 或者: from Parser.Parser import parse_file [as 别名]
def main(log_dir, server_name, database_spec, only=None, files=False):
    sqlhub.processConnection = connectionForURI(database_spec)
    if only:
        domainlist = [only]
    else:
        domainlist = os.listdir(log_dir)
    for domain in domainlist:
        logger.info("Parsing logs for domain " + domain)
        logfile = os.path.join(log_dir, domain, 'access.log')
        p = Parser(files=files)
        p.parse_file(logfile)
        p.parse_file(logfile+'.1')
        for date, d in p.valid_data().items():
            if 'all' not in d:
                continue
            bytes, hits = d['all']
            date_d = datetime.date(*[int(x) for x in date.split("-")])
            try:
                u = Usage.selectBy(date=date_d, domain=domain, server=server_name)[0]
            except:
                Usage(server=server_name, domain=domain, date=date,
                      bytes=bytes, hits=hits)
                logger.debug("Added %s for domain %s" % (date, domain))
            if date_d.strftime("%d.%m.%Y") == datetime.datetime.now().strftime("%d.%m.%Y"):
                try:
                    u = Usage.selectBy(date=date_d, domain=domain, server=server_name)
                    for i in u:
                        u.delete(i.id)
                except:
                    pass
            d.pop('all')
            for filename, e in d.items():
                bytes, hits = e
                date_d = datetime.date(*[int(x) for x in date.split("-")])
                try:
                    u = UsageFiles.selectBy(date=date_d, domain=domain, server=server_name, filename=filename)[0]
                    continue
                except:
                    UsageFiles(server=server_name, domain=domain, date=date,
                                bytes=bytes, hits=hits, filename = filename)
                    logger.debug("Added %s for domain %s file %s" % (date, domain, filename))
                if date_d.strftime("%d.%m.%Y") == datetime.datetime.now().strftime("%d.%m.%Y"):
                    UsageFiles(server=server_name, domain=domain, date=date,
                                bytes=bytes, hits=hits, filename = filename)
                    logger.debug("Added %s for domain %s file %s" % (date, domain, filename))
开发者ID:annttu,项目名称:accesslogparser,代码行数:47,代码来源:parselogs.py

示例3: main

# 需要导入模块: from Parser import Parser [as 别名]
# 或者: from Parser.Parser import parse_file [as 别名]
def main(log_dir, server_name, db_url):
    sqlhub.processConnection = connectionForURI(db_url)
    yesterday = datetime.datetime.now() - datetime.timedelta(days=1)

    for domain in os.listdir(log_dir):
        logger.info("Parsing logs for domain " + domain)
        logfile = os.path.join(log_dir, domain, 'access.log')
        # p = Parser()
        p = Parser(limit_to_date="%04i-%02i-%02i" % (yesterday.year, yesterday.month, yesterday.day))
        p.parse_file(logfile)
        p.parse_file(logfile+'.1')
        for date, d in p.valid_data().iteritems():
            bytes, hits = d
            date_d = datetime.date(*[int(x) for x in date.split("-")])
            try:
                u = Usage.selectBy(date=date_d, domain=domain, server=server_name)[0]
                continue
            except:
                Usage(server=server_name, domain=domain, date=date,
                      bytes=bytes, hits=hits)
                logger.debug("Added %s for domain %s" % (date, domain))
开发者ID:kapsiry,项目名称:accesslogparser,代码行数:23,代码来源:parselogs.py

示例4: __init__

# 需要导入模块: from Parser import Parser [as 别名]
# 或者: from Parser.Parser import parse_file [as 别名]
 def __init__(self):
     parser = Parser("myFile")
     self.node_hash = parser.parse_file()
     self.nodes = []
开发者ID:DanLindeman,项目名称:luthor,代码行数:6,代码来源:Graph.py

示例5: Operators

# 需要导入模块: from Parser import Parser [as 别名]
# 或者: from Parser.Parser import parse_file [as 别名]
from Code           import Code
from Resolver       import Resolver
from Configuration  import Configuration
from Generator      import Generator
from Operators      import Operators

from sys import argv

if __name__ == "__main__":
    operators       = Operators()
    configuration   = Configuration()
    data            = Data(configuration)
    code            = Code(data, configuration, operators)
    commands        = Commands(data, code)
    parser          = Parser(commands)
    parser.parse_file(argv[1])
    # Won't need these after Parsing and Allocation.
    # So let's enforce that for our own discipline.
    # State is carried in Code and Data.
    del parser
    del commands
    print("Parsing and Allocation Done")

    # Dump initial state of code and data
    # immediately after Allocation
    configuration.filedump("LOG.allocate")
    data.filedump("LOG.allocate", append = True)
    code.filedump("LOG.allocate", append = True)

    resolver        = Resolver(data, code, configuration)
    resolver.resolve()
开发者ID:laforest,项目名称:Octavo,代码行数:33,代码来源:Assembler.py


注:本文中的Parser.Parser.parse_file方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。