Ejemplo n.º 1
0
def add_news(request):
	website_urls=['http://rss.cnn.com/rss/edition.rss','https://news.ycombinator.com/rss ','http://economictimes.indiatimes.com/rssfeedsdefault.cms','http://yourstory.com/feed/',]

	#request_recvd = request.POST.get('data')
	for website_url in website_urls:
		parsed_uri = urlparse( website_url )
		domain = '{uri.scheme}://{uri.netloc}/'.format(uri=parsed_uri)
		print website_url
		feeds=feedparser.parse(website_url)
		print feeds
		for loop in feeds.entries : 
			print loop.published
			print loop.summary_detail.value
			print domain
			print website_url
			print loop.title
			news = News(time_stamp = json.dumps(list(loop.published_parsed)),website = domain, url = website_url,title = loop.title,content = loop.summary_detail.value)
			news.save()
		

		
	# if len([News.objects.get(link = link)]) == 0 :
		
		
	return redirect('/api/')
Ejemplo n.º 2
0
    def setUp(self):
        now = timezone.make_aware(timezone.datetime(2019, 1, 1, 0, 0, 0),
                                  timezone.get_default_timezone())

        self._posts = []
        for i in range(10):
            now += timezone.timedelta(minutes=i)
            post = {
                'url': f'url{i}',
                'title': f'title{i}',
                'created': now.isoformat()
            }
            self._posts.append(post)
            n = News(**post)
            n.save()
            post['id'] = n.id
            n.created = now
            n.save()
Ejemplo n.º 3
0
def seed_data():
    """
    seed isl teams data from file
    :return:
    """
    with open(file_name, encoding='utf-8') as fp:
        contents_of_file = json.load(fp)
        for data in contents_of_file:
            news_date = data['news_date']
            content = data['content']
            source = data['source']
            title = data['title']
            news_tags = data['news_tags']
            sport = data['sport']
            is_trending = data['is_trending']
            trend_scale = data['trend_scale']
            display_order = data['display_order']
            image = data['image']
            identifier = data['identifier']

            try:
                news = News.objects.get(identifier=identifier)
            except News.DoesNotExist:
                news = News()

            news.news_date = datetime.datetime.strptime(news_date,
                                                        "%Y-%m-%d").date()
            news.content = content
            news.source = source
            news.title = title
            news.news_tags = news_tags
            news.sport = sport
            news.is_trending = is_trending
            news.trend_scale = trend_scale
            news.display_order = display_order
            news.identifier = identifier

            news.save()
            print('added news')
Ejemplo n.º 4
0
        else:
            cover = headline["cover"]["thumbnailUrl"]

        date = datetime.datetime.fromtimestamp(headline["date"])
        author = headline["author"]["name"]
        intro = headline["intro"]

        htmlText = html.fromstring(headline['entryContent']['html'])
        paragraphs = htmlText.xpath('//p/text()')
        text = ""

        for par in paragraphs:
            text = text + par + "\n\n"

        print(text)
        n1 = positiver.evalute(Api.cleanText(text))
        n2 = checker.evalute(Api.cleanText(text))
        if len(News.objects.all().filter(article_id=article_id)) == 0:
            article = News(article_id=article_id,
                           title=title,
                           intro=intro,
                           date=date,
                           author=author,
                           cover=cover,
                           article=text,
                           authorPosition=n1,
                           concrete=n2)
            article.save()
            time.sleep(10)
    time.sleep(400)