﻿# open earthquakes file in read mode
fn = open('../data/earthquakes.csv', 'r')
# open output files in write mode
# output file with the lines containing titles
fnTitles = open('../data/titles.csv', 'w')
# output file with the lines containing data
fnWithoutTitles = open('../data/earthquakes-no-titles.csv', 'w')
# search in lines for the string "time"
search_string = "time"
# read the content of the file line by line 
cont = fn.readlines() 
type(cont) 
for line in range(0, len(cont)):
    if cont[line].find(search_string) and line != 0 :
        #if string "time" is not found write line in file earthquakes-no-titles.csv
        fnWithoutTitles.write(cont[line])
    else:
        # if string "time" is  found write line in file titles.csv
        fnTitles.write(cont[line])
# close all files
fnWithoutTitles.close()
fnTitles.close()
fn.close()

