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


Python Utils.read_file方法代码示例

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


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

示例1: main

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import read_file [as 别名]
def main():
    
    logger = Utils.enable_logging()
    
    # get client
    client = get_client(PROJECT_ID, service_account=SERVICE_ACCOUNT, private_key=KEY, readonly=False)
    client.swallow_results = False
    logger.info("client: %s" % client)
    
    schema_str = Utils.read_file(GNIP_SCHEMA_FILE)
    schema = json.loads(schema_str)
    
    # initialize table mapping for default table
    table_mapping = {
         DATASET_ID + "." + TABLE_ID : [DATASET_ID, TABLE_ID]
     }
    
    l = BigQueryGnipListener(client, schema, table_mapping, logger=logger)
 
    while True:

        stream = None

        try:
            get_stream(l)
            
        except:

            logger.exception("Unexpected error:");

            if stream:
                stream.disconnect()

            time.sleep(SLEEP_TIME)
开发者ID:PiyushKumar,项目名称:twitter-for-bigquery,代码行数:36,代码来源:load_gnip.py

示例2: main

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import read_file [as 别名]
def main():
    
    logger = Utils.enable_logging(LOGGING_CONFIG)
    
    # get client
    client = get_client(PROJECT_ID, service_account=SERVICE_ACCOUNT, private_key=KEY, readonly=False)
    client.swallow_results = False
    logger.info("BigQuery client: %s" % client)
    
    schema_str = Utils.read_file(SCHEMA_FILE)
    schema = json.loads(schema_str)
    
    # create table BigQuery table
    created = client.create_table(DATASET_ID, TABLE_ID, schema)
    logger.info("BigQuery create table result: %s" % created)
#     if (len(created) == 0):
#         print "failed to create table"
#         return
    
    l = BigQueryListener(client, DATASET_ID, TABLE_ID, logger=logger)
    auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
    auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
 
    while True:

        logger.info("Connecting to Twitter stream")

        stream = None

        try:
            
            # stream = tweepy.Stream(auth, l, headers = {"Accept-Encoding": "deflate, gzip"})
            stream = tweepy.Stream(auth, l)

            # Choose stream: filtered or sample
            stream.sample()
#             stream.filter(track=TRACK_ITEMS) # async=True
            
        except:

            logger.exception("Unexpected error");

            if stream:
                stream.disconnect()

            time.sleep(60)
开发者ID:PiyushKumar,项目名称:twitter-for-bigquery,代码行数:48,代码来源:load.py

示例3: main

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import read_file [as 别名]
def main():

    if config.MODE not in ['gnip', 'twitter']:
        print "Invalid mode: %s" % config.MODE
        exit()

    logger = Utils.enable_logging()
    print "Running in mode: %s" % config.MODE

    schema_file = None
    if config.MODE == 'gnip':
        schema_file = "./schema/schema_gnip.json"
    else:
        schema_file = "./schema/schema_twitter.json"
    schema_str = Utils.read_file(schema_file)
    schema = json.loads(schema_str)

    Utils.insert_table(config.DATASET_ID, config.TABLE_ID, schema)
    print "Default table: %s.%s" % (config.DATASET_ID, config.TABLE_ID)

    if config.MODE == 'gnip':
        GnipListener.start(schema, logger)
    elif config.MODE == 'twitter':
        TwitterListener.start(schema, logger)
开发者ID:jmg132,项目名称:twitter-for-bigquery,代码行数:26,代码来源:load.py

示例4: get

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import read_file [as 别名]
    def get(self):
        
        response = []
        
        type = self.request.get("type")

        dataset = self.request.get("dataset")
        if "gnip" in dataset:
            dataset = "gnip"
            schema_file = "./schema/schema_gnip.json"
        else:
            dataset = "twitter"
            schema_file = "./schema/schema_twitter.json"
        
        table = self.request.get("name")
        rule_list = self.request.get("rules")
        imprt = self.request.get("import")

        schema_str = Utils.read_file(schema_file)
        schema = json.loads(schema_str)
        
        Utils.insert_table(dataset, table, schema)
        TABLE_CACHE.clear()
            
        name = Utils.make_tag(dataset, table)
        rule_list = [s.strip() for s in rule_list.splitlines()]
        for r in rule_list:
            
            params = GNIP_RULES_PARAMS
            params['tag'] = name
    
            response.append(rules.add_rule(r, **params))
            TABLE_CACHE.clear()

        self.response.headers['Content-Type'] = 'application/json'   
        self.response.out.write(json.dumps(response)) 
开发者ID:jmg132,项目名称:twitter-for-bigquery,代码行数:38,代码来源:app.py

示例5: file

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import read_file [as 别名]
#!/usr/bin/python
import shutil
from config import Config
from jinja2 import Template
from utils import Utils

f = file("./config")
config = Config(f)

schema = None
if config.MODE not in ["gnip", "twitter"]:
    print "Invalid Mode. Mode can be 'gnip' or 'twitter' only"
    exit()

container_template = Utils.read_file("./container.yaml.template")
container_template = Template(container_template).render(config)

container_file = open("./container.yaml", "w")
container_file.write(container_template)
开发者ID:slitayem,项目名称:twitter-for-bigquery,代码行数:21,代码来源:setup.py


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