ACCA225 commited on
Commit
8c74a11
1 Parent(s): 70b5b3e

Upload extract.ipynb

Browse files
Files changed (1) hide show
  1. extract.ipynb +116 -0
extract.ipynb ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "id": "cdcb9393-271d-4183-8f41-ab22b3d801e2",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "import os\n",
11
+ "import shutil\n",
12
+ "from concurrent.futures import ThreadPoolExecutor\n",
13
+ "\n",
14
+ "# 关键词集合\n",
15
+ "keywords = {\n",
16
+ " 'rasusurasu', 'hagoonha', 'topia', 'nakkar', 'mignon', 'rei', 'asakuraf', 'Sakimichan', '40hara', 'momoco', \n",
17
+ " 'kawacy', 'rei_(sanbonzakura)', 'nekojira', 'mika_pikazo', 'noyu_(noyu23386566)', 'rolua', 'mochizuki_kei', \n",
18
+ " 'akakura', 'rhasta', 'fuzichoco', 'waka(wk4444)', 'mikaze_oto', 'himitsu_(hi_mi_tsu_2)', 'WANKE', 'goto_p', \n",
19
+ " 'void_0', 'ogata_tei', 'kim_hyung_tae', 'sencha_(senchat)', 'kidmo', 'poharo', 'ningen_mame', 'tab_head', \n",
20
+ " 'sho_(sho_lwlw)', 'torino_aqua', 'deyui', 'mairo', 'ru_zhai', 'kedama_milk', 'riichu', 'hiten_(hitenkei)', \n",
21
+ " 'wlop', 'nima_(niru54)', 'tapioka_(oekakitapioka)', 'hua_hua_de_meme', 'mikozin', 'hokori_sakuni', \n",
22
+ " 'menma_(enaic31)', 'asameshi', 'usashiro_mani', 'ciloranko', 'ame_usari', 'houkisei', 'ke-ta', 'chen_bin', \n",
23
+ " 'momozu_komamochi', 'freng', 'kkase_daiki', 'ATDAN', 'minaba_hideo', 'ask(askzy)', 'rurudo', 'tokkyu', 'as109', \n",
24
+ " 'rella', 'onineko', 'mizumi_zumi', 'tianliang_duohe_fangdongye', 'meion', 'omone_hokoma_agm', 'jima', \n",
25
+ " 'amashiro_natsuki', 'izumi_tsubusu', 'Roha', 'torino', 'Ochya', 'dk_senie', 'maximalism', 'iuui', 'mafuyu', \n",
26
+ " 'gaou_(umaiyo_puyoman)', 'murakami_suigun.ohlia', 'ITO_Noizi', 'ponyponypony', 'anmi', 'bow_(bhp)', \n",
27
+ " 'hoji(hooooooooji1029)', 'tidsean', 'akizero1510', 'binggong_asylum', 'cui_(jidanhaidaitang)', 'tony_taka', \n",
28
+ " 'tiv', 'fumio_(rsqkr)', 'gweda', 'hews', 'mamimi(mamamimi)', 'kuzuvine', 'milkychu', 'miv4t', 'musashi(detks)', \n",
29
+ " 'nixeu', 'refeia', 'sy4', 'yago8_pp3', 'kukka', 'kani_biimu', 'katahira_masashi', 'meito_(maze)', 'milk_panda', \n",
30
+ " 'miyo_(ranthath)', 'you_shimizu', 'momoko(momopoco)', 'avogado6', 'nanmokaken', 'gomzi', \n",
31
+ " 'kaamin_(mariarose753)', 'kantoku', 'tomose_shunsaku', 'cierra(ra-bit)', 'sincos', 'toridamono', 'piromizu', \n",
32
+ " 'mandrill', 'modare', 'demizu_posuka', 'hyouuma', 'nanase_nao', 'yoshinari_you', 'atdan', 'ishiyumi', \n",
33
+ " 'nanashi_(nlo)', 'miyase_mahiro', 'poco(asahi_age)', 'imizu_(nitro_unknown)', 'liduke', 'creayus', 'reoen', \n",
34
+ " 'huanxiang_heitu', 'yuuhagi_(amaretto-no-natsu)', 'qtonagi', 'misaka_12003-gou', 'tsukishiro_saika', 'xinzoruo', \n",
35
+ " 'murakami_suigun', 'touzai(poppin_phl95)', 'namie', 'kaigen_1025', 'ryou(ryoutarou)', 'cogecha', \n",
36
+ " 'nikorashi-ka', 'alphonse(white_datura)', 'amazuyu_tatsuki', 'hana_kazari', 'enkyo_yuuichirou', 'kuromiya', \n",
37
+ " 'kinhasu', 'toosaka', 'hoji(hooooooooji1029)', 'meion', 'mignon', 'refeia', 'yago8_pp3', 'sy4', 'onineko', \n",
38
+ " 'kasumi_(skchkko)', 'meito_(maze)', 'miyase_mahiro', 'chen_bin', 'ask(askzy)', 'ke-ta', 'missile228', 'nixeu', \n",
39
+ " 'rurudo', 'atdan', 'yuuhagi_(amaretto-no-natsu)', 'fkey', 'rella', 'shiromochi_sakura', 'xsurugax', 'vardan', \n",
40
+ " 'mizuhara_yui', 'shiro', 'momozu_komamochi', 'jianren', 'sorimura_youji', 'squchan', 'shiratama_(shiratamaco)', \n",
41
+ " 'houkisei', 'freng', 'poharo', 'saru', 'greenteaneko', 'takanashi_hoshino', 'izumi_tsubasu', 'quan_(kurisu_tina)', \n",
42
+ " 'kabocya_na', 'tantan_men_(dragon)', 'ogipote', 'topia', 'fukahire_(ruinon)', 'naga_u', 'wlop', \n",
43
+ " 'sho_(sho_lwlw)', 'minowa_sukyaru', 'alphonse_(white_datura)'\n",
44
+ "}\n",
45
+ "\n",
46
+ "# 文件夹路径\n",
47
+ "source_folder = '/teamspace/studios/this_studio/train/1_all'\n",
48
+ "destination_folder = '/teamspace/studios/this_studio/destation'\n",
49
+ "\n",
50
+ "# 如果目标文件夹不存在,则创建它\n",
51
+ "os.makedirs(destination_folder, exist_ok=True)\n",
52
+ "\n",
53
+ "def process_and_move_file(file_name):\n",
54
+ " if file_name.endswith('.txt'):\n",
55
+ " file_path = os.path.join(source_folder, file_name)\n",
56
+ " with open(file_path, 'r', encoding='utf-8') as file:\n",
57
+ " content = file.read()\n",
58
+ " # 检查文件内容是否包含任意一个关键词\n",
59
+ " if any(keyword in content for keyword in keywords):\n",
60
+ " # 对应的webp文件名\n",
61
+ " base_name = os.path.splitext(file_name)[0]\n",
62
+ " webp_file = base_name + '.webp'\n",
63
+ "\n",
64
+ " # 源文件路径\n",
65
+ " txt_source_path = os.path.join(source_folder, file_name)\n",
66
+ " webp_source_path = os.path.join(source_folder, webp_file)\n",
67
+ "\n",
68
+ " # 目标文件路径\n",
69
+ " txt_destination_path = os.path.join(destination_folder, file_name)\n",
70
+ " webp_destination_path = os.path.join(destination_folder, webp_file)\n",
71
+ "\n",
72
+ " # 移动txt文件\n",
73
+ " shutil.move(txt_source_path, txt_destination_path)\n",
74
+ "\n",
75
+ " # 移动对应的webp文件\n",
76
+ " if os.path.exists(webp_source_path):\n",
77
+ " shutil.move(webp_source_path, webp_destination_path)\n",
78
+ " else:\n",
79
+ " print(f\"对应的webp文件未找到: {webp_file}\")\n",
80
+ " return file_name\n",
81
+ " return None\n",
82
+ "\n",
83
+ "# 使用线程池并行处理文件\n",
84
+ "with ThreadPoolExecutor() as executor:\n",
85
+ " files = list(os.listdir(source_folder))\n",
86
+ " results = list(executor.map(process_and_move_file, files))\n",
87
+ "\n",
88
+ "# 打印匹配的文件列表\n",
89
+ "print(\"匹配并移动的文件列表:\")\n",
90
+ "for file in filter(None, results):\n",
91
+ " print(file)\n"
92
+ ]
93
+ }
94
+ ],
95
+ "metadata": {
96
+ "kernelspec": {
97
+ "display_name": "Python 3",
98
+ "language": "python",
99
+ "name": "python3"
100
+ },
101
+ "language_info": {
102
+ "codemirror_mode": {
103
+ "name": "ipython",
104
+ "version": 3
105
+ },
106
+ "file_extension": ".py",
107
+ "mimetype": "text/x-python",
108
+ "name": "python",
109
+ "nbconvert_exporter": "python",
110
+ "pygments_lexer": "ipython3",
111
+ "version": "3.10.10"
112
+ }
113
+ },
114
+ "nbformat": 4,
115
+ "nbformat_minor": 5
116
+ }