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'):
filename += '.json' # add file suffix
raw = json.loads(open(
@ -23,16 +23,16 @@ def load_content(filename: str) -> list: # load json content
return combine
def load_word(filename: str) -> list: # load banned words list
banned_list = []
def loadWord(filename: str) -> list: # load banned words list
bannedList = []
for word in open(filename).read().split('\n'):
word = word.strip()
if word != '':
banned_list.append(word)
return banned_list
bannedList.append(word)
return bannedList
def search_word(content: list, word: str) -> list: # search target word
def searchWord(content: list, word: str) -> list: # search target word
result = []
for row in content:
if word in row:
@ -40,9 +40,9 @@ def search_word(content: list, word: str) -> list: # search target word
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:
result = search_word(content, word)
result = searchWord(content, word)
if len(result) == 0: # banned word not found
continue
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')
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'):
filename += '.json' # add file suffix
raw = json.loads(open(
@ -23,14 +23,14 @@ def load_content(filename: str) -> list: # load json content
return combine
def character_set(content: list) -> list: # split into character set
def characterSet(content: list) -> list: # split into character set
characters = set()
for row in content:
characters.update({x for x in row})
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
unicode = 0
for i in range(0, 4):
@ -38,11 +38,11 @@ def to_unicode(character: str) -> int: # get unicode number
return unicode
def show_characters(characters: list) -> None: # show character stat
def showCharacters(characters: list) -> None: # show character stat
chinese = []
punctuation = []
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)
else:
punctuation.append(c)
@ -57,6 +57,6 @@ def show_characters(characters: list) -> None: # show character stat
print('\n')
show_characters(
character_set(load_content(sys.argv[1]))
showCharacters(
characterSet(loadContent(sys.argv[1]))
)

Loading…
Cancel
Save