Alright this is my first program in python, so be gentle. I have 2 files I need to basically combine to create a record in mysql. Features.txt has around 1300 records and property.txt has about 25,000 records. I can read in property.txt fine and get my insert statements. My problem is trying to read in features.txt. I only need the lines that have field 1 = RES. I was thinking a dictionary ('1701' : 'Central Air', '1702' : 'Window Unit", etc) but can seem to quite get it.
for featureline in ffeaturefile.readlines():
featureline = featureline.strip().split("|")
addlist += "'%s', '%s'," % (featureline[0], featureline[3])
resfeaturelist = dict(addlist)
features.txt
1701|RES|HVAC|Central Air
1702|RES|HVAC|Window Unit
1703|RES|HVAC|Heat Pump - AC|
1704|RES|HVAC|No A/C
1705|RES|HVAC|Wall Unit - AC
1706|RES|HVAC|Multizone A/C
1708|RES|HVAC|Gas Hot Air
1701|CND|HVAC|Central Air
...
property.txt (there are a 105 fields so I shortened it here)
0.293|53548|47459||4|101|QUART|2|4||Matthews||1505,1510,1514||1701,1708,1722|
...
I'm inserting into a mysql database here is what I have right now:
Insert into openrealty_en_listingsdbelements (listingdbelements_field_name,listingdbelements_field_value,listingsdb_id,userdb_id) values ('HVAC','1701,1708','2','0');
but I need
Insert into openrealty_en_listingsdbelements (listingdbelements_field_name,listingdbelements_field_value,listingsdb_id,userdb_id) values ('HVAC','Central Air,Gas Hot Air','2','0');
for number, resline in enumerate(fresfile):
resline = resline.strip().split("|")
for count in [0, 21]:
if (count == 21):
#change values to text in features.txt
resfields = resline[count].split(",")
for i, item in enumerate(resfields):
if (featureline[0] == item):
print resfields[3]
else:
fsqlfile.write ("Insert into openrealty_en_listingsdbelements (listingdbelements_field_name,listingdbelements_field_value,listingsdb_id,userdb_id) values ('" + resheader[count] + "','" + resline[count] + "','" + str(number) + "','0');\n")
Also, once I get the features.txt into a dictionary how do I do the substitution?