Skip to content

Commit 20255c8

Browse files
author
Mark Ng
committed
initial
0 parents  commit 20255c8

14 files changed

+198
-0
lines changed

__init__.py

Whitespace-only changes.

__init__.pyc

158 Bytes
Binary file not shown.

aggregator/__init__.py

Whitespace-only changes.

aggregator/__init__.pyc

169 Bytes
Binary file not shown.

aggregator/models.py

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
from django.db import models
2+
import feedparser
3+
import pprint
4+
5+
# Create your models here.
6+
class Category(models.Model):
7+
"""Categories for Feeds"""
8+
name = models.CharField(unique=True,max_length=255)
9+
def __unicode__(self):
10+
"""string rep"""
11+
return self.name
12+
class Admin:
13+
pass
14+
15+
class Feed(models.Model):
16+
"""Feed to be aggregated"""
17+
url = models.URLField("Feed URL",max_length=255)
18+
title = models.TextField("Feed Title",blank=True)
19+
link = models.URLField("Link to site",verify_exists=False, max_length=255,blank=True)
20+
description = models.TextField("Feed description",blank=True)
21+
author_email = models.CharField("Author Email Address",max_length=255,blank=True)
22+
author_name = models.CharField("Author Name",max_length=255,blank=True)
23+
author_link = models.URLField("Author Link",verify_exists=False, max_length=255,blank=True)
24+
subtitle = models.TextField("Feed Subtitle",blank=True)
25+
created_at = models.DateTimeField("Time Created",auto_now_add=True,blank=True)
26+
updated_at = models.DateTimeField("Time Last Updated",auto_now=True,blank=True)
27+
next_retrieval = models.DateTimeField("Next Retrieval Time",auto_now_add=True)
28+
category = models.ForeignKey(Category)
29+
approved = models.BooleanField()
30+
class Admin:
31+
pass
32+
33+
def __unicode__(self):
34+
"""string rep"""
35+
return self.title
36+
37+
def refresh(self):
38+
"""refresh feed and feed items"""
39+
print self.__unicode__()+' is being updated\n'
40+
parsed = feedparser.parse(self.url)
41+
pp = pprint.PrettyPrinter(indent=4)
42+
pp.pprint(parsed.entries[0])
43+
# properties to take from parser
44+
self.title = parsed.feed.title
45+
self.link = getattr(parsed.feed, 'link', '')
46+
self.description = getattr(parsed.feed, 'description', '')
47+
self.author_name = getattr(parsed.feed.author_detail, 'name', '')
48+
self.author_email = getattr(parsed.feed.author_detail, 'email', '')
49+
self.author_link = getattr(parsed.feed.author_detail, 'href', '')
50+
self.subtitle = getattr(parsed.feed, 'subtitle', '')
51+
self.save()
52+
53+
return self
54+
55+
class FeedItem(models.Model):
56+
"""Item belonging to a feed"""
57+
title = models.TextField("Article Title")
58+
link = models.URLField("Article Link",verify_exists=False, max_length=255,blank=True)
59+
feed = models.ForeignKey(Feed,blank=True)
60+
description = models.TextField("Article description",blank=True)
61+
author_name = models.CharField("Author Name",max_length=255,blank=True)
62+
author_email = models.CharField("Author Email",max_length=255,blank=True)
63+
author_link = models.URLField("Author Link",verify_exists=False, max_length=255,blank=True)
64+
content = models.TextField("Content of Item",blank=True)
65+
pub_date = models.TimeField("Publication Date",blank=True)
66+
unique_id = models.TextField("Item unique ID",blank=True)
67+
enclosure = models.TextField("Enclosure",blank=True)
68+
created_at = models.DateTimeField("Time Created",auto_now_add=True)
69+
updated_at = models.DateTimeField("Time Last Updated",auto_now=True)
70+
def __unicode__(self):
71+
"""string rep"""
72+
return self.title

aggregator/models.pyc

4.29 KB
Binary file not shown.

aggregator/refresh.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#! /usr/bin/env python
2+
3+
import sys
4+
import os
5+
6+
def setup_environment():
7+
pathname = os.path.dirname(sys.argv[0])
8+
sys.path.append(os.path.abspath(pathname))
9+
sys.path.append(os.path.normpath(os.path.join(os.path.abspath(pathname), '../')))
10+
# setup Django environment
11+
import settings # your settings module
12+
from django.core import management
13+
management.setup_environ(settings)
14+
15+
setup_environment()
16+
17+
from aggregator.models import Feed, FeedItem
18+
19+
feeds = Feed.objects.all()
20+
21+
for feed in feeds:
22+
print feed.refresh()

