'Updating cell in Google Sheet when mentioning specific word on Twitter

So, I'm using twitter API and Google Sheets API. I'm trying to make a store bot that recognizes mentions and then updates Google Sheet. I want to make a specific cell an inventory. Ex: a single cell contains [ item1, item2, item3 ]

I'm having problems because i'm trying to do this:

  1. When you don't have item4 on the specific inventory cell and you mention [Buy][item4] to the bot, you add item4 to cell so it looks like this: [ item1, item2, item3, item4 ]
  2. When you do have item4 on the specific inventory cell and you mention [Buy][item4] to the bot, it changes [ item4 ] into [ item4X2 ]

I think I can do 1 by using

        worksheet = sh.sheet1
        cell = worksheet.find(mention.user.screen_name)

        delta = result_text #item4

        for i in range(1, 10):
            print(worksheet.cell(cell.row, i).value, end=' ')
            if i == 8:
                item = str(worksheet.cell(cell.row, i).value)
                worksheet.update_cell(cell.row, i, item+", "+delta)
                print(">",worksheet.cell(cell.row, i).value, end=' ')

but I don't know how to do 2. I have no idea... maybe I have to find [ item4 ] in a cell and when it's true you do a certain IF, and when it's false you do a different IF? This is hard to explain.

SUMMARY:

  1. Cell value is [ item1, item2, item3 ]

  2. If cell doesn't have item4, it adds item4 > [ item1, item2, item3, item4 ]

  3. and then when you buy another item4, it changes item4 to item4X2 [ item1, item2, item3, item4X2 ]



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source