from os import remove import sys def chunk(thelist, chunksize): # do chunking ret = list() for i in range(0,len(thelist),chunksize): ret.append(thelist[i:i+chunksize]) return ret def filetolist(path): lines = list() with open(path) as f: line = f.readline() while line: lines.append(line) line = f.readline() return lines def main(): if len(sys.argv) < 4: print("error") lines = filetolist(sys.argv[1]) secrets = filetolist(sys.argv[3]) # lines = ["\#\#\#\#\#,{},\#\#\#\#\#\n".format(secrets.pop(0)[0:-2])] + lines # add padding chunksize = 4 for _ in range((chunksize - len(lines) % chunksize) % chunksize): lines.append("\#\#\#,{},\#\#\#\n".format(secrets.pop(0)[0:-2])) ret = list() for c in chunk(lines, chunksize): ret.append(c) ret.append([c[1], c[0], c[3], c[2]]) with open(sys.argv[2],'w+') as f: for c in ret: for l in c: f.write(l) return with open(sys.argv[3],'w+') as f: for s in secrets: f.write(s) if __name__ == '__main__': main()