Skip to content

Commit c94d0f2

Browse files
obervinovgithub-actions[bot]
andauthored
PR-24: Bug fixes and minor typos (#24)
## v1.0.4 - 2024-02-04 ### What's Changed **full changelog**: v1.0.3...v1.0.4 by @ obervinov #24 #### 📚 Bug Fixes * [List all supported versions of python](#23) * [Soft handling of situations where a configuration file or alias does not exist](#22) --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 5a20f62 commit c94d0f2

File tree

9 files changed

+51
-24
lines changed

9 files changed

+51
-24
lines changed

.github/workflows/pr.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ on:
1010

1111
jobs:
1212
changelog:
13-
uses: obervinov/_templates/.github/workflows/[email protected].12
13+
uses: obervinov/_templates/.github/workflows/[email protected].13
1414

1515
pylint:
16-
uses: obervinov/_templates/.github/workflows/[email protected].12
16+
uses: obervinov/_templates/.github/workflows/[email protected].13
1717

1818
pytest:
19-
uses: obervinov/_templates/.github/workflows/[email protected].12
19+
uses: obervinov/_templates/.github/workflows/[email protected].13
2020

2121
pyproject:
22-
uses: obervinov/_templates/.github/workflows/[email protected].12
22+
uses: obervinov/_templates/.github/workflows/[email protected].13

.github/workflows/release.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ on:
99

1010
jobs:
1111
changelog:
12-
uses: obervinov/_templates/.github/workflows/[email protected].12
12+
uses: obervinov/_templates/.github/workflows/[email protected].13
1313

1414
pylint:
15-
uses: obervinov/_templates/.github/workflows/[email protected].12
15+
uses: obervinov/_templates/.github/workflows/[email protected].13
1616

1717
pytest:
18-
uses: obervinov/_templates/.github/workflows/[email protected].12
18+
uses: obervinov/_templates/.github/workflows/[email protected].13
1919

2020
pyproject:
21-
uses: obervinov/_templates/.github/workflows/[email protected].12
21+
uses: obervinov/_templates/.github/workflows/[email protected].13
2222

2323
create-release:
24-
uses: obervinov/_templates/.github/workflows/[email protected].12
24+
uses: obervinov/_templates/.github/workflows/[email protected].13
2525
needs: [changelog, pylint, pytest, pyproject]

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file.
33
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
44

55

6+
## v1.0.4 - 2024-02-04
7+
### What's Changed
8+
**full changelog**: https://github.com/obervinov/messages-package/compare/v1.0.3...v1.0.4 by @ obervinov https://github.com/obervinov/messages-package/pull/24
9+
#### 📚 Bug Fixes
10+
* [List all supported versions of python](https://github.com/obervinov/messages-package/issues/23)
11+
* [Soft handling of situations where a configuration file or alias does not exist](https://github.com/obervinov/messages-package/issues/22)
12+
13+
614
## v1.0.3 - 2024-01-29
715
### What's Changed
816
**full changelog**: https://github.com/obervinov/messages-package/compare/v1.0.2...v1.0.3 by @ obervinov https://github.com/obervinov/messages-package/pull/21

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 obervinov
3+
Copyright (c) 2024 obervinov
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,5 @@ print(
123123
_output result_
124124
```python
125125
🏞 Messages from the queue have already been processed
126-
[◾◾◾◾◾◾◾◾◾◾◾◾◾◾◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻◻◻◻]19%
126+
[◾◾◾◾◾◾◾◾◾◾◾◾◾◾◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️]19%
127127
```

messages/messages.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import json
77
import math
88
import re
9+
from typing import Union
910
import emoji
1011

1112

@@ -39,15 +40,25 @@ def __init__(
3940
else:
4041
self.config_path = 'configs/messages.json'
4142

42-
with open(self.config_path, 'r', encoding='UTF-8') as config_json:
43-
self.data = json.load(config_json)
44-
config_json.close()
43+
if os.path.exists(self.config_path):
44+
with open(self.config_path, 'r', encoding='UTF-8') as config_json:
45+
try:
46+
self.data = json.load(config_json)
47+
config_json.close()
48+
except json.JSONDecodeError as json_error:
49+
# pylint: disable=no-value-for-parameter
50+
raise json.JSONDecodeError(
51+
f"Configuration file {self.config_path} is not valid JSON: {json_error}\n"
52+
"https://github.com/obervinov/messages-package?tab=readme-ov-file#-usage-examples"
53+
)
54+
else:
55+
raise FileNotFoundError(f"Configuration file not found: {self.config_path}")
4556

4657
def render_template(
4758
self,
4859
template_alias: str = None,
4960
**kwargs
50-
) -> str | None:
61+
) -> Union[str, None]:
5162
"""
5263
Method for reading the text from the configuration file.
5364
@@ -79,13 +90,14 @@ def render_template(
7990
# Building full message
8091
return template['text'].format(*arguments)
8192
except KeyError:
93+
print(f"[Messages]: template not found: {template_alias}")
8294
return None
8395

8496
def render_progressbar(
8597
self,
8698
total_count: int = 0,
8799
current_count: int = 0
88-
) -> str | None:
100+
) -> Union[str, None]:
89101
"""
90102
A Method for generating string with a progress bar based
91103
on the transmitted statistics data.

poetry.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "messages"
3-
version = "1.0.3"
3+
version = "1.0.4"
44
description = "This package helps to easily and quickly generate beautiful messages for telegram bots using templates described in json."
55
authors = ["Bervinov Oleg <[email protected]>"]
66
maintainers = ["Bervinov Oleg <[email protected]>"]
@@ -17,7 +17,7 @@ include = ["CHANGELOG.md"]
1717
"Bug Tracker" = "https://github.com/obervinov/messages-package/issues"
1818

1919
[tool.poetry.dependencies]
20-
python = "^3.10"
20+
python = "^3.9 || ^3.10 || ^3.11"
2121
emoji = "^2"
2222

2323
[build-system]

tests/configs/messages.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
{"templates":{"test_message": {"text": "Hi, <b>{0}</b>! {1}\nAccess for your account - allowed {2}", "args": ["username", ":raised_hand:", ":unlocked:"]}}}
1+
{
2+
"templates": {
3+
"test_message": {
4+
"text": "Hi, <b>{0}</b>! {1}\nAccess for your account - allowed {2}",
5+
"args": ["username", ":raised_hand:", ":unlocked:"]
6+
}
7+
}
8+
}

0 commit comments

Comments
 (0)