This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

change, time, file, list, statistics, language and other utilities

Project Description

shijian

Python change, time, file, list, statistics and other utilities

setup

sudo pip install shijian

usage

time expressions

Function style_datetime_object accepts a datetime object and returns a string representation of a time. The default style is “YYYY-MM-DDTHHMMSS” and it can be changed by argument. Styles available are as follows:

time representation comment
YYYY-MM-DDTHHMMSSZ filename safe (default)
YYYY-MM-DDTHHMMSSMMMMMMZ microseconds
YYYY-MM-DD HH:MM:SS UTC elegant
UNIX time S.SSSSSS UNIX time in seconds with second fraction
UNIX time S UNIX time in seconds rounded

Functions time_UTC and time_UNIX are sorts of special cases of function style_datetime_object which return representations of the current time (as opposed to any specified datetime object) in a style. For time_UTC, the default style is “YYYY-MM-DDTHHMMSS” and for time_UNIX, the default style is “UNIX time S” and these styles can be changed by argument.

>>> shijian.time_UTC()
'2015-01-05T092125Z'
>>> shijian.time_UNIX()
1420449720

unique identifiers

Function propose_filename proposes a safe filename. It can accept a filename suggestion or, by default, can generate its own filename suggestion, a time expression returned by function time_UTC. Filename suggestions are tested and then proposed if they meet test conditions. The default condition is to not overwrite existing files and to append an underscore followed by an integer in order to meet this condition.

>python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import shijian
>>> shijian.propose_filename()
'2015-01-05T092319Z'
>>> shijian.propose_filename(filename = "data.pkl")
'data.pkl'
>>>
>touch data.pkl
>python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import shijian
>>> shijian.propose_filename(filename = "data.pkl")
'data_1.pkl'

Function UID returns a 128 bit integer unique identifier in hexadecimal with dashes in accordance with RFC 4122 UUID version 4.

>>> shijian.UID()
'91df3b90-285c-4f22-8ced-a154b3b5b09b'
>>> shijian.UID()
'169bde88-2be2-4b46-bf2d-5bb7aee85658'

Function unique_number returns an integer that does not exist in a global list of integers recorded by the function.

>>> shijian.unique_number()
1
>>> shijian.unique_number()
2

Function unique_3_digit_number returns an integer of 3 significant figures that does not exist in a global list of integers of 3 significant figures recorded by the function.

>>> shijian.unique_3_digit_number()
100
>>> shijian.unique_3_digit_number()
101

clocks

Clocks can be created in a straightforward way such as the following:

alpha = shijian.Clock(name = "alpha")

By default, clocks keep time from their creation time. This behaviour can be disabled using Boolean argument start = False. Clocks can be assigned a name or can generate their own unique identifier. Clocks can be stopped easily:

beta.stop()

and can be started easily:

alpha.start()

Clocks can report on their characteristics in ways such as the following:

print(alpha.name())
print(alpha.start_time())
print(alpha.stop_time())
print(alpha.time())

Clocks can also provide a general printout of their characteristics:

alpha.printout()

All clocks are recorded in the shijian list of clocks. Printouts of clocks are available in two styles: full and statistics. The style “full” returns the elapsed times of all clocks while the default style “statistics” returns the mean times of all clocks of the same name.

shijian.clocks.printout(style = "full")
shijian.clocks.printout()

daily time range

Whether the current time is in a specified daily time range can be tested:

shijian.in_daily_time_range(time_range = "1700--0900")

filename sequences

The function natural_sort naturally sorts a list. The function find_file_sequences, for which a directory and file extension can be specified, returns a naturally-sorted list of filenames that are in a sequence or returns a dictionary of lists of filenames that are in a sequence. For example, a list something like the following could be returned:

['image-000001.png', 'image-000002.png', 'image-000003.png', 'image-000004.png', 'image-000005.png']

configurations, Markdown lists

Markdown lists are human-readable and machine-readable. So, they can be used to specify configurations written by humans for programs. This module features utilities for loading configurations specified in Markdown lists to Python dictionaries and ordered dictionaries.

In order to facilitate the human-readability of configuration specifications, the idea is that lines that are not valid Markdown lists are ignored.

ICHEP 2016

./time_ICHEP_2016.py

upcoming

Changes to time style specifications are under consideration.

Release History

Release History

This version
History Node

2017.6.8.1147

History Node

2017.5.3.1732

History Node

2017.4.29.2335

History Node

2017.4.28.1309

History Node

2017.4.28.1305

History Node

2017.4.11.1544

History Node

2017.3.15.1633

History Node

2017.3.15.33

History Node

2017.3.9.2350

History Node

2017.3.7.1448

History Node

2017.2.24.130

History Node

2017.2.22.1633

History Node

2017.2.20.1455

History Node

2017.1.19.2013

History Node

2017.1.18.1740

History Node

2017.1.16.1600

History Node

2017.1.10.2032

History Node

2017.1.3.1428

History Node

2016.12.23.337

History Node

2016.12.22.105

History Node

2016.11.24.2350

History Node

2016.11.16.1831

History Node

2016.8.8.2252

History Node

2016.8.8.2210

History Node

2016.7.12.1547

History Node

2016.7.11.1901

History Node

2016.7.11.1857

History Node

2016.6.23.1124

History Node

2016.5.12.1337

History Node

2016.5.11.1424

History Node

2016.5.10.615

History Node

2016.5.9.1801

History Node

2016.4.26.1525

History Node

2016.4.25.2258

History Node

2016.4.13.1547

History Node

2016.4.3.1859

History Node

2016.4.3.1855

History Node

2016.3.28.1733

History Node

2016.1.25.1309

History Node

2016.01.20.0746

History Node

2016.1.15.2317

History Node

2016.01.12.1720

History Node

2016.1.12.1720

History Node

2015.12.7.1819

History Node

2015.11.24.1517

History Node

2015.11.22.1716

History Node

2015.10.30.1948

History Node

2015.10.30.1635

History Node

2015.10.30.1623

History Node

2015.01.11.2111

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
shijian-2017.6.8.1147.tar.gz (28.3 kB) Copy SHA256 Checksum SHA256 Source Jun 8, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting