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


Python Post.save方法代码示例

本文整理汇总了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()
开发者ID:gruzzin,项目名称:test-blog,代码行数:11,代码来源:blog.py

示例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
开发者ID:sebbekarlsson,项目名称:python-scraper,代码行数:54,代码来源:parser.py

示例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()
开发者ID:periodic,项目名称:PyMVC,代码行数:20,代码来源:controller.py

示例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()
开发者ID:gruzzin,项目名称:test-blog,代码行数:5,代码来源:blog.py


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