aggregator/views.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Create your views here.

data

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"pk": 1, "model": "auth.user", "fields": {"username": "mng", "first_name": "", "last_name": "", "is_active": 1, "is_superuser": 1, "is_staff": 1, "last_login": "2008-06-21 07:57:56", "groups": [], "user_permissions": [], "password": "sha1$1367a$48e00ac641e0ca5038e08161c7379048f2714014", "email": "[email protected]", "date_joined": "2008-06-19 17:23:31"}}, {"pk": 28, "model": "auth.permission", "fields": {"codename": "add_category", "name": "Can add category", "content_type": 10}}, {"pk": 29, "model": "auth.permission", "fields": {"codename": "change_category", "name": "Can change category", "content_type": 10}}, {"pk": 30, "model": "auth.permission", "fields": {"codename": "delete_category", "name": "Can delete category", "content_type": 10}}, {"pk": 13, "model": "auth.permission", "fields": {"codename": "add_contenttype", "name": "Can add content type", "content_type": 5}}, {"pk": 14, "model": "auth.permission", "fields": {"codename": "change_contenttype", "name": "Can change content type", "content_type": 5}}, {"pk": 15, "model": "auth.permission", "fields": {"codename": "delete_contenttype", "name": "Can delete content type", "content_type": 5}}, {"pk": 22, "model": "auth.permission", "fields": {"codename": "add_feed", "name": "Can add feed", "content_type": 8}}, {"pk": 23, "model": "auth.permission", "fields": {"codename": "change_feed", "name": "Can change feed", "content_type": 8}}, {"pk": 24, "model": "auth.permission", "fields": {"codename": "delete_feed", "name": "Can delete feed", "content_type": 8}}, {"pk": 25, "model": "auth.permission", "fields": {"codename": "add_feeditem", "name": "Can add feed item", "content_type": 9}}, {"pk": 26, "model": "auth.permission", "fields": {"codename": "change_feeditem", "name": "Can change feed item", "content_type": 9}}, {"pk": 27, "model": "auth.permission", "fields": {"codename": "delete_feeditem", "name": "Can delete feed item", "content_type": 9}}, {"pk": 4, "model": "auth.permission", "fields": {"codename": "add_group", "name": "Can add group", "content_type": 2}}, {"pk": 5, "model": "auth.permission", "fields": {"codename": "change_group", "name": "Can change group", "content_type": 2}}, {"pk": 6, "model": "auth.permission", "fields": {"codename": "delete_group", "name": "Can delete group", "content_type": 2}}, {"pk": 31, "model": "auth.permission", "fields": {"codename": "add_logentry", "name": "Can add log entry", "content_type": 11}}, {"pk": 32, "model": "auth.permission", "fields": {"codename": "change_logentry", "name": "Can change log entry", "content_type": 11}}, {"pk": 33, "model": "auth.permission", "fields": {"codename": "delete_logentry", "name": "Can delete log entry", "content_type": 11}}, {"pk": 1, "model": "auth.permission", "fields": {"codename": "add_message", "name": "Can add message", "content_type": 1}}, {"pk": 2, "model": "auth.permission", "fields": {"codename": "change_message", "name": "Can change message", "content_type": 1}}, {"pk": 3, "model": "auth.permission", "fields": {"codename": "delete_message", "name": "Can delete message", "content_type": 1}}, {"pk": 10, "model": "auth.permission", "fields": {"codename": "add_permission", "name": "Can add permission", "content_type": 4}}, {"pk": 11, "model": "auth.permission", "fields": {"codename": "change_permission", "name": "Can change permission", "content_type": 4}}, {"pk": 12, "model": "auth.permission", "fields": {"codename": "delete_permission", "name": "Can delete permission", "content_type": 4}}, {"pk": 16, "model": "auth.permission", "fields": {"codename": "add_session", "name": "Can add session", "content_type": 6}}, {"pk": 17, "model": "auth.permission", "fields": {"codename": "change_session", "name": "Can change session", "content_type": 6}}, {"pk": 18, "model": "auth.permission", "fields": {"codename": "delete_session", "name": "Can delete session", "content_type": 6}}, {"pk": 19, "model": "auth.permission", "fields": {"codename": "add_site", "name": "Can add site", "content_type": 7}}, {"pk": 20, "model": "auth.permission", "fields": {"codename": "change_site", "name": "Can change site", "content_type": 7}}, {"pk": 21, "model": "auth.permission", "fields": {"codename": "delete_site", "name": "Can delete site", "content_type": 7}}, {"pk": 7, "model": "auth.permission", "fields": {"codename": "add_user", "name": "Can add user", "content_type": 3}}, {"pk": 8, "model": "auth.permission", "fields": {"codename": "change_user", "name": "Can change user", "content_type": 3}}, {"pk": 9, "model": "auth.permission", "fields": {"codename": "delete_user", "name": "Can delete user", "content_type": 3}}, {"pk": 10, "model": "contenttypes.contenttype", "fields": {"model": "category", "name": "category", "app_label": "aggregator"}}, {"pk": 5, "model": "contenttypes.contenttype", "fields": {"model": "contenttype", "name": "content type", "app_label": "contenttypes"}}, {"pk": 8, "model": "contenttypes.contenttype", "fields": {"model": "feed", "name": "feed", "app_label": "aggregator"}}, {"pk": 9, "model": "contenttypes.contenttype", "fields": {"model": "feeditem", "name": "feed item", "app_label": "aggregator"}}, {"pk": 2, "model": "contenttypes.contenttype", "fields": {"model": "group", "name": "group", "app_label": "auth"}}, {"pk": 11, "model": "contenttypes.contenttype", "fields": {"model": "logentry", "name": "log entry", "app_label": "admin"}}, {"pk": 1, "model": "contenttypes.contenttype", "fields": {"model": "message", "name": "message", "app_label": "auth"}}, {"pk": 4, "model": "contenttypes.contenttype", "fields": {"model": "permission", "name": "permission", "app_label": "auth"}}, {"pk": 6, "model": "contenttypes.contenttype", "fields": {"model": "session", "name": "session", "app_label": "sessions"}}, {"pk": 7, "model": "contenttypes.contenttype", "fields": {"model": "site", "name": "site", "app_label": "sites"}}, {"pk": 3, "model": "contenttypes.contenttype", "fields": {"model": "user", "name": "user", "app_label": "auth"}}, {"pk": "98976163daeb39dde7f1a12ab137d0fa", "model": "sessions.session", "fields": {"expire_date": "2008-07-04 23:13:13", "session_data": "gAJ9cQEoVRJfYXV0aF91c2VyX2JhY2tlbmRxAlUpZGphbmdvLmNvbnRyaWIuYXV0aC5iYWNrZW5k\ncy5Nb2RlbEJhY2tlbmRxA1UNX2F1dGhfdXNlcl9pZHEEigEBdS42M2I1NDFiMzAyYzM1Mjc4ZTAy\nZjM3MTk0NTVjYmM2Yg==\n"}}, {"pk": "943129acb460aae46b26617d317637c5", "model": "sessions.session", "fields": {"expire_date": "2008-07-05 07:57:56", "session_data": "gAJ9cQEoVRJfYXV0aF91c2VyX2JhY2tlbmRxAlUpZGphbmdvLmNvbnRyaWIuYXV0aC5iYWNrZW5k\ncy5Nb2RlbEJhY2tlbmRxA1UNX2F1dGhfdXNlcl9pZHEEigEBdS42M2I1NDFiMzAyYzM1Mjc4ZTAy\nZjM3MTk0NTVjYmM2Yg==\n"}}, {"pk": 1, "model": "sites.site", "fields": {"domain": "example.com", "name": "example.com"}}, {"pk": 6, "model": "admin.logentry", "fields": {"action_flag": 1, "action_time": "2008-06-21 08:54:11", "object_repr": "Mark Ng", "object_id": "1", "change_message": "", "user": 1, "content_type": 8}}, {"pk": 5, "model": "admin.logentry", "fields": {"action_flag": 1, "action_time": "2008-06-21 08:53:21", "object_repr": "Blogs", "object_id": "1", "change_message": "", "user": 1, "content_type": 10}}, {"pk": 4, "model": "admin.logentry", "fields": {"action_flag": 1, "action_time": "2008-06-21 08:15:47", "object_repr": "Mark Ng", "object_id": "1", "change_message": "", "user": 1, "content_type": 8}}, {"pk": 3, "model": "admin.logentry", "fields": {"action_flag": 1, "action_time": "2008-06-21 08:15:32", "object_repr": "Blogs", "object_id": "1", "change_message": "", "user": 1, "content_type": 10}}, {"pk": 2, "model": "admin.logentry", "fields": {"action_flag": 1, "action_time": "2008-06-21 08:09:42", "object_repr": "Mark Ng", "object_id": "1", "change_message": "", "user": 1, "content_type": 8}}, {"pk": 1, "model": "admin.logentry", "fields": {"action_flag": 1, "action_time": "2008-06-20 23:24:50", "object_repr": "Category object", "object_id": "1", "change_message": "", "user": 1, "content_type": 10}}, {"pk": 1, "model": "aggregator.category", "fields": {"name": "Blogs"}}, {"pk": 1, "model": "aggregator.feed", "fields": {"category": 1, "subtitle": "", "description": "", "title": "Mark Ng", "url": "http:\/\/feeds.feedburner.com\/MarkNg", "created_at": "2008-06-21 08:54:11", "author_link": "", "updated_at": "2008-06-21 08:54:11", "author_name": "", "author_email": "", "link": "", "next_retrieval": "2008-06-21 08:54:11", "approved": 0}}]

