Exemple #1
0
def get_news():
    now = datetime.now()
    strnow = now.strftime('%Y-%m-%d %H:%M:%S')
    print(strnow)
    # First next run time
    '''
    period = timedelta(days=day, hours=hour, minutes=min, seconds=second)
    next_time = now + period
    strnext_time = next_time.strftime('%Y-%m-%d %H:%M:%S')
    print(strnext_time)
    '''
    pasttime = now - timedelta(days=1)
    paststr = pasttime.strftime('%Y-%m-%d %H:%M:%S')
    print(paststr)

    df = pro.news(src='sina', start_date=strnow, end_date=paststr)
    print(df)
    for index, row in df.iterrows():

        news = News()
        news.timestamp = index
        news.title = row['title']
        news.body = row['content']
        news.author = 'default'
        db.session.add(news)
        db.session.commit()
    newss = News.query.all()
    for n in newss:
        print(n.id, n.body)
Exemple #2
0
def _add_news():
    json = request.get_json(force=True)
    print(json)
    news = News(
        title=json['title'],
        short_text=json['short_text'],
        full_text=json['full_text'],
    )
    from datetime import datetime
    news.creation_date = datetime.strptime(json['creation_date'], '%d/%m/%Y')
    tag_list = json['tags']
    author_id = json['author_id']
    author = Author.query \
        .filter(Author.author_id == author_id)
    news.author = author
    tags = Tag.query \
        .filter(Tag.tag_id.in_(tag_list)).all()
    news.tags = tags
    db.session.add(news)
    db.session.commit()
    return 'ok'
Exemple #3
0
def edit(request):
	print request.method
	if request.method == "POST":
		title = request.POST.get("title", None)
		content = request.POST.get("content", None)
		news_id = request.POST.get("news_id", None)
		delete_tag = request.POST.get("delete_tag", None)
		print title
		print content
		print news_id
		print delete_tag
		if delete_tag is None:
			if title is None or content is None:
				return HttpResponse("error")
			# 新建news
			if news_id is None or news_id == "":
				print news_id
				try:
					news = News()
					news.title = title
					news.content = content
					news.author = "zhaolong"
					news.read_count = 0
					news.save()
					return HttpResponse("success")
				except:
					return HttpResponse("error")
			# 更新news 内容
			else:
				try:
					news = News.objects.get(news_id=int(news_id))
					news.title = title
					news.content = content
					news.author = "zhaolong"
					news.save()
					return HttpResponse("success")
				except:
					return HttpResponse("error")
		# 删除news
		else:
			if news_id is None:
				return HttpResponse("error")
			try:
				news = News.objects.get(news_id=int(news_id))
				news.delete()
				return HttpResponse("success")
			except:
				return HttpResponse("error")

	elif request.method == "GET":
		try:
			news_id = int(request.GET.get("nid", -1))
			news=News.objects.get(pk=news_id)
			form = UEditorTestModelForm(instance= news)
		except Exception, e:
			print str(e)
			form = TestUEditorForm( initial={'content': '请在此输入文字'} )
			news = None
		return render(request, "adminer/editNews.html", {
			'form': form,
			'news': news,
		})