Correction script articles
[auf_savoirs_en_partage_django.git] / auf_savoirs_en_partage_django / scripts / articles.in
CommitLineData
79c398f6
CR
1#!/usr/bin/env python
2# -*- encoding: utf-8 -*-
3
4import sys, os, glob
5sys.path[0:0] = [
6 "%(directory)s",
7 "%(directory)s/auf_savoirs_en_partage_django",
8 ]
9os.environ['DJANGO_SETTINGS_MODULE'] = 'production'
10for d in glob.glob("%(directory)s/eggs/*"):
11 sys.path[0:0] = [d,]
8f77cbb6
CR
12for d in glob.glob("%(directory)s/parts/*"):
13 sys.path[0:0] = [d,]
79c398f6
CR
14
15from django.conf import settings
16from savoirs.models import SourceActualite, Actualite
17import feedparser, datetime
18
19sources = [x.url for x in SourceActualite.objects.all()]
20for url in sources:
21 d = feedparser.parse(url)
22 for entry in d.entries:
23 if len(Actualite.objects.filter(url = entry.link)) == 0:
24 print entry.updated_parsed
25 ts = entry.updated_parsed
26 date = datetime.date(ts.tm_year, ts.tm_mon, ts.tm_mday)
27 print date
28 a = Actualite(titre = entry.title,
29 texte = entry.summary_detail.value,
30 url = entry.link,
31 logo = '',
32 date = date,
33 visible = '0',
34 ancienid = 0)
35 print a.save()