manage.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env python
2+
from django.core.management import execute_manager
3+
try:
4+
import settings # Assumed to be in the same directory.
5+
except ImportError:
6+
import sys
7+
sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
8+
sys.exit(1)
9+
10+
if __name__ == "__main__":
11+
execute_manager(settings)

settings.py

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Django settings for dotdorset project.
2+
3+
DEBUG = True
4+
TEMPLATE_DEBUG = DEBUG
5+
6+
ADMINS = (
7+
# ('Your Name', '[email protected]'),
8+
)
9+
10+
MANAGERS = ADMINS
11+
12+
DATABASE_ENGINE = 'mysql' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
13+
DATABASE_NAME = 'dotdorset' # Or path to database file if using sqlite3.
14+
DATABASE_USER = 'root' # Not used with sqlite3.
15+
DATABASE_PASSWORD = '' # Not used with sqlite3.
16+
DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
17+
DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.
18+
19+
# Local time zone for this installation. Choices can be found here:
20+
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
21+
# although not all choices may be available on all operating systems.
22+
# If running in a Windows environment this must be set to the same as your
23+
# system time zone.
24+
TIME_ZONE = 'Europe/London'
25+
26+
# Language code for this installation. All choices can be found here:
27+
# http://www.i18nguy.com/unicode/language-identifiers.html
28+
LANGUAGE_CODE = 'en-gb'
29+
30+
SITE_ID = 1
31+
32+
# If you set this to False, Django will make some optimizations so as not
33+
# to load the internationalization machinery.
34+
USE_I18N = True
35+
36+
# Absolute path to the directory that holds media.
37+
# Example: "/home/media/media.lawrence.com/"
38+
MEDIA_ROOT = ''
39+
40+
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
41+
# trailing slash if there is a path component (optional in other cases).
42+
# Examples: "http://media.lawrence.com", "http://example.com/media/"
43+
MEDIA_URL = ''
44+
45+
# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
46+
# trailing slash.
47+
# Examples: "http://foo.com/media/", "/media/".
48+
ADMIN_MEDIA_PREFIX = '/media/'
49+
50+
# Make this unique, and don't share it with anybody.
51+
SECRET_KEY = '&51qozlg8y0pxm5!=-b3=z+03cad&&33bqm34(yl%g!k$!wyl*'
52+
53+
# List of callables that know how to import templates from various sources.
54+
TEMPLATE_LOADERS = (
55+
'django.template.loaders.filesystem.load_template_source',
56+
'django.template.loaders.app_directories.load_template_source',
57+
'django.template.loaders.eggs.load_template_source',
58+
)
59+
60+
MIDDLEWARE_CLASSES = (
61+
'django.middleware.common.CommonMiddleware',
62+
'django.contrib.sessions.middleware.SessionMiddleware',
63+
'django.contrib.auth.middleware.AuthenticationMiddleware',
64+
'django.middleware.doc.XViewMiddleware',
65+
)
66+
67+
ROOT_URLCONF = 'dotdorset.urls'
68+
69+
TEMPLATE_DIRS = (
70+
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
71+
# Always use forward slashes, even on Windows.
72+
# Don't forget to use absolute paths, not relative paths.
73+
)
74+
75+
INSTALLED_APPS = (
76+
'django.contrib.auth',
77+
'django.contrib.contenttypes',
78+
'django.contrib.sessions',
79+
'django.contrib.sites',
80+
'django.contrib.admin',
81+
'dotdorset.aggregator',
82+
)

settings.pyc

1.97 KB
Binary file not shown.

urls.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from django.conf.urls.defaults import *
2+
3+
urlpatterns = patterns('',
4+
# Example:
5+
# (r'^dotdorset/', include('dotdorset.foo.urls')),
6+
7+
# Uncomment this for admin:
8+
(r'^admin/', include('django.contrib.admin.urls')),
9+
)

urls.pyc

329 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)