Skip to content

Commit bddbe74

Browse files
authored
Merge pull request #1 from HarshitDalal/develop
Initial code of NumWord Package
2 parents 3d1b9f3 + b540cb8 commit bddbe74

File tree

11 files changed

+465
-4
lines changed

11 files changed

+465
-4
lines changed

.github/workflows/daily_test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
python -m unittest discover -s tests
3030
3131
- name: Upload log files
32-
uses: actions/upload-artifact@v3
32+
uses: actions/upload-artifact@v4
3333
with:
3434
name: log-files
35-
path: WordToNumTest.log
35+
path: NumWord.log

.github/workflows/manual_test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
python -m unittest discover -s tests
2727
2828
- name: Upload log files
29-
uses: actions/upload-artifact@v3
29+
uses: actions/upload-artifact@v4
3030
with:
3131
name: log-files
32-
path: WordToNumTest.log
32+
path: NumWord.log

.gitignore

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
### Python template
2+
# Byte-compiled / optimized / DLL files
3+
__pycache__/
4+
*.py[cod]
5+
*$py.class
6+
7+
# C extensions
8+
*.so
9+
10+
# Distribution / packaging
11+
.Python
12+
build/
13+
develop-eggs/
14+
dist/
15+
downloads/
16+
eggs/
17+
.eggs/
18+
lib/
19+
lib64/
20+
parts/
21+
sdist/
22+
var/
23+
wheels/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
cover/
54+
55+
# Translations
56+
*.mo
57+
*.pot
58+
59+
# Django stuff:
60+
*.log
61+
local_settings.py
62+
db.sqlite3
63+
db.sqlite3-journal
64+
65+
# Flask stuff:
66+
instance/
67+
.webassets-cache
68+
69+
# Scrapy stuff:
70+
.scrapy
71+
72+
# Sphinx documentation
73+
docs/_build/
74+
75+
# PyBuilder
76+
.pybuilder/
77+
target/
78+
79+
# Jupyter Notebook
80+
.ipynb_checkpoints
81+
82+
# IPython
83+
profile_default/
84+
ipython_config.py
85+
86+
# pyenv
87+
# For a library or package, you might want to ignore these files since the code is
88+
# intended to run in multiple environments; otherwise, check them in:
89+
# .python-version
90+
91+
# pipenv
92+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
93+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
94+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
95+
# install all needed dependencies.
96+
#Pipfile.lock
97+
98+
# poetry
99+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
100+
# This is especially recommended for binary packages to ensure reproducibility, and is more
101+
# commonly ignored for libraries.
102+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
103+
#poetry.lock
104+
105+
# pdm
106+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
107+
#pdm.lock
108+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
109+
# in version control.
110+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
111+
.pdm.toml
112+
.pdm-python
113+
.pdm-build/
114+
115+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
116+
__pypackages__/
117+
118+
# Celery stuff
119+
celerybeat-schedule
120+
celerybeat.pid
121+
122+
# SageMath parsed files
123+
*.sage.py
124+
125+
# Environments
126+
.env
127+
.venv
128+
env/
129+
venv/
130+
ENV/
131+
env.bak/
132+
venv.bak/
133+
134+
# Spyder project settings
135+
.spyderproject
136+
.spyproject
137+
138+
# Rope project settings
139+
.ropeproject
140+
141+
# mkdocs documentation
142+
/site
143+
144+
# mypy
145+
.mypy_cache/
146+
.dmypy.json
147+
dmypy.json
148+
149+
# Pyre type checker
150+
.pyre/
151+
152+
# pytype static type analyzer
153+
.pytype/
154+
155+
# Cython debug symbols
156+
cython_debug/
157+
158+
# PyCharm
159+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
160+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
161+
# and can be added to the global gitignore or merged into this file. For a more nuclear
162+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
163+
.idea/
164+
165+
NumWord/temp.py
166+

Logs/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .logs import LoggerConfig

