import os, shutil, re, csv
import pandas as pd


success_copy = 0
failed_copy = 0

def tranname(text):
  
  info_content = ''
  if re.search(r'[\u4e00-\u9fff]+', text):
    info_content = re.sub(r'特巡', '', text)
  else:
    pattern = r'!\[.*?\]\(file:///(.+?)\)'
    match = re.search(pattern, text)
    if match:
      info_content = match.group(1)
  return info_content
def winpath2wls(winpath):
  
  new_path = '/mnt/' + winpath[0].lower() + winpath[1:].replace(
    ':', '').replace('\\', '/')  
  return new_path
def is_contain_chinese(df: pd.DataFrame, col_name: str) -> bool:
  
  return df[col_name].astype(str).str.contains('[\u4e00-\u9fa5]').any()
def folders_detected():

    
    dir_path = os.path.dirname(os.path.abspath(_file_))
    
    dirs = ['all_pics', 'result']
    
    for dir in dirs:
        path = os.path.join(dir_path, dir)  
        if not os.path.exists(path):
            os.makedirs(path)  
def is_adjacent(lst):
  
  return all(abs(lst[i] - lst[i - 1]) > 1 for i in range(1, len(lst)))
def df_lansyspath(df):

  df = df.copy()
  df['Info'] = df['Info'].str.replace("HYC","yanyujie")
  return df
def read2csv(inputfile, outputfile):
  year = 2023
  with open(inputfile, 'r',encoding="utf-8") as f, open(outputfile, 'w',
                                       encoding="utf-8") as csvfile:
    writer = csv.writer(csvfile)
    writer.writerow(['Name', 'Date', 'Time', 'Datetime', 'Info'])
    lines = f.readlines()
    for i in range(0, len(lines), 3):
      line1 = lines[i].strip().split()
      name = line1[0]
      date = str(year) + "-" + line1[1]
      time = line1[2]
      date_time = pd.to_datetime(date + ' ' + time)
      info = tranname(lines[i + 1].strip())
      writer.writerow([name, date, time, date_time, info])
def copy_img(df, folder_path):
  img_count = 0
  cn_count = 0
  success=0
  df = df.copy()
  for i in range(len(df)):
    info = df.iloc[i]['Info']
    if not re.search(r'[\u4e00-\u9fff]+', info):
      basename = os.path.basename(info)
      df.iloc[i]['Info'] = os.path.join(folder_path, basename)
      try:
          shutil.copy(info, folder_path)
          success += 1
      except FileNotFoundError as e:
          print(f"File not found: {e}")
      except PermissionError as e:
          print(f"Permission denied: {e}")
      except Exception as e:
          print(f"Other error: {e}")
    else:
      cn_count += 1
  return df,cn_count,success
def move_onlyimg(img_path,folder_name):
  try:
      shutil.move(img_path, folder_name)
      print("移动成功",img_path,"移动到",folder_name)
  except Your answer should have exactly 4 paragraphs. Make sure that the last paragraph starts with the word "accounts" and that each paragraph is separated by two new lines.
user