Jon and Robert -- Thanks for your responses! I was aware of those modules and have been going around in circles with them for longer than I'd like to admit.
I guess I was hoping that someone far better at python than me would have the few lines of code already written that work with comparing the "completed_date" value from the spacewalk API to some current timestamp. There appear to be about 100 potential ways of doing this, but I've been unable to fit the pieces together for a single one of them! I'll blame that on my newness to writing python. If anyone has any code that is working in python against the spacewalk API and able to evaluate how long ago an event "completed", please let me know? This has got to be easier than I've made it thus far. Best wishes, Andy On 2/6/14 2:35 PM, "Jon Miller" <[email protected]> wrote: You can do both with the datetime[1] module in Python. E.g. from datetime import datetime, timedelta completed_date = datetime.strptime('20131230T23:00:24', '%Y%m%dT%H:%M:%S') if completed_date > datetime.now() - timedelta(hours=-5): print 'Need to do something' The dateutil (python-dateutil RPM) module is also nice about parsing a variety of string representations of date and times. -- Jon Miller [1]: http://docs.python.org/2/library/datetime.html [email protected] writes: > Hello all! > > I need to compare the "completed_date" from the listSystemEvents method > (published at > >http://www.spacewalkproject.org/documentation/api/1.9/handlers/SystemHandl >e > r.html#listSystems ) to the current time (when my python script runs). > > The 'completed_date' is returned from the API in ISO8601 format, e.g.: > 20131230T23:00:24 > > I'm grabbing the current timestamp via datetime.datetime.now(), which > returns a format like: 2014-02-06 13:05:47.583122 > > > > Has anyone got python code that compares two timestamps for use with the > spacewalk API? (Ultimately, I want to create a conditional that says, >"if > the event completed less than X hours ago, do Y") > > TIA! > > > Andy > > Andy Ingham > IT Infrastructure > Fuqua School of Business > Duke University > > > > > > > > _______________________________________________ > Spacewalk-list mailing list > [email protected] > https://www.redhat.com/mailman/listinfo/spacewalk-list -- Jon Miller _______________________________________________ Spacewalk-list mailing list [email protected] https://www.redhat.com/mailman/listinfo/spacewalk-list _______________________________________________ Spacewalk-list mailing list [email protected] https://www.redhat.com/mailman/listinfo/spacewalk-list
