mirror of
https://github.com/Xameren/Txt-File-Analyser.git
synced 2025-02-04 08:39:23 +01:00
Add files via upload
This commit is contained in:
parent
bf29b5ceed
commit
5fa794f351
2 changed files with 66 additions and 0 deletions
BIN
Snímek obrazovky (7261).png
Normal file
BIN
Snímek obrazovky (7261).png
Normal file
Binary file not shown.
After Width: | Height: | Size: 75 KiB |
66
Text analyzer.py
Normal file
66
Text analyzer.py
Normal file
|
@ -0,0 +1,66 @@
|
|||
from collections import Counter
|
||||
import re
|
||||
import time
|
||||
from os import system
|
||||
|
||||
system("title " + ".txt file analyser")
|
||||
FirstTime = True
|
||||
|
||||
def FileMenu():
|
||||
print("\033[H\033[J", end="")
|
||||
Words = text.split()
|
||||
WordCount = Counter(Words)
|
||||
|
||||
x = "[()],"
|
||||
y = " :"
|
||||
TranslateTable = str.maketrans(x, y)
|
||||
|
||||
LongestWord = max(Words, key=len)
|
||||
SmallestWord = min(Words, key=len)
|
||||
|
||||
Sentences = [s.strip() for s in re.split(r'[.!?]+', text) if s.strip()]
|
||||
# magic i came up with at 30 past midnight. Removes special chars and shit.
|
||||
SentenceCount = len(Sentences) - 1
|
||||
|
||||
CharCountNS = sum(len(word) for word in Words)
|
||||
CharCount = len(text)
|
||||
print("====== Sentences =======")
|
||||
print(f"Number of sentences: {SentenceCount}")
|
||||
print(f"Longest sentence: {max(Sentences, key=len)}")
|
||||
print(f"Shortest sentence: {min(Sentences, key=len)}\n")
|
||||
print("======== Words =========")
|
||||
print(f"Number of words: {len(Words)}")
|
||||
print(f"Longest word: {LongestWord}")
|
||||
print(f"Shortest word: {SmallestWord}\n")
|
||||
print("====== Characters ======")
|
||||
print(f"Character count (no spaces): {CharCountNS}")
|
||||
print(f"Character count: {CharCount}\n")
|
||||
print("======== Other =========")
|
||||
print("The 5 most common words:")
|
||||
print(str(WordCount.most_common(5)).replace("), (", "\n ").translate(TranslateTable))
|
||||
# i spent too much time here for what i should have...
|
||||
print("\n========================")
|
||||
print("Press enter to choose another file")
|
||||
input()
|
||||
|
||||
|
||||
def MainMenu(): # amazing menu
|
||||
global text, FirstTime
|
||||
while True:
|
||||
print("\033[H\033[J", end="")
|
||||
if FirstTime == True:
|
||||
print("Welcome to the Xameren's text file analyser")
|
||||
FirstTime = False
|
||||
print("Please enter your file name (for example, \"xameren\", not \"xameren.txt\")")
|
||||
filechosen = input()
|
||||
try:
|
||||
with open(f'{filechosen}.txt', 'r') as file:
|
||||
text = file.read()
|
||||
FileMenu()
|
||||
except Exception as e:
|
||||
print("Please enter a valid file")
|
||||
print("error: ", e )
|
||||
print("\nIf it shows a \"file missing\" error, but file exists, please restart the app")
|
||||
time.sleep(5)
|
||||
|
||||
MainMenu()
|
Loading…
Add table
Reference in a new issue