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


Python Article.url方法代码示例

本文整理汇总了Python中models.Article.url方法的典型用法代码示例。如果您正苦于以下问题:Python Article.url方法的具体用法?Python Article.url怎么用?Python Article.url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Article的用法示例。


在下文中一共展示了Article.url方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: new_blog

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import url [as 别名]
def new_blog(request):
    if request.method == "POST":
        form = BlogForm(request.POST)
        if form.is_valid():
            _blog = form.save(commit=False)
            req_url = BASE_URL % (_blog.name, TEST_API_KEY)
            # parse json
            req = requests.get(req_url)
            jsonlist = json.loads(req.content)
            response = jsonlist['response']
            posts = response['posts']
            blog = response['blog']
            # for post in posts:
            # 	print post['body']

            _blog.title = blog['title']
            _blog.url = blog['url']
            _blog.save()

            for post in posts:
                article = Article()
                article.title = post['title']
                article.url = post['post_url']
                article.description = post['body']
                # article.published_date =
                # datetime.datetime.fromtimestamp(float(post['timestamp']))
                # print article.published_date
                article.blog = _blog
                article.save()
            return redirect('blogs.views.articles_list')
    else:
        form = BlogForm()
    return render(request, "new_blog.html", {"form": form})
开发者ID:joeirimpan,项目名称:blogagg,代码行数:35,代码来源:views.py

示例2: submitarticle

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import url [as 别名]
def submitarticle(request):
	error_msg = u"No POST data sent."	
	if request.method == "POST":
		post = request.POST.copy()
		if post.has_key('tags') and post.has_key('title') and post.has_key('url'):
			try:
				url = post['url']
				art = Article()
				art.tags = post['tags'].strip().split(',')
				art.author = str(request.user)
				art.title = post['title']
				art.votecount = 0
				art.viewcount = 0
				if not url.startswith('http://'):
					url = 'http://'+url
				art.url = url
				if art.url and art.title and art.author:
					try:
						person = getPerson(request)
						person.timesArticle = person.timesArticle + 1
						person.lastActive = datetime.datetime.now()
						rating = Score.objects(type='submitarticle')[0].value
						person.currentRating = person.currentRating + rating
						person.save()
						incrementStat('articles',1)
						art.save()
					except Exception as inst:
						print inst
				return HttpResponseRedirect('/')
			except:
				return HttpResponseServerError('wowza! an error occurred, sorry!')
		else:
			error_msg = u"Insufficient POST data (need 'content' and 'title'!)"
	return HttpResponseServerError(error_msg)
开发者ID:naughtond,项目名称:innuvate,代码行数:36,代码来源:views.py

示例3: create

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import url [as 别名]
def create():
    csrf_token = request.form.get('csrf_token')
    upload_folder = os.path.join(app.config['UPLOAD_FOLDER'], mod.name, csrf_token, 'files')

    form = RegistrationForm()

    if not os.path.exists(upload_folder):
        flash(u'Selecione o arquivo do artigo para enviá-lo.', 'danger')
        return render_template('scholar/new.html', form=form)

    if form.validate() is False:
        return render_template('scholar/new.html', form=form)
    else:
        article = Article()
        article.title = form.title.data
        article.theme = form.theme.data
        article.abstract = form.abstract.data
        article.postage_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        article.approval_status = 0

        author_input_list = form.authors.data.split(',')
        for author_input in author_input_list:
            article.authors.append(AuthorScholar(author_input))

        keyword_input_list = form.keywords.data.split(',')
        for keyword_input in keyword_input_list:
            keyword = KeyWord.query.filter_by(name=keyword_input).first()

            if not keyword:
                article.keywords.append(KeyWord(keyword_input))
            else:
                article.keywords.append(keyword)

        db.session.add(article)
        db.session.flush()

        if os.path.exists(upload_folder):

            file_name = [file for file in os.listdir(upload_folder)][0]

            article.url = upload_helper.upload_s3_file(
                os.path.join(upload_folder, file_name),
                os.path.join('scholar/', str(article.id), 'files/', 'article'),
                {
                    'ContentType': "application/pdf",
                    'ContentDisposition': 'attachment; filename=dataviva-article-' + str(article.id) + '.pdf'
                }
            )

            shutil.rmtree(os.path.split(upload_folder)[0])

        db.session.commit()

        message = u'Muito obrigado! Seu estudo foi submetido com sucesso e será analisado pela equipe do DataViva. \
                    Em até 15 dias você receberá um retorno sobre sua publicação no site!'
        flash(message, 'success')
        return redirect(url_for('scholar.index'))
开发者ID:aromeira,项目名称:dataviva-site,代码行数:59,代码来源:views.py

示例4: process_links

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import url [as 别名]
def process_links(company):
    links = linkz(company.ticker,company.exchange)
    # logging.debug("google links: %s",links)
    yahoo_links = yahoo_linkz(company.ticker)
    # logging.debug("yahoo links: %s",yahoo_links)

    old_titles = company.titles
#    titles = [] 
    if links != None:
#         for [title,link] in links:
#             titles.append(title)

# this could be done with a if title not in old_titles check, to avoid 2 loops through the same list: - see 'if title in titles' below
#         titles = [title for title in titles if title not in old_titles]

        new_titles = []

#         if titles == []:
#         # company.finished_scraping = True # denne slaar inn for tidlig, siden den kommer foer alle artiklene er tatt
#         # company.put()

# DU ER HER - this is probably why nothing is stored:
# denne burde returnere article keys, siden mekanismen er at titles gradvis tømmes, og er tom når man er ferdig:
#             return None



#        link_ctr = 1
        article_keys = []
        # scrape_ctr = 0
        for [title, link] in links: 
#            if link_ctr > 100: # sanity check. there should normally not be more articles than this per day.
#                return article_keys
            #break # from this links loop

#this is where you should do if titles not in old_titles instead:
            if title not in old_titles:

#                link_ctr += 1

                if link != None and link != "":
                    html = fetch(link)
                    if html != None:
                        article = Article()
                        article.title = title
                        # logging.debug("title: %s", title)
#                        titles.remove(title) # when finished, titles = []
                        article.html = html
                        article.url = link
                        article.company = company
#                        article.clean = False

                        article.put() 
                        # scrape_ctr += 1
                        article_keys.append(article.key())
                        new_titles.append(title)

        new_titles = old_titles + new_titles
        company.titles = new_titles #this list should be shortened every now and then - not if it's used for display!
        company.put() 

        # logging.debug("scraped %s articles", scrape_ctr)
                                
        return article_keys
    else:
        return None
开发者ID:memius,项目名称:market-analyzer,代码行数:68,代码来源:scrape.py


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