本文整理汇总了Python中post.Post.raw_page方法的典型用法代码示例。如果您正苦于以下问题:Python Post.raw_page方法的具体用法?Python Post.raw_page怎么用?Python Post.raw_page使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类post.Post
的用法示例。
在下文中一共展示了Post.raw_page方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_file
# 需要导入模块: from post import Post [as 别名]
# 或者: from post.Post import raw_page [as 别名]
def process_file(file_name, out_dir):
"""
:param file_name: fully qualified name of the file to be processed
:param out_dir: Output directory to put the post in.
:return: None
"""
code_parser = CodeParser()
link = code_parser.get_page_link(file_name)
if not link:
print "I can't find any link in the given file"
return
# link = 'https://www.leetcode.com/problems/add-digits/'
# initialize the post
post = Post(link=link, file_name=file_name)
# Object of Uniqueness checker
verify_unique = VerifyUnique(config)
# Check for post uniqueness for current file
status = verify_unique.check_post_exists(post)
if status is verify_unique.NON_UNIQUE:
print 'post file already exists'
elif status is verify_unique.NEW_CODE:
# Old post file already exists.
# Append the current code to existing post file.
append_to_post(post.post_file, file_name)
print "updated already existing post file for: " + file_name
else:
# Object to fetch the web page
fetcher = Fetcher(logging.DEBUG)
# Get the host and web page from the link
try:
host, response = fetcher.fetch(link.strip())
except Exception as e:
print "Exception while fetching for link: ", link
print "Exception: ", e
return
# print host
# print response
# update the post with host_name and
# raw_page response values
post.host_name = host
post.raw_page = response
# Get the appropriate problem description
try:
problem_desc_tag = WebParser.parse_page(post)
except Exception, e:
print "Exception in parsing page: ", e
problem_desc_tag = None
# print 'title: ' + post.title
# print problem_desc_tag
if not problem_desc_tag:
print "could not parse the file "
return
# update the post object with problem description
post.problem_text = problem_desc_tag
# Save the post file
print "making the post"
try:
make_post(file_name, post, out_dir)
verify_unique.serialize_post(post)
except Exception, e:
print "could not make the post file", e
return