Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📦 NEW: get week and get month #47

Merged
merged 1 commit into from
Apr 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion happy/functions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
import os
from datetime import datetime
from datetime import datetime, timedelta
from random import choice, sample
from sys import exit

Expand Down Expand Up @@ -130,6 +130,8 @@ def read_file(
tag=None,
date=False,
today=False,
lastndays=False,
days=0,
flowers=False,
after=False,
before=False,
Expand Down Expand Up @@ -159,6 +161,18 @@ def read_file(
display = True
display_entry(flowers, log, nocolor)

if lastndays:
inital_time = datetime.today() - timedelta(days=days)

with open(DATA_PATH, "r") as happy_file:
happy_data = json.load(happy_file) # converts json file to dictionary
for log in happy_data['logs']:
date = log['date']
dt = datetime.strptime(date, "%d/%b/%Y")
if dt > inital_time:
display = True
display_entry(flowers, log, nocolor)

elif tag is not None:
with open(DATA_PATH, "r") as happy_file:
happy_data = json.load(happy_file)
Expand Down
18 changes: 18 additions & 0 deletions happy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def cli() -> None:
get = subparsers.add_parser("get", help="gets entries")
get.add_argument("all", help="gets all entries", nargs="?")
get.add_argument("today", help="gets today's entries", nargs="?")
get.add_argument("week", help="gets the week's entries", nargs="?")
get.add_argument("month", help="gets the months's entries", nargs="?")
get.add_argument("before today", help="gets all entries before today", nargs="?")
get.add_argument("random", help="gets a random entry", nargs="?")
get.add_argument(
Expand Down Expand Up @@ -98,6 +100,22 @@ def header(msg=""):
footer()
exit()

# `happy get week`
elif args.all == "week":
console.print("")
header("This Week's Entries")
read_file(lastndays=True, days=7, flowers=args.flowers, nocolor=args.nocolor)
footer()
exit()

# `happy get month`
elif args.all == "month":
console.print("")
header("This Months's Entries")
read_file(lastndays=True, days=30, flowers=args.flowers, nocolor=args.nocolor)
footer()
exit()

# `happy get all`
elif args.all == "all":
console.print("")
Expand Down