473,327 Members | 2,090 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,327 software developers and data experts.

comparing apache timestamps

1
I want to compare timestamps from an apache log file to see whether one request has been made less than five minutes after the previous one. Timestamp looks like this [05/Feb/2007:00:31:59 +0100]. How do I make the comparison?
Mar 4 '08 #1
1 2181
bvdet
2,851 Expert Mod 2GB
I want to compare timestamps from an apache log file to see whether one request has been made less than five minutes after the previous one. Timestamp looks like this [05/Feb/2007:00:31:59 +0100]. How do I make the comparison?
Does anyone have a better way?
Expand|Select|Wrap|Line Numbers
  1. import time, datetime
  2. def date_compare(ts1, ts2, **compkw):
  3.     t1 = time.strptime(ts1.strip('[]').split()[0], '%d/%b/%Y:%H:%M:%S')
  4.     d1 = datetime.datetime(*t1[:6])
  5.  
  6.     t2 = time.strptime(ts2.strip('[]').split()[0], '%d/%b/%Y:%H:%M:%S')
  7.     d2 = datetime.datetime(*t2[:6])
  8.  
  9.     delta = d2-d1
  10.     orderList = ['days', 'hours', 'minutes', 'seconds']
  11.     outList = []
  12.     for item in orderList:
  13.         if compkw.has_key(item):
  14.             outList.append('%s %s' % (compkw[item], item))
  15.     outStr = ', '.join(outList)
  16.  
  17.     if delta <= datetime.timedelta(**compkw):
  18.         return 'Less than or equal to %s' % (outStr)
  19.     return 'Greater than %s' % (outStr)
Example:
Expand|Select|Wrap|Line Numbers
  1. >>> ts1 = '[05/Feb/2007:00:31:59 +0100]'
  2. >>> ts2 = '[09/Feb/2007:00:37:00 +0100]'
  3. >>> print date_compare(ts1, ts2, minutes=5, days=2)
  4. Greater than 2 days, 5 minutes
  5. >>> ts1 = '[05/Feb/2007:00:31:59 +0100]'
  6. >>> ts2 = '[05/Feb/2007:00:36:59 +0100]'
  7. >>> print date_compare(ts1, ts2, minutes=5)
  8. Less than or equal to 5 minutes
  9. >>> 
Mar 4 '08 #2

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

Similar topics

2
by: Andrew Pasetti | last post by:
Hello, Executing phpinfo() from the command line and on the browser reveal that the CLI and Apache API have different config statements. How would I resolve this? I would like the CLI API to...
7
by: lkrubner | last post by:
This might be an idiot question, but how do you group by timestamps by date? I mean, given a large number of timestamps, spanning many months, how do grab them and say how many are from each day?...
3
by: jrc4728 | last post by:
I have a MySQL table with the date stored in three fields as string values like this. (sorry, its imported data) str_yy str_dd str_mm ------------------------ 05 01 04 05 ...
1
by: fnord | last post by:
I'm in a bit of a mess here, trying to deal with some timestamp issues. I need to select items from a database with a datetime timestamp: 0000-00-00 00:00:00 I need to select these items...
5
by: Robert Schuldenfrei | last post by:
Dear NG, I have not heard from anyone about a good book that deals with the concurrency issue in SQL Server using C#. I have PROMISED Nick I would not use record locking and I have used an old...
2
by: Chumma Dede | last post by:
Hi, I need to code a DLL in .NET which logs the response times for our asp.net multi-tier application. The problem is we need to log the timestamps at multiple stages in a process lifecycle...
4
by: Craig G | last post by:
im not too sure how i should be storing the SQL2000 timestamps basically i return a dataset which is used to populate an editable grid. this dataset contains the timestamp. how should i be...
4
by: eoghan.kenny | last post by:
Hi, I need to compare two timestamp columns in sql server and see which one is greater. (i can tell if they are not equal buts not enough for this requirement). A timestamp value is unique in...
2
by: ameshkin | last post by:
Hi GUys, Im trying to compare two dates in MYSQL. But its not treating the dates as numbers, but as strings. I try using strtotime but that did not work. Basically, if the last comment is...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.