Skip to content

Commit

Permalink
Merge pull request #87 from brunoamaral/add-rss-feeds
Browse files Browse the repository at this point in the history
Add rss feeds via Django
  • Loading branch information
brunoamaral authored Mar 31, 2022
2 parents c9c1468 + 608b233 commit 942a730
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 13 deletions.
File renamed without changes.
32 changes: 19 additions & 13 deletions django/admin/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,31 @@
from django.contrib import admin
from django.urls import include, path, re_path
from rest_framework import routers
from api import views
from api.views import *
from rss.views import *

router = routers.DefaultRouter()
router.register(r'articles', views.ArticleViewSet, views.RelevantList)
router.register(r'trials', views.TrialViewSet)
router.register(r'sources', views.SourceViewSet)
router.register(r'articles', ArticleViewSet, RelevantList)
router.register(r'trials', TrialViewSet)
router.register(r'sources', SourceViewSet)


urlpatterns = [
path('admin/', admin.site.urls),
path('api-auth/', include('rest_framework.urls')),
path('articles/all/', views.AllArticleViewSet.as_view()),
path('trials/all/', views.AllTrialViewSet.as_view()),
re_path('^articles/relevant/$', views.RelevantList.as_view()),
path('articles/prediction/none/', views.ArticlesPredictionNone.as_view()),
re_path('^articles/source/(?P<source>.+)/$', views.ArticlesBySourceList.as_view()),
re_path('^trials/source/(?P<source>.+)/$', views.TrialsBySourceList.as_view()),
re_path('^articles/unsent/$', views.UnsentList.as_view()),
path('articles/related/', views.RelatedArticles.as_view({'get': 'list'})),
path('articles/count/', views.ArticlesCount.as_view({'get': 'list'})),
path('articles/all/', AllArticleViewSet.as_view()),
path('trials/all/', AllTrialViewSet.as_view()),
re_path('^articles/relevant/$', RelevantList.as_view()),
path('articles/prediction/none/', ArticlesPredictionNone.as_view()),
re_path('^articles/source/(?P<source>.+)/$', ArticlesBySourceList.as_view()),
re_path('^trials/source/(?P<source>.+)/$', TrialsBySourceList.as_view()),
re_path('^articles/unsent/$', UnsentList.as_view()),
path('articles/related/', RelatedArticles.as_view({'get': 'list'})),
path('articles/count/', ArticlesCount.as_view({'get': 'list'})),
path('', include(router.urls)),
path('feed/latest/articles/', LatestArticlesFeed()),
path('feed/latest/trials/', LatestTrialsFeed()),
path('feed/machine-learning/', MachineLearningFeed()),
path('feed/articles/prediction/none/', ToPredictFeed()),

]
Empty file added django/rss/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions django/rss/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions django/rss/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class RssConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'rss'
Empty file.
3 changes: 3 additions & 0 deletions django/rss/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
3 changes: 3 additions & 0 deletions django/rss/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
78 changes: 78 additions & 0 deletions django/rss/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
from django.shortcuts import render

# Create your views here.
from django.contrib.syndication.views import Feed
from django.urls import reverse
from gregory.models import Articles, Trials

class LatestArticlesFeed(Feed):
title = "Gregory MS - latest research articles"
link = "/articles/"
description = "Real time results for research on Multiple Sclerosis."

def items(self):
return Articles.objects.order_by('-discovery_date')[:5]

def item_title(self, item):
return item.title

def item_description(self, item):
return item.summary

# # item_link is only needed if NewsItem has no get_absolute_url method.
def item_link(self, item):
return 'https://gregory-ms.com/articles/' + str(item.pk) + '/'

class LatestTrialsFeed(Feed):
title = "Gregory MS - latest clinical trials"
link = "/trials/"
description = "Real time results for research on Multiple Sclerosis."

def items(self):
return Trials.objects.order_by('-discovery_date')[:5]

def item_title(self, item):
return item.title

def item_description(self, item):
return item.summary

# # item_link is only needed if NewsItem has no get_absolute_url method.
def item_link(self, item):
return 'https://gregory-ms.com/trials/' + str(item.pk) + '/'

class MachineLearningFeed(Feed):
title = "Gregory MS - Relevant articles by machine learning"
link = "/articles/"
description = "Real time results for research on Multiple Sclerosis."

def items(self):
return Articles.objects.filter(ml_prediction_gnb=True)[:20]

def item_title(self, item):
return item.title

def item_description(self, item):
return item.summary

# # item_link is only needed if NewsItem has no get_absolute_url method.
def item_link(self, item):
return 'https://gregory-ms.com/articles/' + str(item.pk) + '/'

class ToPredictFeed(Feed):
title = "Gregory MS - Relevant articles by machine learning"
link = "/articles/"
description = "Real time results for research on Multiple Sclerosis."

def items(self):
return Articles.objects.filter(ml_prediction_gnb=None)[:20]

def item_title(self, item):
return item.title

def item_description(self, item):
return item.summary

# # item_link is only needed if NewsItem has no get_absolute_url method.
def item_link(self, item):
return 'https://gregory-ms.com/articles/' + str(item.pk) + '/'

0 comments on commit 942a730

Please sign in to comment.