You are not logged in.
Pages: 1
i'm learning python right now, and writing a simple subversion mailing script.
how do i parse the date that's spit out from "svnlook date"? i can't seem to find any parsing functions
thanks.
Offline
EDIT ooops yeah like what Dusty says .....
Mr Green
Offline
I'm not sure how the output looks, but you might want to look at these string functions:
find
endswith
startswith
replace
split
The last (split) is probably your best bet.
You might also want to look at the re module (for regular expressions). I suspect There is also a tokenize module, but I don't know anything about it.
HTH,
Dusty
Offline
:'(
i got babied by .net's datetime.parse function...
i guess i could regex it. thanks.
Offline
oh, do you want time.strptime()? :
http://www.python.org/doc/2.4/lib/module-time.html
Offline
import re ?
Offline
it's a very simple app. i wanna generate a text file for the current date, containing subversion log messages, the dates, authors, and files modified.
i just make use of svnlook, and parse the output. the format of the date that svnlook spits out is:
2006-08-24 10:21:29 -0400 (Thu, 24 Aug 2006)
really, i only need the first part. i just figured python would have a function somewhere that would parse "2006-08-24" into a datetime object or something.
i've written the script in c# already, and seemed like a good opportunity to learn some python.
the easiest way so far is just to use substring, and create the datetime object manually.
Offline
errr split maybe
a = "2006-08-24 10:21:29 -0400 (Thu, 24 Aug 2006)"
b = a.split()
print b[0]
or
print a[0:10]
hth
Mr Green
Offline
this is what i've done,
sdate = os.popen(svnlook + " date " + svnrepo + " -r " + revision).read()
date = datetime.datetime(int(sdate[0:4]), int(sdate[5:7]), int(sdate[8:10]))
seems to work
i'm still not used to this type inference...it's scary looking!
Offline
it wouldn't look so scary if you didn't put it all in one line . I would go with split(' ') instead of slicing too..
Offline
I don't have time to test it, but I think the time.strptime() function does what you want. Here's the help:
strptime( string[, format])
Parse a string representing a time according to a format. The return value is a struct_time as returned by gmtime() or localtime(). The format parameter uses the same directives as those used by strftime(); it defaults to "%a %b %d %H:%M:%S %Y" which matches the formatting returned by ctime(). If string cannot be parsed according to format, ValueError is raised. If the string to be parsed has excess data after parsing, ValueError is raised. The default values used to fill in any missing data are (1900, 1, 1, 0, 0, 0, 0, 1, -1) .Support for the %Z directive is based on the values contained in tzname and whether daylight is true. Because of this, it is platform-specific except for recognizing UTC and GMT which are always known (and are considered to be non-daylight savings timezones).
I think it'll return a rather ugly tuple that can be used to construct a datetime object or something, which will allow you really simple access to each of the fields.
Dusty
Offline
it wouldn't look so scary if you didn't put it all in one line .
you should look at my c# code if that looks scary :twisted:
...
you are indeed correct
the following will work
time.strptime(sdate[0:10], "%Y-%m-%d")
Offline
You might look at installing/using these modules:
http://labix.org/python-dateutil
http://www.nanoo.org/~daniel/parsetime/
"I know nothing except the fact of my ignorance."
- Socrates
Offline
Pages: 1