Need Help comparing dates

2006-06-15 Thread colincolehour
I am new to Python and am working on my first program. I am trying to
compare a date I found on a website to todays date. The problem I have
is the website only shows 3 letter month name and the date.
Example: Jun 15

How would I go about comparing that to a different date? The purpose of
my program is to load a webpage and see if the content on the front
page is fresh or stale as in older than a few days. Any help in the
right direction would be great!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need Help comparing dates

2006-06-16 Thread colincolehour
So when I grab the date of the website, that date is actually a string?

How would I got about converting that to a date?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need Help comparing dates

2006-06-16 Thread colincolehour
Thanks for the reply, the book I'm actually using is Python Programming
for the absolute beginner. The book has been good to pick up basic
things but it doesn't cover time or dates as far as I can tell. As for
previous programming experience, I have had some lite introductions to
C & C++ about 6 years ago but I never went past the introductions.So
far "my first program" has been written from snippets from many
different websites.

Also i'm using ActiveState Active Python 2.4 on a Windows XP machine.

I will try to work through Tim's response. I tried using it yesterday
but I was really confused on what I was doing.

Colin

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need Help comparing dates

2006-06-19 Thread colincolehour
I kept getting a Python error for the following line:

month = m[webMonth]


I changed it to month = month_numbers[webMonth]

and that did the trick.


Tim Chase wrote:
> > I am new to Python and am working on my first program. I am trying to
> > compare a date I found on a website to todays date. The problem I have
> > is the website only shows 3 letter month name and the date.
> > Example: Jun 15
>
> No year, right?  Are you making the assumption that the year is
> the current year?
>
> > How would I go about comparing that to a different date?
>
> Once you've got them as dates,
>
>  >>> from datetime import date
>
> you can just compare them as you would any other comparable items.
>
> If you need to map the month-strings back into actual dates, you
> can use this dictionary:
>
>  >>> month_numbers = dict([(date(2006, m, 1).strftime("%b"), m)
> for m in range(1,13)])
>
> It happens to be locale specific, so you might have to tinker a
> bit if you're mapping comes out differently from what the website
> uses.  I also made the assumption the case was the same (rather
> than trying to normalize to upper/lower case)
>
> Then, you can use
>
>  >>> webpageDateString = "Mar 21"
>  >>> webMonth, webDay = webpageDateString.split()
>  >>> month = m[webMonth]
>  >>> day = int(webDay)
>  >>> webpageDate = date(date.today().year, month, day)
>  >>> compareDate = date.today()
>  >>> compareDate < webpageDate
> False
>  >>> compareDate > webpageDate
> True
>
> You can wrap the load in a function, something like
>
>  >>> def isNewer(dateString, year = date.today().year):
> ... monthString, dayString = dateString.split()
> ... month = month_numbers[monthString]
> ... day = int(dayString)
> ... return date.today() < date(year, month, day)
>
> which will allow you to do
>
>  >>> isNewer("Jul 1")
> True
>  >>> isNewer("Apr 1")
> False
>
> and the like.
> 
> There's plenty of good stuff in the datetime module.
> 
> -tkc

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need Help comparing dates

2006-06-19 Thread colincolehour
The program works great! It does everything I wanted it to do and now
I'm already thinking about ways of making it more useful like emailing
me the results of my program.

Thanks everyone for the help and advice.

Colin

Tim Chase wrote:
> > I kept getting a Python error for the following line:
> >
> > month = m[webMonth]
> >
> > I changed it to month = month_numbers[webMonth]
> >
> > and that did the trick.
>
> Sorry for the confusion.  Often when I'm testing these things,
> I'll be lazy and create an alias to save me the typing.  In this
> case, I had aliased the month_numbers mapping to "m":
>
>   >>> m = month_numbers
>
> and it slipped into my pasted answer email.  You correctly fixed
> the problem.  The purpose of the mapping is simply to resolve the
> month name to the month number so that the month number can be
> used.  Depending on how predictable the website's date string
> will be, you can use
>
>   month_numbers = dict([(date(2006, m, 1).strftime("%b").upper(),
> m) for m in range(1,13)])
>
> and then use
>
>   month = month_numbers[webMonth.upper()]
>
> or
>
>   month = month_numbers[webMonth[0:3].upper()]
>
> depending on whether the website might return full month names or
> not.
> 
> -tkc

-- 
http://mail.python.org/mailman/listinfo/python-list


XML validationg against XSD file in Python

2006-06-28 Thread colincolehour
I have tried searching for tips or tutorials on validating an XML file
against and XSD file in python but I haven't had any luck. Can someone
point me in the right direction to how this would be achieved. I've
read that Python has built in libraries for DTD validation but nothing
about XSD.

Thanks,
Colin

-- 
http://mail.python.org/mailman/listinfo/python-list