Giter Site home page Giter Site logo


Logo

Demo Design Patterns

Object-Oriented Design and Design Patterns Knowledge
Why Learn Patterns »

Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Examples
  5. Tests
  6. Contributing
  7. Challenges
  8. Contact
  9. Acknowledgments

About The Project

Product Name Screen Shot

Make a tool that is built on "SOLID" principles.

(back to top)

Getting Started

This is a simple API allowing you to add new records, filter users. Display data in Json and Yaml. A CLI exists to add, display, convert and filter the whole data set. It is written so as to have an extendable system in future. No Validation is included at this point as the focus is only on patterns.

Prerequisites

Additional Modules required.

  • json2html
  • pytest
  • pyyaml

Installation

  • Create a python3.9 virtual environment and activate it
virtualenv .venv
.venv\Scripts\activate.bat
  • cd into cloned repo and run
cd singhaidotnish

Ready to test.

Usage

For testing module

pip install -e .[dev]

(back to top)

For command line see examples below

To make use of new file type follow these steps

  1. Add new file type to class variable ALL_TYPES of class FileFactory
    ALL_TYPES = ['Json', 'Yaml', '<new_file_type>']
  1. Based on class description below, replace "yaml" with new file type. and use its corresponding load and dump methods to read and write.
class Yaml(IFile):
    DEMO_YAML = 'demo.yaml'

    def __init__(self):
        super().__init__()
        self.name = 'Yaml'
        self.file = os.path.join(os.path.dirname(__file__), Yaml.DEMO_YAML)

    def read(self, read_from=None):
        _data = None
        try:
            if read_from:
                _data = json.dumps(read_from, indent=4)
                _data = json.loads(_data)
            else:
                with open(self.file, 'r') as yamlFile:
                    _data = yaml.safe_load(yamlFile) or []
        except yaml.YAMLError as e:
            raise Exception('Error Reading Yaml {e}')
        return _data

    def write(self, data):
        try:
            _tmp_data = self.read()
            _tmp_data['data'].append(data)
            with open(self.file, 'w') as stream:
                yaml.safe_dump(_tmp_data, stream, default_flow_style=False)
        except (IOError, ) as e:
            return False
        return _tmp_data

Examples:

Add -

python -m demo_design_pattern.cli --add --name FF --phone 9090909090 --address "a\\b building no X, floor X, landmark, city, state pincode" --filetype Yaml

Add Command

Display -

python -m demo_design_pattern.cli --display --filetype Yaml

Display Command

Convert -

python -m demo_design_pattern.cli --convert --filetype Yaml --filetype_to Json

Convert Command

Filter -

python -m demo_design_pattern.cli --filter A* --filetype Yaml

Filter Command

List all file types -

python -m demo_design_pattern.cli --all_types

List All Types Command

Tests:

Go to tests folder

Test Add

pytest -k add -v

Test Add

Test Convert

pytest -k convert -v

Test Convert

Test Filter

pytest -k filter -v

Test Convert

Test Display

pytest -k display -v

Test Convert

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

Challenges

  1. Converting json to yaml is not working. It shows json format instead of yaml format on terminal
  2. Writing Document is more challenging then writing code.

Contact

Your Name - @knishua - singhai(dot)nish(at)gmail.com

Project Link: https://github.com/singhaidotnish/singhaidotnish

(back to top)

Acknowledgments

  • Animal Logic Pipeline - I am Thankful to the pipeline team at Animal Logic for giving this task.

(back to top)

Nishith Singhai's Projects

awesome-cg-vfx-pipeline icon awesome-cg-vfx-pipeline

List of open-source technologies that help in the process of building a pipeline for CG and VFX productions

jekyll-klise icon jekyll-klise

:beach_umbrella: Klisé is a minimalist Jekyll theme for running a personal site or blog, light & dark mode support. (https://klise.vercel.app)

minimal-mistakes icon minimal-mistakes

:triangular_ruler: Jekyll theme for building a personal site, blog, project documentation, or portfolio.

resume-template icon resume-template

:page_facing_up::briefcase::tophat: A simple Jekyll + GitHub Pages powered resume template.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.