本文整理汇总了Python中post.Post.save方法的典型用法代码示例。如果您正苦于以下问题:Python Post.save方法的具体用法?Python Post.save怎么用?Python Post.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类post.Post
的用法示例。
在下文中一共展示了Post.save方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mod_post
# 需要导入模块: from post import Post [as 别名]
# 或者: from post.Post import save [as 别名]
def mod_post(args):
posts = Post.load()
if not args.title and not args.body:
print('Either title or body are required for post modificaion')
else:
p = Post(args.title or posts[args.postid]['title'],
args.body or posts[args.postid]['body'],
postid=args.postid)
p.save()
示例2: run
# 需要导入模块: from post import Post [as 别名]
# 或者: from post.Post import save [as 别名]
def run(self):
while 1 == 1:
try:
for url in self.urls:
self.urls.remove(url)
print(url)
opener = urllib2.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)')]
response = opener.open(url)
html = response.read()
soup = BeautifulSoup(html, 'html.parser')
text = soup.text
links = soup.find_all('a')
images = soup.find_all('img')
post = Post(self.connection, url, url, 'url')
post.save()
download_path = 'sites/' + url
if not os.path.exists(download_path):
os.makedirs(download_path)
for image in images:
print('image')
src = urljoin(url, image.get('src'))
if src.startswith("http") or src.startswith("https"):
fname = self.basename(src)
if fname != None:
self.download_file(src, download_path + fname)
print('ok')
'''self.reset_config()
for p in self.config:
textElements = re.findall(p['regex'], text)
if textElements != None:
for element in textElements:
post = Post(self.connection, element, element, p['type'])
post.save()'''
for link in links:
href = urljoin(url, link.get('href'))
if href.startswith("http") or href.startswith("https"):
fname = self.basename(href)
if fname in self.extensions:
self.download_file(href, download_path + fname)
self.urls.append(href)
except:
pass
示例3: createPost
# 需要导入模块: from post import Post [as 别名]
# 或者: from post.Post import save [as 别名]
def createPost(self, title, body):
if not title or not body:
self.view.showError("Invalid input.")
self.view.displayForm()
return
try:
post = Post(title=title, body=body)
post.save(self.db)
self.backToList()
except ValueError:
self.view.showError("Invalid post.")
self.backToList()
except Exception as e:
self.view.showError("An error occured: %s" % e)
self.backToList()
示例4: add_post
# 需要导入模块: from post import Post [as 别名]
# 或者: from post.Post import save [as 别名]
def add_post(args):
p = Post(args.title, args.body)
p.save()