architv / soccer-cli

:soccer: Football scores for hackers. :computer: A command line interface for all the football scores.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Move printing functionality into it's own module

carlosvargas opened this issue · comments

Now that we are able to print the results out into multiple formats (Issue #36), we realized that we need to separate the functionality into it's own module to make things cleaner.

I was thinking about this and here are my thoughts.

Move all of the printing code into a module called writers.py that will look like:

def get_writer(output):
    if output == 'stdout':
         return Console()
    ...

class Console:
    def live_scores(...):    
    ...

class JSON:
    def live_scores(...):   
    ...

class CSV:
    def live_scores(...):   
    ...

then in main.py we can call the factory function:

import writers

def get_live_scores(writer):
    ...
    writer.live_scores(...)

def main(..., output):
    writer = writers.get_writer(output)
    ...
    if live:
         get_live_scores(writer)

What do you guys think?

i like this alot...and we can create a BaseClass such that Console/JSON/CSV can all inherit from it because they will have some similar functionality and name of functions. we can just override the functions that differ in implementation and define methods that are common in all 3 in the BaseClass.