Accéder au contenu.
Menu Sympa

devel - [Devel] r122 - scripts

Objet : devel-adl

Archives de la liste

[Devel] r122 - scripts


Chronologique Discussions 
  • From: thomas AT lolut.utbm.info
  • To: devel AT agendadulibre.org
  • Subject: [Devel] r122 - scripts
  • Date: Thu, 12 Jan 2006 00:03:51 +0100 (CET)
  • List-archive: <http://lolut.utbm.info/pipermail/devel>
  • List-id: Developpement de l'Agenda du Libre <devel.agendadulibre.org>

Author: thomas
Date: 2006-01-12 00:03:50 +0100 (Thu, 12 Jan 2006)
New Revision: 122

Modified:
scripts/adl-submit.py
Log:
Use time module

Modified: scripts/adl-submit.py
===================================================================
--- scripts/adl-submit.py 2006-01-11 22:00:15 UTC (rev 121)
+++ scripts/adl-submit.py 2006-01-11 23:03:50 UTC (rev 122)
@@ -22,11 +22,15 @@
import pycurl
import StringIO
import re
+import time

eventFields = [ "title", "start-date", "end-date", "start-hour",
"end-hour", "description", "city", "region",
"url", "contact" ]

+#baseUrl = "http://www.agendadulibre.org";
+baseUrl = "http://humanoidz.org/~thomas/agenda/";
+
def Usage():
print """Soumettre un �v�nement dans l'Agenda du Libre

@@ -144,6 +148,10 @@

def SubmitEvent(event):

+ if event.has_key ("start-date") is False:
+ print "Missing start date"
+ return
+
if event.has_key ("end-date") is False:
event ["end-date"] = event ["start-date"]

@@ -151,16 +159,40 @@
print "Formatting problem in title: '%s'" % event['title']
return

- startDate = re.compile(r'([0-9]{4})-0?(1?[0-9])-([0-9]{2})').search
(event['start-date'])
- if startDate is None:
+ try:
+ startDate = time.strptime(event['start-date'], "%Y-%m-%d")
+ except ValueError:
print "Formatting problem in starting date: '%s'. Must be
YYYY-MM-DD" % event['start-date']
return

- endDate = re.compile(r'([0-9]{4})-0?(1?[0-9])-([0-9]{2})').search
(event['end-date'])
- if endDate is None:
+ try:
+ endDate = time.strptime(event['end-date'], "%Y-%m-%d")
+ except ValueError:
print "Formatting problem in ending date: '%s'. Must be YYYY-MM-DD"
% event['end-date']
return

+ if time.mktime(startDate) <= time.time():
+ print "Beginning of the event is in the past"
+ return
+
+ if time.mktime(endDate) <= time.time():
+ print "End of the event is in the past"
+ return
+
+ if time.mktime(endDate) < time.mktime(startDate):
+ print "Beginning of event is after the end"
+ return
+
+# startDate = re.compile(r'([0-9]{4})-0?(1?[0-9])-([0-9]{2})').search
(event['start-date'])
+# if startDate is None:
+# print "Formatting problem in starting date: '%s'. Must be
YYYY-MM-DD" % event['start-date']
+# return
+
+# endDate = re.compile(r'([0-9]{4})-0?(1?[0-9])-([0-9]{2})').search
(event['end-date'])
+# if endDate is None:
+# print "Formatting problem in ending date: '%s'. Must be YYYY-MM-DD"
% event['end-date']
+# return
+
startHour = re.compile(r'^([0-9]{2}):([0-9]{2})$').search
(event['start-hour'])
if startHour is None:
print "Formatting problem in starting hour: '%s'. Must be HH:MM" %
event['start-hour']
@@ -179,27 +211,27 @@
print "Formatting problem in region: '%s'. Must be a number." %
event['region']
return

- if re.compile(r'^http://.*$').search (event['url']) is None:
+ if re.compile(r'^http://.*$').search (event['url']) is None and
re.compile(r'^https://.*$').search (event['url']) is None:
print "Formatting problem in url: '%s'. Must start with http://."; %
event['url']
return

- if re.compile(r'^.*@.*$').search (event['contact']) is None:
+ if
re.compile(r'^([A-Za-z0-9_\.\-]*)@([A-Za-z0-9_\-]*)\.([A-Za-z0-9_\.\-]*)$').search
(event['contact']) is None:
print "Formatting problem in e-mail: '%s'. Must contain an '@'." %
event ['contact']
return

curl = pycurl.Curl()
contents = StringIO.StringIO()
- curl.setopt (curl.URL, 'http://www.agendadulibre.org/submit.php')
+ curl.setopt (curl.URL, baseUrl + '/submit.php')

curl.setopt(curl.HTTPPOST, [('__event_title',
str(event['title'])),
- ('__event_start_day',
startDate.groups(0)[2]),
- ('__event_start_month',
startDate.groups(0)[1]),
- ('__event_start_year',
startDate.groups(0)[0]),
+ ('__event_start_day', startDate[2]),
+ ('__event_start_month', startDate[1]),
+ ('__event_start_year', startDate[0]),
('__event_start_hour',
str(startHour.groups(0)[0])),
('__event_start_minute',
str(startHour.groups(0)[1])),
- ('__event_end_day',
endDate.groups(0)[2]),
- ('__event_end_month',
endDate.groups(0)[1]),
- ('__event_end_year',
endDate.groups(0)[0]),
+ ('__event_end_day', endDate[2]),
+ ('__event_end_month', endDate[1]),
+ ('__event_end_year', endDate[0]),
('__event_end_hour',
str(endHour.groups(0)[0])),
('__event_end_minute',
str(endHour.groups(0)[1])),
('__event_description',
str(event['description'])),





  • [Devel] r122 - scripts, thomas, 12/01/2006

Archives gérées par MHonArc 2.6.16.

Haut de le page