Skip to content

Commit

Permalink
rudimentary test case
Browse files Browse the repository at this point in the history
  • Loading branch information
DeutscheGabanna committed Oct 22, 2023
1 parent 6841e02 commit 19f52e8
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 16 deletions.
12 changes: 6 additions & 6 deletions compile_md.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
import logging
from functools import reduce
# Other
import cmd_args
from cmd_args import settings
import load_moods
import utils

def compile_note_YAML():
def compile_note_yaml():
"""Returns string with YAML metadata for each note. It looks like this:
---
tags: <your_custom_tags>
---
"""
return f"---\ntags: {cmd_args.settings.TAGS} \n---\n\n"
return f"---\ntags: {settings.TAGS} \n---\n\n"

def compile_entry_contents(entry):
"""Return a string that is a parsed entry from Daylio CSV as a string.
Expand All @@ -37,11 +37,11 @@ def compile_entry_contents(entry):
"""
# compose the title with optional mood colouring
this_entry_title = get_colour(entry.mood) + entry.mood + " - " + entry.time
final_output = cmd_args.settings.HEADER_LEVEL*'#' + " " + this_entry_title
final_output = settings.HEADER_LEVEL*'#' + " " + this_entry_title

# compose the mood-tag and the activity-tags into one paragraph
final_output += "\nI felt #"
final_output += utils.slugify(entry.mood, cmd_args.settings.ACTIVITIES_AS_TAGS)
final_output += utils.slugify(entry.mood, settings.ACTIVITIES_AS_TAGS)
if len(entry.activities) > 0 and entry.activities[0] != "":
final_output += " with the following: "
## first append # to each activity, then mush them together into one string
Expand All @@ -61,7 +61,7 @@ def get_colour(mood_to_check):
"""Prepend appropriate colour for the mood passed in mood_to_check"""
prepended_colour = ""
mood_colour=["🟣","🟢","🔵","🟠","🔴"] # 0 - best, 4 - worst mood group
if cmd_args.settings.colour:
if settings.colour:
for i, (_, this_group) in enumerate(load_moods.available_moods.items()):
if mood_to_check in this_group:
prepended_colour = f"{mood_colour[i]} "
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
)

for day, entries in days.items():
note_contents = compile_md.compile_note_YAML()
note_contents = compile_md.compile_note_yaml()
for current_entry in entries:
note_contents += compile_md.compile_entry_contents(current_entry)
current_note = write_md.Note(day, note_contents)
Expand Down
6 changes: 3 additions & 3 deletions parse_csv.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Creates structured data from Daylio .CSV"""
import csv
import utils
import cmd_args
from cmd_args import settings

delimiter = f" {cmd_args.settings.csv_delimiter} "
delimiter = f" {settings.csv_delimiter} "

class Entry:
"""Journal entry made at a given moment in time, and describing a particular emotional state"""
Expand All @@ -16,7 +16,7 @@ def __init__(self, parsed_line, prop_inside_delimiter = delimiter):
for index, _ in enumerate(self.activities):
self.activities[index] = utils.slugify(
self.activities[index],
cmd_args.settings.ACTIVITIES_AS_TAGS
settings.ACTIVITIES_AS_TAGS
)
self.title = self.slice_quotes(parsed_line[6])
self.note = self.slice_quotes(parsed_line[7])
Expand Down
4 changes: 0 additions & 4 deletions test_main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
"""Test cases for main.py"""
import unittest
import os
# Custom
import parse_csv
import write_md
import compile_md
import utils
import cmd_args

class TestScript(unittest.TestCase):
def setUp(self):
Expand Down
4 changes: 2 additions & 2 deletions write_md.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
import hashlib
import os
# Custom
import cmd_args
from cmd_args import settings

class Note:
"""Note is a file encompassing every entry made on a given date"""
def __init__(self, day, contents):
self.day = day
self.contents = contents
self.path = f"{os.path.join(cmd_args.settings.destination, cmd_args.settings.prefix)}{day}{cmd_args.settings.suffix}.md"
self.path = f"{os.path.join(settings.destination, settings.prefix)}{day}{settings.suffix}.md"
self.control_sum = hashlib.sha256()
temp_contents = self.contents # we need a temporary contents var to be consumed
for byte_block in iter(lambda: temp_contents[:4096].encode('utf-8'), b""):
Expand Down

0 comments on commit 19f52e8

Please sign in to comment.