Exemplo n.º 1
0
Arquivo: RegExp.py Projeto: logonmy/XX
 def get_date_time(s):
     if not s or not isinstance(s, str):
         return ""
     r = r"(\d{2,4}[-/年]\d{1,2}[-/月]\d{1,2}日? \d{2}:\d{2}(:\d{2})?)"
     r = r"\d{2,4}[-/年]\d{1,2}[-/月]\d{1,2}日? \d{2}:\d{2}(:\d{2})?"
     p = re.compile(r)
     result = re.findall(p, s)
     try:
         result[0] = result[0].replace('年', '-').replace('月', '-').replace(
             '日', '').replace('号', '')
         if result[0] == "今天":
             return DT.GetToday()
         if len(result[0]) == 4 or len(result[0]) == 5:
             print(result[0])
             return str(DT.GetToday().split("-")[0]) + result[0]
         return result[0]
     except Exception as e:
         print(e)
Exemplo n.º 2
0
Arquivo: RegExp.py Projeto: logonmy/XX
 def get_date(s):
     if not s or not isinstance(s, str):
         return ""
     p = re.compile(
         r'\d{4}[-|/|.]\d{1,2}[-|/|.]\d{1,2}|\d{4}年\d{1,2}月\d{1,2}[日号]|今天|\d{1,2}月\d{1,2}[日号]'
     )
     result = re.findall(p, s)
     try:
         print(result[0])
         result[0] = result[0].replace('年', '-').replace('月', '-').replace(
             '日', '').replace('号', '')
         if result[0] == "今天":
             return DT.GetToday()
         if len(result[0]) == 4 or len(result[0]) == 5:
             print(result[0])
             return str(DT.GetToday().split("-")[0]) + result[0]
         return result[0]
     except Exception as e:
         print(e)
Exemplo n.º 3
0
 def inner(*args, **kwargs):
     if len(args) < 2:
         json_data = kwargs.get("json_data", None)
         spider = kwargs.get("spider", None)
         fp = kwargs.get("fp", None)
     else:
         json_data = args[0]
         spider = args[1]
         fp = args[3]
     if json_data:
         today = dt.GetToday().replace("-", "_")
         uf.FileHelper.mkdir(fp + spider)
         json.dump(json_data,
                   open(fp + spider + os.sep + today + ".json",
                        "a",
                        encoding="utf-8"),
                   ensure_ascii=False)
     return func(*args, **kwargs)  # 2