Parce que «Ça peut toujours servir»™ et que de toutes façons il y en a déjà des bouts qui sont dans le dépôt et que c'est chiant de git add -f.
Et puis bon, ça fait que 3Mo
This commit is contained in:
parent
29f50c2ed9
commit
3bde363deb
299 changed files with 17466 additions and 0 deletions
0
archive/cransnews/__init__.py
Normal file
0
archive/cransnews/__init__.py
Normal file
BIN
archive/cransnews/base.db
Normal file
BIN
archive/cransnews/base.db
Normal file
Binary file not shown.
1
archive/cransnews/feeds/annonces_description.html
Normal file
1
archive/cransnews/feeds/annonces_description.html
Normal file
|
@ -0,0 +1 @@
|
|||
{{ obj.body }}
|
1
archive/cransnews/feeds/annonces_title.html
Normal file
1
archive/cransnews/feeds/annonces_title.html
Normal file
|
@ -0,0 +1 @@
|
|||
{{ obj.title }}
|
11
archive/cransnews/manage.py
Executable file
11
archive/cransnews/manage.py
Executable file
|
@ -0,0 +1,11 @@
|
|||
#!/usr/bin/env python
|
||||
from django.core.management import execute_manager
|
||||
try:
|
||||
import settings # Assumed to be in the same directory.
|
||||
except ImportError:
|
||||
import sys
|
||||
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__)
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
execute_manager(settings)
|
96
archive/cransnews/news2rss/__init__.py
Normal file
96
archive/cransnews/news2rss/__init__.py
Normal file
|
@ -0,0 +1,96 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from django.contrib.syndication.feeds import Feed
|
||||
from email.Parser import Parser
|
||||
import email.Utils
|
||||
import nntplib, datetime
|
||||
from email.Header import decode_header
|
||||
p = Parser()
|
||||
|
||||
def unicode_header( h ):
|
||||
h = decode_header( h )
|
||||
h = map(lambda x: x[0].decode(x[1] or "ascii"), h)
|
||||
return u" ".join( h )
|
||||
|
||||
class Message(object):
|
||||
def __init__(self, raw_message):
|
||||
## parsing message
|
||||
emailMessage = p.parsestr(raw_message)
|
||||
## getting subject right
|
||||
subject = emailMessage['Subject'].replace("\n", "")
|
||||
subject = unicode_header( subject )
|
||||
self.title = subject
|
||||
print subject
|
||||
## getting body right
|
||||
body = None
|
||||
if emailMessage.is_multipart():
|
||||
body = "No text found"
|
||||
for part in emailMessage.get_payload():
|
||||
print part.get_content_type()
|
||||
if part.get_content_type() == "text/plain":
|
||||
print part.get_payload()
|
||||
body = part.get_payload()
|
||||
body = body.decode("quopri_codec")
|
||||
body = body.decode(part.get_content_charset() or "ascii")
|
||||
break
|
||||
else:
|
||||
body = emailMessage.get_payload()
|
||||
body = body.decode("quopri_codec")
|
||||
body = body.decode(emailMessage.get_content_charset() or "ascii")
|
||||
|
||||
self.body = body
|
||||
self.date = datetime.datetime( *email.Utils.parsedate( emailMessage.get('Date'))[:-2] )
|
||||
|
||||
def get_absolute_url(self):
|
||||
return "http://www.crans.org"
|
||||
def __unicode__(self):
|
||||
return self.title
|
||||
|
||||
def getMessages(group, n=10):
|
||||
messages = []
|
||||
news = nntplib.NNTP('news.crans.org')
|
||||
resp, count, first, last, name = news.group(group)
|
||||
## faire: renvoyer 404 si existe pas NNTPTemporaryError
|
||||
subs = news.xhdr('subject', str(int(last)-10) + '-' + last)[1]
|
||||
for id, sub in subs[-10:]:
|
||||
info, id, kd, article = news.article( id )
|
||||
msg = Message( u"\n".join(article) )
|
||||
messages.append( msg )
|
||||
messages.reverse()
|
||||
return messages
|
||||
|
||||
class DernieresAnnonces(Feed):
|
||||
title = "Annonces cr@ns"
|
||||
link = "/"
|
||||
description = "Annonces officielles de l'association cr@ns (Cachan Réseau @ Normal' Sup)"
|
||||
|
||||
def items(self):
|
||||
return getMessages("crans.crans.annonces", 10)
|
||||
|
||||
def item_pubdate(self, item):
|
||||
"""
|
||||
Takes an item, as returned by items(), and returns the item's
|
||||
pubdate.
|
||||
"""
|
||||
return item.date
|
||||
|
||||
class LatestMessages(Feed):
|
||||
title = "Annonces cr@ns"
|
||||
link = "/"
|
||||
description = "Annonces officielles de l'association cr@ns (Cachan Réseau @ Normal' Sup)"
|
||||
|
||||
def get_object(self, bits):
|
||||
# In case of "/rss/beats/0613/foo/bar/baz/", or other such clutter,
|
||||
# check that bits has only one member.
|
||||
if len(bits) != 1:
|
||||
raise ObjectDoesNotExist
|
||||
return bits[0]
|
||||
def items( self, obj ):
|
||||
return getMessages(obj, 10)
|
||||
|
||||
def item_pubdate(self, item):
|
||||
"""
|
||||
Takes an item, as returned by items(), and returns the item's
|
||||
pubdate.
|
||||
"""
|
||||
return item.date
|
||||
|
3
archive/cransnews/news2rss/models.py
Normal file
3
archive/cransnews/news2rss/models.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.db import models
|
||||
|
||||
# Create your models here.
|
15
archive/cransnews/news2rss/views.py
Normal file
15
archive/cransnews/news2rss/views.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
# Create your views here.
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
import nntplib
|
||||
import email
|
||||
|
||||
def news2rss(request, group):
|
||||
news = nntplib.NNTP('news.crans.org')
|
||||
resp, count, first, last, name = news.group(group)
|
||||
## faire: renvoyer 404 si existe pas NNTPTemporaryError
|
||||
subs = news.xhdr('subject', str(int(last)-10) + '-' + last)[1]
|
||||
response = ""
|
||||
for id, sub in subs[-10:]:
|
||||
response += sub
|
||||
message = news.xhdr(group, last)
|
||||
return HttpResponse(response)
|
82
archive/cransnews/settings.py
Normal file
82
archive/cransnews/settings.py
Normal file
|
@ -0,0 +1,82 @@
|
|||
# Django settings for cransnews project.
|
||||
|
||||
DEBUG = True
|
||||
TEMPLATE_DEBUG = DEBUG
|
||||
|
||||
ADMINS = (
|
||||
# ('Your Name', 'your_email@domain.com'),
|
||||
)
|
||||
|
||||
MANAGERS = ADMINS
|
||||
|
||||
DATABASE_ENGINE = 'sqlite3' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
|
||||
DATABASE_NAME = '/usr/scripts/cransnews/base.db' # Or path to database file if using sqlite3.
|
||||
DATABASE_USER = '' # Not used with sqlite3.
|
||||
DATABASE_PASSWORD = '' # Not used with sqlite3.
|
||||
DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
|
||||
DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.
|
||||
|
||||
# Local time zone for this installation. Choices can be found here:
|
||||
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
|
||||
# although not all choices may be available on all operating systems.
|
||||
# If running in a Windows environment this must be set to the same as your
|
||||
# system time zone.
|
||||
TIME_ZONE = 'America/Chicago'
|
||||
|
||||
# Language code for this installation. All choices can be found here:
|
||||
# http://www.i18nguy.com/unicode/language-identifiers.html
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
SITE_ID = 1
|
||||
|
||||
# If you set this to False, Django will make some optimizations so as not
|
||||
# to load the internationalization machinery.
|
||||
USE_I18N = True
|
||||
|
||||
# Absolute path to the directory that holds media.
|
||||
# Example: "/home/media/media.lawrence.com/"
|
||||
MEDIA_ROOT = ''
|
||||
|
||||
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
|
||||
# trailing slash if there is a path component (optional in other cases).
|
||||
# Examples: "http://media.lawrence.com", "http://example.com/media/"
|
||||
MEDIA_URL = ''
|
||||
|
||||
# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
|
||||
# trailing slash.
|
||||
# Examples: "http://foo.com/media/", "/media/".
|
||||
ADMIN_MEDIA_PREFIX = '/media/'
|
||||
|
||||
# Make this unique, and don't share it with anybody.
|
||||
SECRET_KEY = 'jrsj4g%%)6xk86z+snji%f3t270q2+0a^nhag4$tm0r50fvhdy'
|
||||
|
||||
# List of callables that know how to import templates from various sources.
|
||||
TEMPLATE_LOADERS = (
|
||||
'django.template.loaders.filesystem.load_template_source',
|
||||
'django.template.loaders.app_directories.load_template_source',
|
||||
# 'django.template.loaders.eggs.load_template_source',
|
||||
)
|
||||
|
||||
MIDDLEWARE_CLASSES = (
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.middleware.doc.XViewMiddleware',
|
||||
)
|
||||
|
||||
ROOT_URLCONF = 'cransnews.urls'
|
||||
|
||||
TEMPLATE_DIRS = (
|
||||
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
|
||||
# Always use forward slashes, even on Windows.
|
||||
# Don't forget to use absolute paths, not relative paths.
|
||||
"/Users/gdetrez/Development/django-projects/cransnews/templates/"
|
||||
)
|
||||
|
||||
INSTALLED_APPS = (
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.sites',
|
||||
'cransnews.news2rss',
|
||||
)
|
|
@ -0,0 +1 @@
|
|||
{{ obj.body|safe }}
|
1
archive/cransnews/templates/feeds/annonces_title.html
Normal file
1
archive/cransnews/templates/feeds/annonces_title.html
Normal file
|
@ -0,0 +1 @@
|
|||
{{ obj.title|safe }}
|
1
archive/cransnews/templates/feeds/group_description.html
Normal file
1
archive/cransnews/templates/feeds/group_description.html
Normal file
|
@ -0,0 +1 @@
|
|||
<pre>{{ obj.body }}</pre>
|
1
archive/cransnews/templates/feeds/group_title.html
Normal file
1
archive/cransnews/templates/feeds/group_title.html
Normal file
|
@ -0,0 +1 @@
|
|||
{{ obj.title|safe }}
|
18
archive/cransnews/urls.py
Normal file
18
archive/cransnews/urls.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
from django.conf.urls.defaults import *
|
||||
from cransnews.news2rss import DernieresAnnonces, LatestMessages
|
||||
|
||||
feeds = {
|
||||
'group': LatestMessages,
|
||||
'annonces': DernieresAnnonces,
|
||||
}
|
||||
|
||||
|
||||
urlpatterns = patterns('',
|
||||
# Example:
|
||||
# (r'^cransnews/', include('cransnews.foo.urls')),
|
||||
#(r'^rss/(?P<group>[\.\w]+)', 'news2rss.views.news2rss'),
|
||||
(r'^rss/(?P<url>.*)/$', 'django.contrib.syndication.views.feed', {'feed_dict': feeds}),
|
||||
|
||||
# Uncomment this for admin:
|
||||
# (r'^admin/', include('django.contrib.admin.urls')),
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue