-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwordsearch.py
73 lines (57 loc) · 1.99 KB
/
wordsearch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#
#
#
__author__ = "blalyasar"
__copyright__ = "Copyright 2020"
__credits__ = [""]
__license__ = "GPL"
__version__ = "1.0.0"
__maintainer__ = ""
__email__ = "[email protected]"
__status__ = ""
# bash e ekleme
# alias wordsearch='python path/dosyaismi.py'
import os
from argparse import ArgumentParser
p = ArgumentParser(description=' *filetype search word ')
p.add_argument('--f',
#"filetype",
required=True,
help='file type -> tr:dosya uzantısı' ,
type=str)
p.add_argument('--w',
#"--word",
required=True,
help='search word-> tr: aranılacak kelime' ,
type=str)
p.print_help() # helpi cagırmak :)
args = p.parse_args()
#
#
#
CURRENT_DIR = os.getcwd()
print( CURRENT_DIR )
CURRENT_DIR_FILE = os.listdir( CURRENT_DIR )
#print(CURRENT_DIR_FILE)
CURRENT_DIR_FILE = [img for img in CURRENT_DIR_FILE if img.endswith(f"{args.f}")]
#print(CURRENT_DIR_FILE)
for iread in CURRENT_DIR_FILE:
with open( iread , "r", encoding="utf-8") as fileread:
lines = fileread.readlines() # liste doner
for index in range(len(lines)): # tum metnın ıcınde gez
word = lines[index]
#print(word)
for word2 in word.split(): #
#print(word2)
# kucuk harfe cevirme olayı
if word2.lower() == args.w.lower() :
print("Kelime su dosyada bulundu --->",iread)
print("Kelime su satırda bulundu --->",index)
print(word)
for point in word2.split("."):
# kucuk harfe cevirme olayı
if point.lower() == args.w.lower() :
print("Kelime su dosyada bulundu --->",iread)
print("Kelime su satırda bulundu --->",index)
print(word.strip()) # tab olayına karşı
print("")