Skip to main content

Utility detect probable date/time formats given a numeric input.

Project description

https://travis-ci.org/martinvw/epoch-analyzer.png?branch=master https://coveralls.io/repos/martinvw/epoch-analyzer/badge.png?branch=master

A python module to analyze numbers to determine on which epoch they might be based and in what unit they might be expressed.

Installation

  1. Install using pip:

    pip install epoch_analyzer

    for windows:

    py -m pip install epoch_analyzer

    Alternatively, you can download or clone this repo and call pip install -e ..

Usage in Python

Import the EpochTester from the package epoch_analyzer

from epoch_analyzer import EpochTester

If you desire you can pass a min_date and max_date which are used for reference.

Given the resulting object you can call test or convert, for either testing numbers for a probable format or (batch) converting lists of numbers to dates.

Usage EpochTester.test

You can pass one number, an iterable list of numbers (for example a counter) to this method.

For each number one test conversion is performed, it then check which format matches most of the values, a counter object is returned. By calling most_common on that object, the items can be iterated in order starting at the most likely options.

from epoch_analyzer import EpochTester

tester = EpochTester()
results = tester.test({12345435, 231920232})

for match, occurrence in result.most_common():
      print("t%s:\t%d%%" % (match, occurrence))

Usage EpochTester.convert

Lorem ipsum

Usage from the command line

When the module is correctly installed, the command epoch should be available from your path. There are a lot of options, which are listed calling the command without any argument.

Some examples:

Just convert a single value:

epoch 1394543556

Output:

For input 1394543556:
  Number Of Seconds Since Unix Epoch (2014-03-11 13:12:36)

Convert a list of timestamp from a file and output them to a file as unix timestamp.

epoch -f input.txt -u > output-timestamps.txt

Make a summary of the matches from a list of timestamps from a file.

epoch -f input.txt --summary

Output:

Summary for 5 inputs:
      1.      Number Of Seconds Since Unix Epoch:     40%
      2.      Number Of Minutes Since Mac OSX Epoch:  40%
      3.      Number Of Mili Seconds Since Unix Epoch:        20%

Supply a minimum (which is in this case out-of-range for this unixtime):

epoch --min 2014-12-01 1394543556

Output:

For input 1394543556:
  No matching pattern was found

A space seperated hexadecimal input is supported:

epoch "aa bb" --hex

Output (Note that big and little endian are both tested):

For input 48042:
      No matching pattern was found
For input 43707:
      No matching pattern was found

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

epoch_analyzer-0.3.tar.gz (9.0 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page