以下のコードでは、DB に実際に表示される唯一のコミットは、最後に見つかった「idn」です。idn は、顧客ごとにいくつのセット トップ ボックスがあるかをカウントするための識別番号です。したがって、idn 1、2、および 3 がすべて存在する場合、1、2、および 3 を正しくする必要がある場合にのみ、DB に 3 を書き込みます。idn 1 のみが存在する場合は、書き込まれます。ご協力いただきありがとうございます!
if "STBSINFO||" in line:
head, sep, tail = line.partition('STBSINFO||')
idn = idn + 1
if "|" in tail:
head, sep, tail = tail.partition('|')
#Creates the mac address variable from the partition
mac = head
if "|" in tail:
head, sep, tail = tail.partition('|')
#Gathers the IP of the given set top box
stbip = head
if idn == 1:
cursor.execute("INSERT OR REPLACE INTO packages (cid, mstb1) VALUES (?,?)", (cid, stbip))
conn.commit()
elif idn == 2:
cursor.execute("INSERT OR REPLACE INTO packages (cid, mstb2) VALUES (?,?)", (cid, stbip))
conn.commit()
elif idn == 3:
cursor.execute("INSERT OR REPLACE INTO packages (cid, mstb3) VALUES (?,?)", (cid, stbip))
conn.commit()
elif idn == 4:
cursor.execute("INSERT OR REPLACE INTO packages (cid, mstb4) VALUES (?,?)", (cid, stbip))
conn.commit()