Module that allows extracting valid date from user input.
Project description
Datify
This Python3 module allows to extract parts of valid date from user input.
User input is processed through class Datify
.
Languages supported:
- English
- Russian
- Ukrainian.
Installing
Simply run pip install datify
from your command line.
Class:
Datify(user_input, year, month, date)
: takes str when creating. Also, can take particular parameters like year
, month
, and day
along with user input or without it. If no parameters are given, raises ValueError. See the section Formats to discover default Datify's formats.
Class methods:
Static:
findDate(string)
: Takes string. Returns substring with date in General Date format if it is contained in the given string.isYear(year)
: Takes str or int. Returns True if given parameter suits year format.isDigitMonth(month)
: Takes str or int. Returns True if given parameter suits digit month format.isAlphaMonth(string)
: Takes str. Returns True if given string suits months dictionary. For languages in which there are multiple forms of words it's basically enough to have only the main form of the word in dictionary - see_isSameWord
function.getAlphaMonth(string)
: Takes str. Returns number(int) of month name in given string according to months dictionary. If no month name is found in the string, returns None.isDay(day)
: Takes str or int. Returns True if given parameter suits day format.isDate(date)
: Takes str or int. Returns True if given parameter suits general date format (See the section Default formats).isDatePart(string)
: Takes str. Returns True if given string contains at least one of date parts such as day, month, or year._getWordsList(string)
: from given string returns list of words splitted by a found separator inconfig['SEPARATORS']
(See the section Config). If no separators are found, returns None.
Instance:
date()
: returns datetime object from parameters of Datify object. If not all of the necessary parameters are known (year
,month
, andday
), raises TypeError.tuple()
: returns tuple from all known parameters. Be careful using it because of there is no accurate way to know if number is a day or a month!date_or_tuple()
: returns datetime object if all of the necessary parameters are known, otherwise returns tuple from all known parameters.setYear(year)
: Takes str or int. Extracts year from given parameter and setsyear
field of the called Datify object. If given parameter doesn't suit year format, raises ValueError. If the year is given in shortened format, counts it as 20YY.setMonth(month)
: Takes str or int. Extracts month from given parameter and setsmonth
field of the called Datify object. If given parameter doesn't suit month format and doesn't contain any month names, raises ValueError.setDay(day)
: Takes str or int. Extracts day from given parameter and setsday
field of the called Datify object. If given parameter doesn't suit day format, raises ValueError.
GitHub
Extended documentation can be found at https://github.com/MitryP/datify
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
datify-1.0.tar.gz
(6.1 kB
view hashes)