memoir wordcount automation
authorM. Taylor Saotome-Westlake <[email protected]>
Sat, 7 Jan 2023 18:51:52 +0000 (10:51 -0800)
committerM. Taylor Saotome-Westlake <[email protected]>
Sat, 7 Jan 2023 18:53:24 +0000 (10:53 -0800)
This doesn't count as an accomplishment today, the second day of the
new year (that I'm willing to admit to), but it's—warming up my typing
fingers. Now to make the line go up!

notes/memoir_wordcounts.csv
notes/memoir_wordcounts.py

index 5aa77e6..222b03c 100644 (file)
@@ -1,9 +1,43 @@
-04/30/22,6746
-05/30/22,10305
-06/30/22,13313
-07/31/22,20391
-08/28/22,36784
-09/30/22,49533
-10/30/22,66302
-11/30/22,74002
-12/22/22,74043
+03/13/2022,5961\r
+04/09/2022,5965\r
+04/21/2022,5990\r
+04/29/2022,6141\r
+05/08/2022,7392\r
+05/14/2022,7412\r
+05/15/2022,7757\r
+05/20/2022,8783\r
+05/22/2022,8682\r
+05/29/2022,9785\r
+06/04/2022,10655\r
+06/05/2022,11437\r
+06/10/2022,11537\r
+06/16/2022,13076\r
+06/26/2022,13285\r
+07/08/2022,13341\r
+07/17/2022,16167\r
+07/23/2022,15642\r
+07/23/2022,19852\r
+07/29/2022,18832\r
+08/03/2022,20388\r
+08/07/2022,23247\r
+08/14/2022,25009\r
+08/20/2022,26132\r
+08/25/2022,35059\r
+08/28/2022,36784\r
+09/03/2022,39599\r
+09/09/2022,41815\r
+09/15/2022,44858\r
+09/18/2022,45706\r
+09/25/2022,47740\r
+09/30/2022,49533\r
+10/07/2022,51922\r
+10/14/2022,53472\r
+10/20/2022,58146\r
+10/25/2022,62922\r
+10/29/2022,64086\r
+11/04/2022,66317\r
+11/06/2022,68083\r
+11/12/2022,69792\r
+11/20/2022,71859\r
+11/27/2022,74002\r
+12/16/2022,74039\r
index 6d2e0f9..eeb297a 100755 (executable)
@@ -1,25 +1,59 @@
 #!/usr/bin/env python3
 
+import csv
+import datetime
+import re
 import subprocess
 
-shas = [
-    '347fe081c6',
-    '4681a3764a',
-    '867b6583c7',
-    'a8b07bd83a',
-    'cfdc07319c',
-    'bbb4315cfe'
-]
-
-for sha in shas:
-    subprocess.run(["git", "checkout", sha])
-    subprocess.run("wc content/drafts/blanchards-dangerous-idea-and-the-plight-of-the-lucid-crossdreamer.md content/drafts/a-hill-of-validity-in-defense-of-meaning.md content/drafts/agreeing-with-stalin-in-ways-that-exhibit-generally-rationalist-principles.md".split())
-
-# 30 Apr 347fe081c6   6746
-# 30 May 4681a3764a  10308   +3562
-# 30 Jun 867b6583c7  13313   +3005
-# 31 Jul a8b07bd83a  20391   +7078
-# 28 Aug cfdc07319c  36784  +16393
-# 30 Sep bbb4315cfe  49533  +12749
-# 30 Oct c9b6c312d1  66302  +16769
-# 30 Nov (projected) 83302??
+MONTHS = {
+    "Jan": 1,
+    "Feb": 2,
+    "Mar": 3,
+    "Apr": 4,
+    "May": 5,
+    "Jun": 6,
+    "Jul": 7,
+    "Aug": 8,
+    "Sep": 9,
+    "Oct": 10,
+    "Nov": 11,
+    "Dec": 12,
+}
+
+def wordcount_at_this_sha():
+    result = subprocess.run("wc -w content/drafts/blanchards-dangerous-idea-and-the-plight-of-the-lucid-crossdreamer.md content/drafts/a-hill-of-validity-in-defense-of-meaning.md content/drafts/if-clarity-seems-like-death-to-them.md content/drafts/agreeing-with-stalin-in-ways-that-exhibit-generally-rationalist-principles.md".split(), stdout=subprocess.PIPE)
+    wc_lines = result.stdout.decode('utf8').split('\n')
+    total_line = wc_lines[-2]  # last line is empty
+    return int(total_line.split()[0])
+
+def date_at_this_sha():
+    result = subprocess.run("git show HEAD".split(), stdout=subprocess.PIPE)
+    show_lines = result.stdout.decode('utf8').split('\n')
+    dateline = show_lines[2]
+    match_groups = re.search("(?P<month>\w{3}) (?P<day>\d{1,2}) \d{2}:\d{2}:\d{2} (?P<year>\d{4})", dateline).groupdict()
+    return datetime.date(int(match_groups['year']), MONTHS[match_groups['month']], int(match_groups['day']))
+
+
+def look_back():
+    wordcounts = []
+    keep_going = True
+    while keep_going:
+        subprocess.run(["git", "checkout", "HEAD~10"])
+        wordcount = wordcount_at_this_sha()
+        date = date_at_this_sha()
+        if date < datetime.date(2022, 4, 1):
+            keep_going = False
+        wordcounts.append((date, wordcount))
+    return sorted(wordcounts)
+
+
+def write_csv(wordcounts):
+    with open("memoir_wordcounts.csv", 'w') as f:
+        writer = csv.writer(f)
+        for date, wordcount in wordcounts:
+            writer.writerow([date.strftime("%m/%d/%Y"), wordcount])
+
+
+if __name__ in "__main__":
+    wordcounts = look_back()
+    write_csv(wordcounts)