I'm needing some help on appending my data to the output .csv file. What I have is I'm generating a .csv file down line by line from city and state data. It has to be in order from top to bottom and not random. Here is the code that is creating the .csv file with one column.
f_in = open("data_files/main_keyword.txt",'r') prefix = f_in.read().strip() f_in = open('data_files/states/' + random.choice(list(open('data_files/generate_what_state.txt'))).replace("\n", "") + '.csv', 'r') f_out = open('data_files/titles.csv', 'w') for line in f_in.readlines(): f_out.write(prefix.title() + ' ' + line.split(",")[1]+"" + ' ' + line.split(",")[2]+"" + ' - ' + random.choice(list(open('data_files/end_keywords.txt'))).replace("\n", "").title() + ' In ' + line.split(",")[0]+"" + '') f_out.write('\n') f_in.close() Example data of the output for the above code:
Air Duct Cleaning Addison Texas - Cleaning Air Ducts In Dallas Air Duct Cleaning Allen Texas - Cost Of Air Duct Cleaning In Dallas Air Duct Cleaning Balch Springs Texas - Cleaning Air Ducts In Dallas Air Duct Cleaning Carrollton Texas - Cleaning Air Ducts In Dallas That creates what I need for the city and state titles in the first column. What I need to do is append this data to the next data that is generated. So my first column is the city and state titles, my next column needs to be this data generated in the output file specified below in the code.
f_in = open("data_files/main_keyword.txt",'r') prefix = f_in.read().strip() f_in = open('data_files/states/' + random.choice(list(open('data_files/generate_what_state.txt'))).replace("\n", "") + '.csv', 'r') f_out = open('import_this_file_into_wordpress.csv', 'w') for line in f_in.readlines(): f_out.write(';<p>' + random.choice(list(open('data_files/content.txt'))).replace("\n", "") + '</p>' + '\n') f_in.close() Example data of the output for the above code:
<p>This is a line of text generated.</p> <p>This is a line of text generated.</p> <p>This is a line of text generated.</p> <p>This is a line of text generated.</p> So what I'm doing is generating the city and state titles and saving them into a .csv file and then generating the body of the post and needing to append the city and state titles to the first column of the file import_this_file_into_wordpress.csv. I need to append the city and state titles from top to bottom entirely line by line to this file. So my final output would be column 1 is city and state title and column 2 is the body content. Can someone help me with this? I hope I made some sense of that. If not please tell me and I will try and clarify a bit more. Thank you for your help.
Example of how the data should be output in the final file:
Air Duct Cleaning Addison Texas - Cleaning Air Ducts In Dallas,<p>This is a line of text generated.</p> Air Duct Cleaning Allen Texas - Cost Of Air Duct Cleaning In Dallas,<p>This is a line of text generated.</p> Air Duct Cleaning Balch Springs Texas - Cleaning Air Ducts In Dallas,<p>This is a line of text generated.</p> Air Duct Cleaning Carrollton Texas - Cleaning Air Ducts In Dallas,<p>This is a line of text generated.</p>