def insert_before_back(lines, thingsToAdd):
    backIndex = lines.index('Back:\n')
for item in reversed(thingsToAdd):
    lines.insert(backIndex, item)
return lines

def add_inventory(lines, shopName):
    shopFound = 0
for i in range(len(lines)):
    if shopName in lines[i]:
        shopFound = 1
if 'InventoryLocation:' in lines[i] and shopFound:
    shopFound = 0
lineSplit = lines[i].split(': ')
incrementInventory = str(int(lineSplit[-1]) + 1)
lineSplit[-1] = incrementInventory + '\n'
lines[i] = ': '.join(lineSplit)
newLines = []
with open('input.txt', 'r') as f:
    inputLines = f.readlines()
newLines = insert_before_back(inputLines, ['Hello\n', 'From\n', 'heinst\n'])
add_inventory(newLines, 'HadesKitty')
with open('output.txt', 'w') as f:
    for line in newLines:
        f.write(line)
Добавлять в определенный момент в файле, каждый раз увеличивать значение