Updated version.
All checks were successful
isspam build / build (push) Successful in 32s

This commit is contained in:
retoor 2024-11-30 20:32:55 +01:00
parent 94e5d7bfa5
commit 3785af9bb4
3 changed files with 53 additions and 1 deletions

BIN
isspam

Binary file not shown.

View File

@ -263,7 +263,12 @@ sl *get_forbidden_words(char *content) {
slf(words);
return found;
}
unsigned int total = 0;
void analyze(FILE *f) {
total = total + 1;
printf("#%u\n", total);
char *data = fread_till_eof(f);
str_t *all = strn(1337);
@ -321,9 +326,15 @@ void analyze(FILE *f) {
stra(all, sbuf);
free(sbuf);
strd(all);
if(words->count){
double capitalized_word_percentage = 100 * ((double)capitalized_words->count / (double)words->count);
printf("Capitalized percentage: %f%%\n",capitalized_word_percentage);
double forbidden_word_percentage = 100 * ((double)fw->count / (double)words->count);
printf("Forbidden percentage: %f%%\n",forbidden_word_percentage);
ulonglong word_count_per_sentence = words->count / (sentences->count ? sentences->count : 1);
printf("Word count per sentence: %llu\n", word_count_per_sentence);
}
slf(capitalized_words);
slf(sentences);
slf(words);

41
totals.py Normal file
View File

@ -0,0 +1,41 @@
#
# [USAGE]
#
# This quick & dirty script will summarize the output
# generated by the isspam application.
# To use, you do:
# ./isspam ./your-content/*.txt > output.txt
# Then you execute: python totals.py output.txt
# - retoor
import sys
import pathlib
totals = {}
count = 0
with pathlib.Path(sys.argv[1]).open("r") as f:
data = f.read()
for line in data.split("\n"):
if line.startswith("<"):
continue
parts = line.split(": ")
if(len(parts) < 2):
continue
key = parts[0]
if key == "File":
count += 1
if not key in ["File","Memory usage"]:
if key not in totals:
totals[key] = 0.0
value = float(parts[1].replace("%",""))
totals[key] += value
else:
value = parts[1]
for key, value in totals.items():
print(key.count("percentage"))
if key.count("percentage") > 0:
value = value / count
print(key,":",value)