#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import glob
import json
import os

import openpyxl

BASE = '/Users/liuxinyuan/Desktop/hermas输入-工作台数据库'
for p in glob.glob(os.path.join(BASE, '**', '*订单*.xlsx'), recursive=True):
    try:
        wb = openpyxl.load_workbook(p, read_only=True, data_only=True)
    except Exception as e:
        print('打开失败', p, e)
        continue
    print('\n==', os.path.basename(p), '｜sheets', wb.sheetnames)
    for ws in wb.worksheets:
        rows = ws.iter_rows(values_only=True)
        try:
            header = next(rows)
        except StopIteration:
            continue
        head = [str(c) for c in header if c is not None]
        if not head:
            continue
        print('  sheet', ws.title, '｜表头前8:', head[:8])
        n = 0
        for r in rows:
            s = ' '.join(str(c) for c in r if c is not None)
            if '艾德' in s and '艾德范思' not in s:
                print('   ', {head[i] if i < len(head) else i: r[i] for i in range(min(8, len(r)))})
                n += 1
                if n >= 6:
                    break
        break

# 联系人 id 溯源
W = '/Users/liuxinyuan/Desktop/Hermes输出-工作类'
for p in glob.glob(os.path.join(W, '数据', '*.json')):
    try:
        s = open(p, encoding='utf-8', errors='ignore').read()
    except Exception:
        continue
    if '4418589911' in s:
        i = s.find('4418589911')
        print('\n联系人ID出现在', os.path.basename(p), ':', s[max(0, i - 120):i + 60].replace('\n', ' '))
