This task is to address some of the issues identified in T122227.
Execution and business logic code need to be separated, the code needs more comments and better variable names, curl code needs to be abstracted (or use a separate library) to avoid code duplication. Try to make sure the important functions are testable (i.e. self-contained functions that have well defined return values, etc.). We should probably put the business logic code in a class and make the code more object-oriented in general (for better modularity, readability, memory usage, testability, etc.). Also create a README.md with some basic documentation.