I am trying to find a more efficient way to filter through a list of SSIDs in a .csv file and then write the filtered results to another file.
Currently, the code I have looks like this (And it works as expected):
def ssidFilter():
File = open("/home/pi/unFilter.csv", "r")
for line in File:
if 'Test SSID' in line:
with open("/home/pi/dataLog.csv", "a") as finalFile:
finalFile.write(str(line))
if 'Public' in line:
with open("/home/pi/dataLog.csv", "a") as finalFile:
finalFile.write(str(line))
if 'HomeNet' in line:
with open("/home/pi/dataLog.csv", "a") as finalFile:
finalFile.write(str(line))
if 'Network 1' in line:
with open("/home/pi/gpsMaster/dataLog.csv", "a") as finalFile:
finalFile.write(str(line))
if 'LimeOak' in line:
with open("/home/pi/dataLog.csv", "a") as finalFile:
finalFile.write(str(line))
if 'BlackCrow' in line:
with open("/home/pi/dataLog.csv", "a") as finalFile:
finalFile.write(str(line))
if 'GuestWiFi' in line:
with open("/home/pi/dataLog.csv", "a") as finalFile:
finalFile.write(str(line))
File.close()
However, I'd like to use a solution that isn't running through each of the SSIDs separately. Id like to use a list and iterate through it. I asked a question about the zip function this morning, but wasn't able to get it working with this part of the code.
What I've been working with (Has NOT worked):
SSID = ['Test SSID' , 'Public' , '....etc...']
File = open("/home/pi/unFilter/csv" , "r")
for line in File:
if SSID in line:
with open("/home/pi/dataLog.csv", "a") as finalFile:
finalFile.write(str(line))
File.close()
The output of this yields an error at 'if SSID in line:' as "TypeError: 'in ' requires string as left operand, not list."
When substituting 'if SSID' with 'if str(SSID)', I get no error, but also nothing returns and I'm guessing that's because its searching for that whole string instead of the individual elements.
I've had the same TypeError, except its treating it as a tuple and not a list, when trying to use zip, if I'm using it correctly..
File = open('/home/pi/unFilter.csv', 'r')
for line in File:
for new in zip(SSID):
if new in line:
print line
How should I approach this issue?