Skip to content

Commit

Permalink
Automatically skip weekends again
Browse files Browse the repository at this point in the history
  • Loading branch information
stijndcl committed Sep 7, 2022
1 parent 4edae95 commit 071c495
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ $ food config ls

Note that `boolean` arguments can be supplied as any of `[true, false, t, f, 1, 0]`.

| Name | Description | Type (choices) | Default |
|---------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------|---------|
| hidden | A list of meal kinds that should be hidden when fetching menus. This can be useful for vegetarians and vegans who don't care about the meat dishes. | List\[String\] ("fish", "meat", "soup", "vegan", "vegetarian") | [] |
| language | The language used to fetch the menus in. | String ("en" 🇬🇧 , "nl" 🇧🇪/🇳🇱) | "en" |
| skip_weekends | Whether to automatically skip weekends when fetching menus. This defaults to true because the restaurants aren't usually open during weekends. For example: using the tool on a Saturday will show the menu for the coming Monday. | Boolean | True |
| Name | Description | Type (choices) | Default |
|---------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------|---------|
| hidden | A list of meal kinds that should be hidden when fetching menus. This can be useful for vegetarians and vegans who don't care about the meat dishes. | List\[String\] ("fish", "meat", "soup", "vegan", "vegetarian") | [] |
| language | The language used to fetch the menus in. | String ("en" 🇬🇧 , "nl" 🇧🇪/🇳🇱) | "en" |
| skip_weekends | Whether to automatically skip weekends when fetching menus without an explicit day argument. This defaults to true because the restaurants aren't usually open during weekends. For example: using the tool on a Saturday will show the menu for the coming Monday. | Boolean | True |
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ files = [

[tool.poetry]
name = "ugent-food"
version = "1.0.1"
version = "1.1.0"
description = "Command-line tool to get the current menu for Ghent University restaurants"
license = "MIT"
authors = ["stijndcl"]
Expand Down
2 changes: 1 addition & 1 deletion ugent_food/cli/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async def menu_fetcher(day: Optional[str] = None):
If no value is provided, the menu for today is fetched instead.
"""
# Try to parse the date arg
date_instance = parse_date_argument(day)
date_instance = parse_date_argument(day, skip_weekends=user_config.skip_weekends)

# Parsing failed
if date_instance is None:
Expand Down
3 changes: 2 additions & 1 deletion ugent_food/cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ class Config:
skip_weekends: bool = field( # type: ignore # Mypy doesn't enjoy this one
default=CONFIG_DEFAULTS["skip_weekends"],
metadata={
"description": "Whether to automatically skip weekends when fetching menus. "
"description": "Whether to automatically skip weekends when fetching menus "
"without an explicit day argument. "
"This defaults to True because the restaurants aren't usually open during weekends."
"\nUsing the tool on a Saturday (with this setting set to True) will show "
"the menu for the coming Monday instead."
Expand Down
6 changes: 5 additions & 1 deletion ugent_food/cli/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ def _forward_date_to(weekday: int, date_instance: date) -> date:
return date_instance


def parse_date_argument(argument: Optional[str] = None) -> Optional[date]:
def parse_date_argument(argument: Optional[str] = None, *, skip_weekends: bool = True) -> Optional[date]:
"""Try to parse an argument into a date"""
today = date.today()

# Default to today
if argument is None:
# If weekends should be skipped & today is a weekend, skip to monday
if skip_weekends and today.weekday() > 4:
today += timedelta(days=7 - today.weekday())

return today

argument = argument.lower()
Expand Down
2 changes: 1 addition & 1 deletion ugent_food/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.1"
__version__ = "1.1.0"

0 comments on commit 071c495

Please sign in to comment.