Aestate
others.py
Go to the documentation of this file.
1 # -*- utf-8 -*-
2 # @Time: 2021/5/30 10:17
3 # @Author: CACode
4 import os
5 import time
6 from datetime import datetime
7 
8 from aestate.conf import BASE_ATTR
9 
10 
12  """
13  将val的类型转换为字符串并插入array
14  """
15  if isinstance(val, datetime):
16  val = val.strftime('%Y-%m-%d %H:%M:%S')
17  return val
18 
19 
20 def date_format(time_obj=time, fmt='%Y-%m-%d %H:%M:%S') -> str:
21  """
22  时间转字符串
23  :param time_obj:
24  :param fmt:
25  :return:
26  """
27  _tm = time_obj.time()
28  _t = time.localtime(_tm)
29  return time.strftime(fmt, _t)
30 
31 
32 def time_to_datetime(t_time):
33  """
34  时间戳转datetime
35  """
36  try:
37  d_time = datetime.fromtimestamp(t_time)
38  except OSError as ose:
39  return None
40  return d_time
41 
42 
44  """
45  获取类的非默认全局变量
46  """
47  retD = list(set(dir(cls)).difference(set(BASE_ATTR)))
48  return retD
49 
50 
51 def fullname(o):
52  """获取对象的类名"""
53  module = o.__class__.__module__
54  if module is None or module == str.__class__.__module__:
55  cls_name = o.__class__.__name__
56  else:
57  cls_name = module + '.' + o.__class__.__name__
58 
59  if cls_name == 'type':
60  cls_name = o.__base__.__module__ + '.' + o.__base__.__name__
61 
62  return cls_name
63 
64 
65 def logTupleToText(next_line=True, *content):
66  temp = []
67  if isinstance(content, str):
68  temp.append(content)
69  elif isinstance(content, tuple):
70  for c in content:
71  if isinstance(c, tuple):
72  temp.extend(c)
73  else:
74  temp.append(str(c))
75  else:
76  temp.append(str(content))
77  if next_line:
78  temp.append('\n')
79  return ''.join([str(_) for _ in temp])
80 
81 
82 def write(path, *content):
83  """
84  写出文件
85  :param path:位置
86  :param content:内容
87  :return:
88  """
89  # 防止有些使用`/`有些用`\\`
90  _sep_path = []
91  s = path.split('/')
92  [_sep_path.extend(item.split('\\')) for item in s]
93  _path = ''
94  for i in _sep_path:
95  _end = _sep_path[len(_sep_path) - 1]
96  if i != _end:
97  _path += str(i) + os.sep
98  else:
99  _path += str(i)
100  if not os.path.exists(_path):
101  if '.' not in i:
102  os.makedirs(_path)
103  _write_content = logTupleToText(True, *content)
104  with open(os.path.join(_path), mode="a", encoding="UTF-8") as f:
105  f.write(_write_content)
106  f.close()
aestate.util.others.time_to_datetime
def time_to_datetime(t_time)
Definition: others.py:32
aestate.util.others.get_static_fields
def get_static_fields(cls)
Definition: others.py:43
aestate.util.others.conversion_types
def conversion_types(val)
Definition: others.py:11
aestate.conf
Definition: conf.py:1
aestate.util.others.date_format
str date_format(time_obj=time, fmt='%Y-%m-%d %H:%M:%S')
Definition: others.py:20
aestate.util.others.logTupleToText
def logTupleToText(next_line=True, *content)
Definition: others.py:65
aestate.util.others.fullname
def fullname(o)
Definition: others.py:51
aestate.util.others.write
def write(path, *content)
Definition: others.py:82