473,394 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How can time be compared

Hello,

I am writing a script that is going to download and read XML data from a server. The server updates the xml data every 4 hours. Instead of downloading a new copy of the xml everytime the script runs, I want to look at the timestamp of the local file to see if it is less than 4 hours old. If it is, I will read the local copy, but if not I will download a new copy and read it. I can't seem to find any good way of doing this. Any help would be appreciated.
Sep 8 '10 #1
3 1476
dwblas
626 Expert 512MB
Try os.stat() and use either ctime, mtime, or stime, depending on your requirements http://docs.python.org/library/os.html. Note that all times must be in the same units, seconds since the epoch, or datetime format.
Sep 8 '10 #2
bvdet
2,851 Expert Mod 2GB
Here's a simple example using os.path.getmtime and time.time:
Expand|Select|Wrap|Line Numbers
  1. import time, os
  2.  
  3. def mtime_diff(fn):
  4.     '''
  5.     Return the difference between the current time and the time of
  6.     last modification of a given file name in seconds.'''
  7.     return time.time() - os.path.getmtime(fn)
  8.  
  9. diff = mtime_diff('file_name')
  10. fourhours = 60*60*4.
  11. print "The file was last modified %.2f hours ago." % (diff/fourhours)
Sep 8 '10 #3
thank you sir. That did the trick!
Sep 9 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Marc H. | last post by:
Hello, I recently converted one of my perl scripts to python. What the script does is simply search a lot of big mail files (~40MB) to retrieve specific emails. I simply converted the script...
3
by: nandan | last post by:
Hi, Has any one ever compared the performance of calling a DataTable's Select method with a stored procedure doing the same thing? My point is: dataRows = DataTable.Select(filter) is better or...
6
by: Thomas Beutin | last post by:
Hi, i've a speed problem withe the following statement: SELECT DISTINCT pz.l1_id, pz.l2_id, pz.l3_id, pz.l4_id FROM ot_adresse AS a, ot_produkt AS p LEFT OUTER JOIN ot_kat_prod AS pz ON (...
5
by: Michael | last post by:
i experience slower compile times with VC++ 2003 compared to VC+6.0. Anyone experiencing the same? Should that be expected? This ineed matters, when total compilation time is > 1h and you have to...
10
by: Pieter | last post by:
Hi, I know this is kind of Off Topic, but I think this is the best place to ask this (if not, please tell me where :-) ). The question is: What's the cost of having an existing (access)...
12
by: baibaichen | last post by:
i know that pImpl idiom can decrease compile time, but Is there any good practice/idiom to decrease link time? any reference or any idea is appreciated thanks
50
by: diffuser78 | last post by:
I have just started to learn python. Some said that its slow. Can somebody pin point the issue. Thans
25
by: Andy B | last post by:
How hard/easy is it to use/learn VB compared to c#?
27
by: CodeMonk3y | last post by:
gotta question on sizeof keyword does the sizeof keyword calcuates the size at compile time or run time ?? -- Posted on news://freenews.netfront.net - Complaints to news@netfront.net --
1
by: sanjupommen | last post by:
I am in the process of exploring the possibility of providing our products on databases other than Oracle.I am able to migrate the data, procedures etc without too much effort (latest version of DB2...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.