-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
68 lines (57 loc) · 2.02 KB
/
util.py
File metadata and controls
68 lines (57 loc) · 2.02 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# https://exploreflask.com/en/latest/views.html#custom-converters
from werkzeug.routing import BaseConverter
from datetime import datetime
import dateutil.parser
import pytz
from markupsafe import Markup
import re
class ListConverter(BaseConverter):
def to_python(self, value):
return value.split(',')
def to_url(self, values):
return ','.join(str(value) for value in values)
# Date formatter
def format_date(date_obj, time_zone=None):
if date_obj is None:
return 'None'
if time_zone is not None:
# return dateutil.parser.parse(date_string).astimezone(pytz.timezone(time_zone)).strftime('%Y-%m-%d %H:%M')
date_obj = date_obj.astimezone(pytz.timezone(time_zone))
# date_obj = datetime.strptime(date_string, '%Y-%m-%dT%H:%M:%SZ')
# formatted_date = date_obj.strftime('%Y-%m-%d %I:%M %p')
formatted_date = date_obj.strftime('%Y-%m-%d %H:%M')
return Markup(formatted_date) # Use Markup to avoid HTML escaping
def short_date(date_obj, time_zone=None):
if date_obj is None:
return 'None'
if time_zone is not None:
date_obj = date_obj.astimezone(pytz.timezone(time_zone))
# date_obj = datetime.strptime(date_obj, '%Y-%m-%dT%H:%M:%SZ')
formatted_date = date_obj.strftime('%Y-%m-%d')
return Markup(formatted_date) # Use Markup to avoid HTML escaping
def rename_section(config, old_section, new_section):
# Create a new section with the desired name
config.add_section(new_section)
# Copy items from the old section to the new one
for (name, value) in config.items(old_section):
config.set(new_section, name, value)
# Remove the old section
config.remove_section(old_section)
windows_badnames = (
'CON',
'AUX',
'COM1',
'COM2',
'COM3',
'COM4',
'LPT1',
'LPT2',
'LPT3',
'PRN',
'NUL',
)
def sanitize(filename):
clean_name = re.sub(r"[/\\?%*:|\"<>\x7F\x00-\x1F]", '-', filename)
if clean_name in windows_badnames:
clean_name = clean_name + '_'
return clean_name