Created
December 15, 2017 12:26
-
-
Save ronaldlangeveld/1f55289a3e0fae6c06a3f90c3dc3ea95 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.shortcuts import render | |
from django.http import HttpResponse, JsonResponse, HttpResponseRedirect | |
from pullrss.models import RSSData | |
import feedparser | |
from django.db import IntegrityError | |
from time import mktime | |
from datetime import datetime | |
from django.shortcuts import render_to_response | |
from django.template import RequestContext | |
def index(request): | |
rss_list = PullRSS.objects.all().order_by('-timestamp') | |
context = { | |
"rssfeedlist": rss_list, | |
} | |
print(rss_list) #for testing the code | |
sources = [ | |
"link to your source", | |
"add as many as you wish" | |
] | |
rss_data = [] | |
for url in sources: | |
rss_data.append(feedparser.parse(url)) | |
for data in rss_data: | |
for post in data.entries: | |
try: | |
title = post.title | |
link = post.link | |
timestamp = datetime.fromtimestamp(mktime(post['published_parsed'])) | |
# print(timestamp) | |
add = PullRSS() | |
add.title = title | |
add.link = link | |
add.timestamp = timestamp | |
add.save() | |
print("Added successfully") | |
except IntegrityError: | |
pass | |
return render(request, 'index.html', context) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment