Python utilities in order to make your coding life easier
Some of the functions, are unable to run as a single python code so you have to create Django project.
Also use python3
All functions return the data if all checks are ok.
If there is any strange character that doesn't match, a custom Exception is raised
import sanitize
data = 'rocky_99'
try:
sanitize.alphanumeric(data)
# Register user
except sanitize.SanitizationException as e:
print(e)
the same password is returned. Otherwise Exception is raised
import sanitize
data = 'p@as$wor!2'
try:
sanitize.password_check(data)
# Do what you need
except sanitize.SanitizationException as e:
# Something is wrong, print the errors
print(e)
Returns a random unique string. Uniquines is based on timestamp. Default length is 8.
Argumentrs: length, prefix, suffix, invalid_chars If you need to get a random unique string of 16 chars with prefix 'user'
get(16, 'user')
avoid_chars = 'ofdAre'
get(6, invalid_chars=avoid_chars)
First of all you need to import datetime
Returns the date after given days. If true is passed, hence will be calculated backwords If you need to get the date after one weekdays_hence(7)
calculate_back = True
days_hence(5, calculate_back)
sample_date = datetime.date(1987, 8, 13)
is_adult(sample_date)
If the given date is over 18 years old, returns True else False
sample_date = datetime.date(1987, 8, 13)
adult_years = 21
is_adult(sample_date, adult_years)
In some countries adultd age differs, so pass the years you need
Make a request and return the answer in json format. Chech function definition for more.
send_request('GET', 'some/api/', return_json=True, debug=True)