datafile writing in a mode, readme update

This commit is contained in:
Doman 2021-07-11 00:35:48 +02:00
parent c28cac3805
commit 77e856a177
5 changed files with 15 additions and 11 deletions

View file

@ -15,9 +15,9 @@ from cloned github repository. Without any argument program waits for user to en
`python3 -m fasttyper example_text.txt`
Program also allows user to pipe text into it. Keep in mind, it only supports spaces and new line characters, so you won't be able to table tabs. For example, you can run _Fasttyper_ on rfurtune generated quote changing tabulators to spaces with sed:
Program also allows user to pipe text into it. Keep in mind, it only supports spaces and new line characters, so you won't be able to table tabs. For example, you can run _Fasttyper_ on fortune generated quote changing tabulators to spaces with sed:
`rfurtune | sed 's/\t/ /g' | python3 -m fasttyper`
`furtune | sed 's/\t/ /g' | python3 -m fasttyper`
# Known issues

View file

@ -5,5 +5,5 @@
"stats_template": "\n\nwpm: {stats.wpm}\ntime: {stats.total_seconds}s",
"stats_color": 5,
"summary_template": "WPM: {stats.wpm}\nCPM: {stats.cpm}\nRAW WPM: {stats.raw_wpm}\nRAW CPM: {stats.raw_cpm}\ntotal seconds: {stats.total_seconds}\ntotal minutes: {stats.total_minutes}\ncorrect words: {stats.correct_words}\ncorrect chars: {stats.correct_chars}\nincorrect words: {stats.incorrect_words}\nincorrect chars: {stats.incorrect_chars}\ntotal words: {stats.total_words}\ntotal chars: {stats.total_chars}\naccuracy: {stats.accuracy}%",
"summary_datafile": "~/.config/cache/fasttyper/datafile.csv"
}
"summary_datafile": "~/.cache/fasttyper/datafile.csv"
}

View file

@ -43,7 +43,7 @@ def main():
parser = argparse.ArgumentParser()
if is_tty:
parser.add_argument("file", metavar="FILE")
parser.add_argument("file", metavar="FILE", help="file to type")
parser.add_argument(
"--config",

View file

@ -20,7 +20,7 @@ class Config:
"total chars: {stats.total_chars}\n"
"accuracy: {stats.accuracy}%"
),
"summary_datafile": "~/.config/cache/fasttyper/datafile.csv",
"summary_datafile": "~/.cache/fasttyper/datafile.csv",
}
def __init__(self, configmap):

View file

@ -110,10 +110,14 @@ class Stats:
record = self.produce_record()
with open(datafile, "w") as f:
writter = csv.DictWriter(f, fieldnames=record.keys())
if not exists:
if not exists:
with open(datafile, "w") as f:
writter = csv.DictWriter(f, fieldnames=record.keys())
writter.writeheader()
writter.writerow(record)
else:
with open(datafile, "a") as f:
writter = csv.DictWriter(f, fieldnames=record.keys())
writter.writerow(record)
writter.writerow(record)
print(f"\nwrote stats to {datafile}")