Logs/logs.py

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import logging
2+
import logging.config
3+
import os
4+
5+
6+
class LoggerConfig(logging.Logger):
7+
"""
8+
A class to configure logging settings for an application.
9+
"""
10+
11+
def __init__(self, app_name, streams=('console', 'file'), file_name='NumWord.log'):
12+
"""
13+
Initialize LoggerConfig with given parameters.
14+
15+
Args:
16+
app_name (str): Name of the application.
17+
streams (tuple, optional): List of streams to log to. Options are ('file', ) or ('console', 'file') Default is ('console', ).
18+
file_name (str, optional): Name of the log file, default is 'SAM.log'.
19+
"""
20+
super().__init__(app_name)
21+
self.__app_name = app_name
22+
self.__stream = list(streams)
23+
self.__filename = file_name
24+
25+
def __handler_config(self):
26+
"""
27+
Configure logging handlers based on the specified streams.
28+
29+
Returns:
30+
dict: A dictionary containing the logging handler configurations.
31+
Depending on the value of `self.__stream`, it can contain:
32+
33+
- Both 'console' and 'file' handlers
34+
- Only 'file' handler
35+
- Only 'console' handler
36+
37+
Notes:
38+
- 'console': Logs will be displayed on the console.
39+
- 'file': Logs will be written to a file specified by `self.__filename`.
40+
41+
"""
42+
return {
43+
'console': {
44+
'class': 'logging.StreamHandler',
45+
'formatter': 'default'
46+
},
47+
'file': {
48+
'class': 'logging.FileHandler',
49+
'filename': self.__filename,
50+
'formatter': 'default'
51+
}
52+
} if self.__stream == ['console', 'file'] else {
53+
'file': {
54+
'class': 'logging.FileHandler',
55+
'filename': self.__filename,
56+
'formatter': 'default'
57+
}
58+
} if self.__stream == ['file'] else {
59+
'console': {
60+
'class': 'logging.StreamHandler',
61+
'formatter': 'default'
62+
}
63+
}
64+
65+
def __log_config(self):
66+
"""
67+
Configure logging settings including formatters, handlers, and loggers.
68+
69+
Constructs a dictionary containing the logging configuration details for the application.
70+
71+
Returns:
72+
dict: Logging configuration dictionary with version, formatters, handlers, and loggers.
73+
74+
"""
75+
return {
76+
'version': 1,
77+
'disable_existing_loggers': False,
78+
'formatters': {
79+
'default': {
80+
'format': '%(asctime)s - %(name)s - %(levelname)-8s - %(message)s'
81+
}
82+
},
83+
'handlers': self.__handler_config(),
84+
'loggers': {
85+
f'{self.__app_name}': {
86+
'handlers': self.__stream,
87+
'level': os.getenv('LOG_LEVEL', 'INFO'),
88+
'propagate': True
89+
}
90+
}
91+
}
92+
93+
def __configure_logger(self):
94+
"""
95+
Configure the logger using the constructed logging configuration dictionary.
96+
97+
Uses the `logging.config.dictConfig` method to apply the logging configuration.
98+
99+
Returns:
100+
None: Configures the logger settings for the application.
101+
"""
102+
logging.config.dictConfig(self.__log_config())
103+
104+
def get_logger(self):
105+
"""
106+
Retrieve the logger for the application.
107+
108+
Returns:
109+
logging.Logger: Returns a logger instance configured for the application.
110+
"""
111+
self.__configure_logger()
112+
return logging.getLogger(self.__app_name)

NumWord/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from .english import ENGLISH
2+
3+
class GetLanguage:
4+
def get_language(self, language):
5+
if language == "en":
6+
return ENGLISH
7+
else:
8+
raise NotImplementedError(f"Language {language} is not supported.")

NumWord/english.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
ENGLISH = {
2+
"zero": 0,
3+
"one": 1,
4+
"two": 2,
5+
"three": 3,
6+
"four": 4,
7+
"five": 5,
8+
"six": 6,
9+
"seven": 7,
10+
"eight": 8,
11+
"nine": 9,
12+
"ten": 10,
13+
"eleven": 11,
14+
"twelve": 12,
15+
"thirteen": 13,
16+
"fourteen": 14,
17+
"fifteen": 15,
18+
"sixteen": 16,
19+
"seventeen": 17,
20+
"eighteen": 18,
21+
"nineteen": 19,
22+
"twenty": 20,
23+
"thirty": 30,
24+
"forty": 40,
25+
"fifty": 50,
26+
"sixty": 60,
27+
"seventy": 70,
28+
"eighty": 80,
29+
"ninety": 90,
30+
"hundred": 100,
31+
"thousand": 1000,
32+
"million": 1000000,
33+
"billion": 1000000000,
34+
"trillion": 1000000000000,
35+
"quadrillion": 1000000000000000,
36+
"quintillion": 1000000000000000000,
37+
"sextillion": 1000000000000000000000,
38+
"septillion": 1000000000000000000000000,
39+
"octillion": 1000000000000000000000000000,
40+
"nonillion": 1000000000000000000000000000000,
41+
}
42+
43+

0 commit comments

Comments
 (0)