本文整理汇总了Python中utils.Logger.log_level方法的典型用法代码示例。如果您正苦于以下问题:Python Logger.log_level方法的具体用法?Python Logger.log_level怎么用?Python Logger.log_level使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.Logger
的用法示例。
在下文中一共展示了Logger.log_level方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from utils import Logger [as 别名]
# 或者: from utils.Logger import log_level [as 别名]
def create(x, db) :
connection = db['connection']
cursor = db['cursor']
# Build and execute SQL Insert query (uses new string interpolation method format() instead of % syntax)
format_str = """INSERT OR REPLACE INTO submissions (id, created_at, subreddit, title, user, upvotes, downvotes, comment_count) VALUES ("{id}", datetime("{created_at}", 'unixepoch'), "{subreddit}", "{title}", "{user}", "{upvotes}", "{downvotes}", "{comment_count}");"""
sql_command = format_str.format(id = x['id'], created_at = x['created_at'], subreddit = x['subreddit'], title = x['title'], user = x['user'], upvotes = x['upvotes'], downvotes = x['downvotes'], comment_count = x['comment_count'])
cursor.execute(sql_command)
connection.commit()
Logger.log_level("Submission created: " + x['title'], 2)
示例2: create
# 需要导入模块: from utils import Logger [as 别名]
# 或者: from utils.Logger import log_level [as 别名]
def create(stream, db) :
connection = db['connection']
cursor = db['cursor']
format_str = """ SELECT * FROM streams WHERE url LIKE "{url}" AND source_id LIKE "{source_id}"; """
sql_command = format_str.format(url = stream["url"], source_id = stream['source_id'])
cursor.execute(sql_command)
results = cursor.fetchall()
result_count = len(results) if (results is not None) else 0
if result_count == 0:
Logger.log_level("Creating stream.", 1)
Logger.log_level("Rating: " + str(stream['rating']) + " Provider: " + stream['provider'] + " URL: " + stream['url'], 2)
format_str = """ INSERT OR REPLACE INTO streams (url, source_type, source_id, provider, created_at, quality, language, rating) VALUES ("{url}", "{source_type}", "{source_id}", "{provider}", datetime("{created_at}"), "{quality}", "{language}", "{rating}"); """
sql_command = format_str.format(url = stream['url'], source_type = stream['source_type'], source_id = stream['source_id'], provider = stream['provider'], created_at = stream['created_at'], quality = stream['quality'], language = stream['language'], rating = stream['rating'])
cursor.execute(sql_command)
connection.commit()
else:
Logger.log_level("Stream already exists.", 1)
Logger.log_level("Rating: " + str(stream['rating']) + " Provider: " + stream['provider'] + " URL: " + stream['url'], 2)
示例3: print_all
# 需要导入模块: from utils import Logger [as 别名]
# 或者: from utils.Logger import log_level [as 别名]
def print_all(db) :
connection = db['connection']
cursor = db['cursor']
# Execute query
cursor.execute("SELECT * FROM submissions")
# Fetch results
result = cursor.fetchall()
# Iterate through results and print them
for r in result:
result_dict = map_db_record_to_object(r)
Logger.log_level("Submission: ", 1)
Logger.log_level(result_dict['title'], 2)
示例4: create
# 需要导入模块: from utils import Logger [as 别名]
# 或者: from utils.Logger import log_level [as 别名]
def create(x, db) :
connection = db['connection']
cursor = db['cursor']
if x['user'] is not None:
Logger.log_level("Comment created: From user " + x['user'], 3)
# Build and execute SQL Insert query (uses new string interpolation method format() instead of % syntax)
format_str = """INSERT OR REPLACE INTO comments (id, parent_id, created_at, subreddit, body, user, upvotes, downvotes) VALUES ("{id}", "{parent_id}", datetime("{created_at}", 'unixepoch'), "{subreddit}", "{body}", "{user}", "{upvotes}", "{downvotes}");"""
sql_command = format_str.format(id = x['id'], parent_id = x['parent_id'], created_at = x['created_at'], subreddit = x['subreddit'], body = html.escape(x['body'], quote=True).encode('utf-8'), user = x['user'], upvotes = x['upvotes'], downvotes = x['downvotes'])
cursor.execute(sql_command)
connection.commit()
else:
Logger.log_level("Comment: DELETED", 3)
示例5: initialize
# 需要导入模块: from utils import Logger [as 别名]
# 或者: from utils.Logger import log_level [as 别名]
def initialize(rebuild = False) :
# Create DB connection
connection = sqlite3.connect(DB_NAME)
# Get DB cursor
cursor = connection.cursor()
db = {
'connection': connection,
'cursor': cursor
}
if rebuild == True:
Logger.log_level("Rebuilding tables.", 1)
rebuild_tables(db)
return db
示例6: scrape_posts
# 需要导入模块: from utils import Logger [as 别名]
# 或者: from utils.Logger import log_level [as 别名]
def scrape_posts(reddit_object, subreddit_name, post_limit) :
submissions_list = []
Logger.log_level("SUBREDDIT: " + subreddit_name, 1)
subreddit = reddit_object.get_subreddit(subreddit_name)
submissions = subreddit.get_new(limit = post_limit)
for s in submissions:
Logger.log_level("Scraping submission: " + s.title, 2)
comments_list = []
for c in s.comments:
if c.author is not None:
Logger.log_level("Scraping comment: posted by " + c.author.name, 3)
comment_obj = {
'id': c.name,
'parent_id': c.parent_id,
'created_at': c.created_utc,
'subreddit': c.subreddit.display_name,
'body': html.unescape(c.body_html),
'user': c.author.name,
'upvotes': c.ups,
'downvotes': c.downs,
}
comments_list.append(comment_obj)
else:
Logger.log_level("Scraping comment: Comment deleted.", 3)
submission_obj = {
'id': s.name,
'created_at': s.created_utc,
'subreddit': s.subreddit.display_name,
'title': s.title,
'user': s.author.name,
'upvotes': s.ups,
'downvotes': s.downs,
'comment_count': s.num_comments,
'comments': comments_list
}
submissions_list.append(submission_obj)
return submissions_list
示例7: print_praw_object
# 需要导入模块: from utils import Logger [as 别名]
# 或者: from utils.Logger import log_level [as 别名]
def print_praw_object(obj_type, obj) :
str = "\n\n===========================\n*** {obj_type} object ***"
Logger.log_level(str.format(obj_type = obj_type))
pprint(vars(obj))
Logger.log_level("======================================\n\n")