本文整理汇总了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)
示例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)
示例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)
示例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))
示例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)