Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

Commit

Permalink
Merge branch 'release/0.24.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
SebRut committed Nov 16, 2020
2 parents f1746d3 + bc8969a commit 8a36fa1
Show file tree
Hide file tree
Showing 14 changed files with 494 additions and 452 deletions.
1 change: 1 addition & 0 deletions .github/no-response.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
responseRequiredLabel: more-information-needed

1 change: 1 addition & 0 deletions .github/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ exemptLabels:
- security
- "[Status] Maybe Later"
- enhancement
- tests
29 changes: 20 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
# Changelog

## [v0.23.0](https://github.com/SebRut/pygrocy/tree/v0.23.0) (2020-09-11)
## [v0.24.0](https://github.com/SebRut/pygrocy/tree/v0.24.0) (2020-11-16)

[Full Changelog](https://github.com/SebRut/pygrocy/compare/v0.22.0...v0.23.0)
[Full Changelog](https://github.com/SebRut/pygrocy/compare/v0.23.0...v0.24.0)

**Implemented enhancements:**

- add "get all products" method [\#97](https://github.com/SebRut/pygrocy/issues/97)
- Add "yearly" PeriodType [\#137](https://github.com/SebRut/pygrocy/pull/137) ([mdallaire](https://github.com/mdallaire))

**Closed issues:**

- Dependabot couldn't authenticate with https://pypi.python.org/simple/ [\#134](https://github.com/SebRut/pygrocy/issues/134)
- Split up main file [\#110](https://github.com/SebRut/pygrocy/issues/110)

**Merged pull requests:**

- Fix example [\#136](https://github.com/SebRut/pygrocy/pull/136) ([basxto](https://github.com/basxto))

## [v0.23.0](https://github.com/SebRut/pygrocy/tree/v0.23.0) (2020-09-11)

[Full Changelog](https://github.com/SebRut/pygrocy/compare/v0.22.0...v0.23.0)

**Closed issues:**

Expand All @@ -31,11 +44,13 @@

**Merged pull requests:**

- split up the main file [\#135](https://github.com/SebRut/pygrocy/pull/135) ([yellalena](https://github.com/yellalena))
- check if location field exists before parsing [\#130](https://github.com/SebRut/pygrocy/pull/130) ([SebRut](https://github.com/SebRut))
- Update responses requirement from ~=0.11.0 to ~=0.12.0 [\#128](https://github.com/SebRut/pygrocy/pull/128) ([dependabot-preview[bot]](https://github.com/apps/dependabot-preview))
- Update pdoc3 requirement from ~=0.9.0 to ~=0.9.1 [\#126](https://github.com/SebRut/pygrocy/pull/126) ([dependabot-preview[bot]](https://github.com/apps/dependabot-preview))
- Update pdoc3 requirement from ~=0.8.4 to ~=0.9.0 [\#125](https://github.com/SebRut/pygrocy/pull/125) ([dependabot-preview[bot]](https://github.com/apps/dependabot-preview))
- Update responses requirement from ~=0.10.16 to ~=0.11.0 [\#124](https://github.com/SebRut/pygrocy/pull/124) ([dependabot-preview[bot]](https://github.com/apps/dependabot-preview))
- Check for empty string in parse\_date [\#120](https://github.com/SebRut/pygrocy/pull/120) ([isabellaalstrom](https://github.com/isabellaalstrom))

## [v0.21.0](https://github.com/SebRut/pygrocy/tree/v0.21.0) (2020-08-18)

Expand All @@ -56,8 +71,8 @@
**Merged pull requests:**

- init all Product fields with None by default [\#123](https://github.com/SebRut/pygrocy/pull/123) ([SebRut](https://github.com/SebRut))
- Check for empty string in parse\_date [\#120](https://github.com/SebRut/pygrocy/pull/120) ([isabellaalstrom](https://github.com/isabellaalstrom))
- Update coveralls requirement from ~=2.1.1 to ~=2.1.2 [\#108](https://github.com/SebRut/pygrocy/pull/108) ([dependabot-preview[bot]](https://github.com/apps/dependabot-preview))
- Update responses requirement from ~=0.10.15 to ~=0.10.16 [\#107](https://github.com/SebRut/pygrocy/pull/107) ([dependabot-preview[bot]](https://github.com/apps/dependabot-preview))

## [v0.20.0](https://github.com/SebRut/pygrocy/tree/v0.20.0) (2020-08-16)

Expand Down Expand Up @@ -96,10 +111,6 @@

- Misnaming in enum [\#112](https://github.com/SebRut/pygrocy/issues/112)

**Merged pull requests:**

- fix issue \#112 [\#113](https://github.com/SebRut/pygrocy/pull/113) ([SebRut](https://github.com/SebRut))

## [v0.16.0](https://github.com/SebRut/pygrocy/tree/v0.16.0) (2020-08-13)

[Full Changelog](https://github.com/SebRut/pygrocy/compare/v0.15.0...v0.16.0)
Expand All @@ -110,9 +121,9 @@

**Merged pull requests:**

- fix issue \#112 [\#113](https://github.com/SebRut/pygrocy/pull/113) ([SebRut](https://github.com/SebRut))
- Bugfix/bug smashing [\#111](https://github.com/SebRut/pygrocy/pull/111) ([SebRut](https://github.com/SebRut))
- Add meal plan / recipe interfaces. \#90 [\#109](https://github.com/SebRut/pygrocy/pull/109) ([nervetattoo](https://github.com/nervetattoo))
- Update responses requirement from ~=0.10.15 to ~=0.10.16 [\#107](https://github.com/SebRut/pygrocy/pull/107) ([dependabot-preview[bot]](https://github.com/apps/dependabot-preview))
- Update pdoc3 requirement from ~=0.8.3 to ~=0.8.4 [\#105](https://github.com/SebRut/pygrocy/pull/105) ([dependabot-preview[bot]](https://github.com/apps/dependabot-preview))
- Update coveralls requirement from ~=2.0.0 to ~=2.1.1 [\#104](https://github.com/SebRut/pygrocy/pull/104) ([dependabot-preview[bot]](https://github.com/apps/dependabot-preview))
- Update pdoc3 requirement from ~=0.8.1 to ~=0.8.3 [\#102](https://github.com/SebRut/pygrocy/pull/102) ([dependabot-preview[bot]](https://github.com/apps/dependabot-preview))
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ grocy = Grocy("https://example.com", "GROCY_API_KEY", port = 9192, verify_ssl =
Get current stock:
```python
for entry in grocy.stock():
print("{} in stock for product id {}".format(entry.id, entry.amount))
print("{} in stock for product id {}".format(entry.available_amount, entry.id))
```

## Development testing
Expand Down
Empty file added pygrocy/data_models/__init__.py
Empty file.
152 changes: 152 additions & 0 deletions pygrocy/data_models/chore.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
from datetime import datetime
from enum import Enum
from typing import List, Dict
from pygrocy.base import DataModel
from pygrocy.data_models.user import User
from pygrocy.grocy_api_client import CurrentChoreResponse, ChoreDetailsResponse, GrocyApiClient


class PeriodType(str, Enum):
MANUALLY = "manually"
DYNAMIC_REGULAR = "dynamic-regular"
DAILY = "daily"
WEEKLY = "weekly"
MONTHLY = "monthly"
YEARLY = "yearly"


class AssignmentType(str, Enum):
NO_ASSIGNMENT = "no-assignment"
WHO_LEAST_DID_FIRST = "who-least-did-first"
RANDOM = "random"
IN_ALPHABETICAL_ORDER = "in-alphabetical-order"


class Chore(DataModel):
def __init__(self, response):
if isinstance(response, CurrentChoreResponse):
self._init_from_CurrentChoreResponse(response)
elif isinstance(response, ChoreDetailsResponse):
self._init_from_ChoreDetailsResponse(response)

# noinspection PyPep8Naming
def _init_from_CurrentChoreResponse(self, response: CurrentChoreResponse):
self._id = response.chore_id
self._last_tracked_time = response.last_tracked_time
self._next_estimated_execution_time = response.next_estimated_execution_time
self._name = None
self._last_done_by = None

# noinspection PyPep8Naming
def _init_from_ChoreDetailsResponse(self, response: ChoreDetailsResponse):
chore_data = response.chore
self._id = chore_data.id
self._name = chore_data.name
self._description = chore_data.description

if chore_data.period_type is not None:
self._period_type = PeriodType(chore_data.period_type)
else:
self._period_type = None

self._period_config = chore_data.period_config
self._period_days = chore_data.period_days
self._track_date_only = chore_data.track_date_only
self._rollover = chore_data.rollover

if chore_data.assignment_type is not None:
self._assignment_type = AssignmentType(chore_data.assignment_type)
else:
self._assignment_type = None

self._assignment_config = chore_data.assignment_config
self._next_execution_assigned_to_user_id = (
chore_data.next_execution_assigned_to_user_id
)
self._userfields = chore_data.userfields

self._last_tracked_time = response.last_tracked
self._next_estimated_execution_time = response.next_estimated_execution_time
if response.last_done_by is not None:
self._last_done_by = User(response.last_done_by)
else:
self._last_done_by = None
self._track_count = response.track_count
if response.next_execution_assigned_user is not None:
self._next_execution_assigned_user = User(
response.next_execution_assigned_user
)
else:
self._next_execution_assigned_user = None

def get_details(self, api_client: GrocyApiClient):
details = api_client.get_chore(self.id)
self._init_from_ChoreDetailsResponse(details)

@property
def id(self) -> int:
return self._id

@property
def name(self) -> str:
return self._name

@property
def description(self) -> str:
return self._description

@property
def period_type(self) -> PeriodType:
return self._period_type

@property
def period_config(self) -> str:
return self._period_config

@property
def period_days(self) -> int:
return self._period_days

@property
def track_date_only(self) -> bool:
return self._track_date_only

@property
def rollover(self) -> bool:
return self._rollover

@property
def assignment_type(self) -> AssignmentType:
return self._assignment_type

@property
def assignment_config(self) -> str:
return self._assignment_config

@property
def next_execution_assigned_to_user_id(self) -> int:
return self._next_execution_assigned_to_user_id

@property
def userfields(self) -> Dict[str, str]:
return self._userfields

@property
def last_tracked_time(self) -> datetime:
return self._last_tracked_time

@property
def next_estimated_execution_time(self) -> datetime:
return self._next_estimated_execution_time

@property
def last_done_by(self) -> User:
return self._last_done_by

@property
def track_count(self) -> int:
return self._track_count

@property
def next_execution_assigned_user(self) -> User:
return self._next_execution_assigned_user
83 changes: 83 additions & 0 deletions pygrocy/data_models/meal_items.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import base64
from datetime import datetime
from pygrocy.base import DataModel
from pygrocy.grocy_api_client import RecipeDetailsResponse, MealPlanResponse, GrocyApiClient


class RecipeItem(DataModel):
def __init__(self, response: RecipeDetailsResponse):
self._id = response.id
self._name = response.name
self._description = response.description
self._base_servings = response.base_servings
self._desired_servings = response.desired_servings
self._picture_file_name = response.picture_file_name

@property
def id(self) -> int:
return self._id

@property
def name(self) -> str:
return self._name

@property
def description(self) -> str:
return self._description

@property
def base_servings(self) -> int:
return self._base_servings

@property
def desired_servings(self) -> int:
return self._desired_servings

@property
def picture_file_name(self) -> str:
return self._picture_file_name

def get_picture_url_path(self, width: int = 400):
if self.picture_file_name:
b64name = base64.b64encode(self.picture_file_name.encode("ascii"))
path = "files/recipepictures/" + str(b64name, "utf-8")

return f"{path}?force_serve_as=picture&best_fit_width={width}"


class MealPlanItem(DataModel):
def __init__(self, response: MealPlanResponse):
self._id = response.id
self._day = response.day
self._recipe_id = response.recipe_id
self._recipe_servings = response.recipe_servings
self._note = response.note

@property
def id(self) -> int:
return self._id

@property
def day(self) -> datetime:
return self._day

@property
def recipe_id(self) -> int:
return self._recipe_id

@property
def recipe_servings(self) -> int:
return self._recipe_servings

@property
def note(self) -> str:
return self._note

@property
def recipe(self) -> RecipeItem:
return self._recipe

def get_details(self, api_client: GrocyApiClient):
recipe = api_client.get_recipe(self.recipe_id)
if recipe:
self._recipe = RecipeItem(recipe)
Loading

0 comments on commit 8a36fa1

Please sign in to comment.