Browse Source

update: use camelCase

master
Dnomd343 2 years ago
parent
commit
2ff637b547
  1. 18
      src/banned_words/search.py
  2. 14
      src/character/character.py

18
src/banned_words/search.py

@ -10,7 +10,7 @@ defaultPath = os.path.join(
) )
def load_content(filename: str) -> list: # load json content def loadContent(filename: str) -> list: # load json content
if not filename.endswith('.json'): if not filename.endswith('.json'):
filename += '.json' # add file suffix filename += '.json' # add file suffix
raw = json.loads(open( raw = json.loads(open(
@ -23,16 +23,16 @@ def load_content(filename: str) -> list: # load json content
return combine return combine
def load_word(filename: str) -> list: # load banned words list def loadWord(filename: str) -> list: # load banned words list
banned_list = [] bannedList = []
for word in open(filename).read().split('\n'): for word in open(filename).read().split('\n'):
word = word.strip() word = word.strip()
if word != '': if word != '':
banned_list.append(word) bannedList.append(word)
return banned_list return bannedList
def search_word(content: list, word: str) -> list: # search target word def searchWord(content: list, word: str) -> list: # search target word
result = [] result = []
for row in content: for row in content:
if word in row: if word in row:
@ -40,9 +40,9 @@ def search_word(content: list, word: str) -> list: # search target word
return result return result
def search_list(content: list, words: list) -> None: # search target banned list def searchList(content: list, words: list) -> None: # search target banned list
for word in words: for word in words:
result = search_word(content, word) result = searchWord(content, word)
if len(result) == 0: # banned word not found if len(result) == 0: # banned word not found
continue continue
print('Found \033[0;36m%d\033[0;39m banned word: \033[0;32m%s\033[0;39m' % (len(result), word)) print('Found \033[0;36m%d\033[0;39m banned word: \033[0;32m%s\033[0;39m' % (len(result), word))
@ -54,4 +54,4 @@ def search_list(content: list, words: list) -> None: # search target banned lis
print('-' * 128 + '\n') print('-' * 128 + '\n')
search_list(load_content(sys.argv[1]), load_word(sys.argv[2])) searchList(loadContent(sys.argv[1]), loadWord(sys.argv[2]))

14
src/character/character.py

@ -10,7 +10,7 @@ defaultPath = os.path.join(
) )
def load_content(filename: str) -> list: # load json content def loadContent(filename: str) -> list: # load json content
if not filename.endswith('.json'): if not filename.endswith('.json'):
filename += '.json' # add file suffix filename += '.json' # add file suffix
raw = json.loads(open( raw = json.loads(open(
@ -23,14 +23,14 @@ def load_content(filename: str) -> list: # load json content
return combine return combine
def character_set(content: list) -> list: # split into character set def characterSet(content: list) -> list: # split into character set
characters = set() characters = set()
for row in content: for row in content:
characters.update({x for x in row}) characters.update({x for x in row})
return sorted(characters) return sorted(characters)
def to_unicode(character: str) -> int: # get unicode number def toUnicode(character: str) -> int: # get unicode number
character = character[0] # only first character character = character[0] # only first character
unicode = 0 unicode = 0
for i in range(0, 4): for i in range(0, 4):
@ -38,11 +38,11 @@ def to_unicode(character: str) -> int: # get unicode number
return unicode return unicode
def show_characters(characters: list) -> None: # show character stat def showCharacters(characters: list) -> None: # show character stat
chinese = [] chinese = []
punctuation = [] punctuation = []
for c in characters: for c in characters:
if int('4E00', 16) < to_unicode(c) < int('9FA5', 16): # chinese unicode range if int('4E00', 16) < toUnicode(c) < int('9FA5', 16): # chinese unicode range
chinese.append(c) chinese.append(c)
else: else:
punctuation.append(c) punctuation.append(c)
@ -57,6 +57,6 @@ def show_characters(characters: list) -> None: # show character stat
print('\n') print('\n')
show_characters( showCharacters(
character_set(load_content(sys.argv[1])) characterSet(loadContent(sys.argv[1]))
) )

Loading…
Cancel
Save