Skip to content

Commit

Permalink
Add occurance of characters with argparse
Browse files Browse the repository at this point in the history
  • Loading branch information
7pandeys committed Aug 20, 2024
1 parent aace1e1 commit 4a7216c
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/github-actions-demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ jobs:
steps:
- run: python --version
- run: curl -sSL https://install.python-poetry.org | python3 -
# - run: cp /home/runner/work/2024/2024/Basic/Basic_Of_Python/pyproject.toml .
# - run: poetry install
- run: cd ${{ github.workspace }}/Basic/Basic_Of_Python
- run: poetry install
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
Expand Down
2 changes: 0 additions & 2 deletions Basic/Basic_Of_Python/basic_of_python/__init__.py

This file was deleted.

2 changes: 2 additions & 0 deletions Basic/Basic_Of_Python/src/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"""This allows you to import prime_numbers directly from prime_module."""
from .prime_numbers import prime_numbers
101 changes: 101 additions & 0 deletions Basic/Basic_Of_Python/src/occurrence_char.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
"""This module is to check occurances of character."""

import argparse
import logging


# from Basic
# from .configs.occurrence_config import (INPUT_STRING)


def count_of_occurrence(value):
"""
Determine if a number is prime.
Args:
x (int): The number to check for primality
Returns:
str: A message stating whether the number is prime or not.
"""
d = {}
for i in value:
if i not in d:
d[i] = + 1
else:
d[i] = 1
return d


class OccurrenceChar:
"""HelloArg."""

def __init__(self):
"""
Get Instance of OccurrenceCharacter.
:param logger: Logger
:param input_string: input value
"""
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s = %(message)s')
self.logger = logging.getLogger(__name__)

self.parser = argparse.ArgumentParser(description="Occurrence of Characters")
self.parser.add_argument('--verbose', action='store_true', help='Enable verbose logging')
self.parser.add_argument('--name', type=str, required=True, help="String to be process")

def parse_arguments(self):
"""
Determine if a number is prime.
Args:
x (int): The number to parse arguments
Returns:
str: arguments.
"""
args = self.parser.parse_args()
if args.verbose:
self.logger.setLevel(logging.DEBUG)
else:
self.logger.setLevel(logging.INFO)
return args

def run(self):
"""
Determine if a number is prime.
Args:
x (int): The number to check for primality
Returns:
str: A message stating whether the number is prime or not.
"""
args = self.parse_arguments()
self.logger.debug('Arguments parsed: %s', args)

# Example of using the parsed argument
self.logger.info('Hello, %s!', args.name)

# Simulate some processing
try:
self.logger.debug('Starting processing...')
# Simulate processing step
out = count_of_occurrence(args.name)
# result = f"Output {out}"
self.logger.info("Here you GO :")
for key, value in out.items():
self.logger.info("%s is occurring %s times", key, value)

# self.logger.info('Processing complete: %s', result)
except (TypeError, KeyError) as e:
self.logger.error('A specific error occurred: %s', e)


if __name__ == "__main__":
app = OccurrenceChar()
app.run()
File renamed without changes.
2 changes: 1 addition & 1 deletion Basic/Basic_Of_Python/tests/prime_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from basic_of_python.prime_numbers import prime_numbers
from src.prime_numbers import prime_numbers

def test_prime_number():
assert prime_numbers(11) == "11 is Prime Number"
Expand Down

0 comments on commit 4a7216c

Please sign in to comment.