forked from l3uddz/traktarr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstr.py
35 lines (27 loc) · 837 Bytes
/
str.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from misc.log import logger
log = logger.get_logger(__name__)
def get_year_from_timestamp(timestamp):
year = 0
try:
if not timestamp:
return 0
year = timestamp[:timestamp.index('-')]
except Exception:
log.exception("Exception parsing year from %s: ", timestamp)
return int(year) if str(year).isdigit() else 0
def is_ascii(string):
try:
string.encode('ascii')
except UnicodeEncodeError:
return False
except UnicodeDecodeError:
return False
except Exception:
log.exception(u"Exception checking if %r was ascii: ", string)
return False
return True
def ensure_endswith(data, endswith_key):
if not data.strip().endswith(endswith_key):
return "%s%s" % (data.strip(), endswith_key)
else:
return data