2017-07-07 00:11:20 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import random
|
2017-07-31 13:29:59 +00:00
|
|
|
from typing import Tuple
|
2017-08-22 11:20:44 +00:00
|
|
|
from datetime import datetime
|
2017-07-07 00:11:20 +00:00
|
|
|
|
|
|
|
|
2017-08-22 11:20:44 +00:00
|
|
|
def re_generator(low: int = 5, high: int = 20) -> str:
|
|
|
|
return 'R{}'.format('E' * random.randint(low, high))
|
2017-07-07 00:11:20 +00:00
|
|
|
|
|
|
|
|
2017-08-22 11:20:44 +00:00
|
|
|
def date_from_iso(date: str) -> datetime:
|
2020-05-18 20:48:20 +00:00
|
|
|
try:
|
|
|
|
return datetime.strptime(date, '%Y-%m-%dT%H:%M:%S.%f%z')
|
|
|
|
except ValueError:
|
|
|
|
return datetime.strptime(date, '%Y-%m-%dT%H:%M:%S%z')
|
2017-07-07 00:11:20 +00:00
|
|
|
|
|
|
|
|
2019-12-08 19:35:10 +00:00
|
|
|
def is_int(val: str) -> bool:
|
|
|
|
return val.isdigit() or (val.startswith('+') or val.startswith('-')) and val[1:].isdigit()
|
|
|
|
|
|
|
|
|
2017-07-31 13:29:59 +00:00
|
|
|
def parse_int(val: str, select: bool = True) -> Tuple[int, str]:
|
2017-07-07 00:11:20 +00:00
|
|
|
try:
|
|
|
|
val = int(val)
|
2020-05-01 23:20:37 +00:00
|
|
|
if val != 0:
|
2017-07-07 00:11:20 +00:00
|
|
|
if val < 1:
|
2017-08-22 14:15:52 +00:00
|
|
|
order = 'DESC'
|
2017-07-07 00:11:20 +00:00
|
|
|
val *= -1
|
|
|
|
else:
|
2017-08-22 14:15:52 +00:00
|
|
|
order = 'ASC'
|
2017-07-07 00:11:20 +00:00
|
|
|
if select:
|
|
|
|
val -= 1
|
|
|
|
return val, order
|
|
|
|
except ValueError:
|
|
|
|
pass
|