importconfigparserimportargparseimportjsonimportosfromcolourimportColorfrommathimportceildefmain():args=parse_args()ifargs.string:phrase=args.stringelse:print('string required')raiseSystemExitrb=Rainbow(args.colors,args.start_color,args.end_color,args.format)rainbow_text=rb.generate(phrase)print(rainbow_text)classRainbow(object):"""A rainbow object that can be applied to a string"""def__init__(self,color_count=None,start_color=None,end_color=None,output_format=None):conf=parse_config('config.ini')self.color_count=int(conf['color_count'])self.start_color=conf['start_color']self.current_color=conf['start_color']self.index=Noneself.end_color=conf['end_color']self.output_format=conf['format']self.rainbow=[]self.cpc=1ifcolor_count:self.color_count=int(color_count)ifstart_color:self.start_color=start_colorself.current_color=start_colorifend_color:self.end_color=end_colorifoutput_format:self.output_format=output_formatwithopen(conf['formats_file'])asf:self.formats=json.loads(f.read())ifself.output_formatinself.formats:self.template=self.formats[self.output_format]else:raiseRuntimeError('format not found! Are you sure it exists in '+conf['formats_file']+'?')def__iter__(self):returnselfdef__next__(self):try:result=self.rainbow[self.index]exceptIndexError:raiseStopIterationself.index+=1returnresult