Converting command line python script to django app

I inherited the command line python script "myscript.py" which has several classes and contains the following:

def main():
    parser = OptionParser()
    parser.add_option("-a", "--all", dest="saveall",
                      help="Store all information", action="store_true",
                      default=False)
    options, args = parser.parse_args()
    output = options.output
    count = options.count
    saveall=options.saveall

    grabber = Grabber()
    grabber.run(count, output, saveall)
if __name__ == '__main__':
    main()

      

I tested this on the command line and it works. I want to turn it into a django app. I can easily place all the classes in the application view, but I'm not sure how to refactor the main function to launch the application with various parameters that are available via an HTTP request to django. assuming I am passing arguments with something like:

@csrf_exempt
def myscript(request):

    option1 = str(request.POST.get( option1, False))
    option2 = str(request.POST.get(option2, False))

      

How to run myscript from django passing parameters to it with minimal changes to the script?

+3


source to share





All Articles