Commit 168936ef authored by Renán Sosa Guillen's avatar Renán Sosa Guillen

date classifier

parent 30d91be1
......@@ -8,7 +8,7 @@ python parse_date_files.py <nombre_del_crawler>
Ej.
python parse_date_files.py laJornadaBC2
"""
this_file_path = os.path.dirname(os.path.realpath(__file__))
json_file_path = this_file_path+'/descarga_hacia_atras/'+sys.argv[1]
destination_path = this_file_path+'/'+sys.argv[1]
......@@ -17,38 +17,38 @@ json_file = json.loads(open(json_file_path+'/noticias.json').read())
date_set = set()
for news in json_file:
if news['date'] is not None:
news_date = news['date'][:news['date'].rfind('T')]
if len(news_date) > 10:
news_date = news['date'][:news['date'].rfind(' ')]
if not news_date in date_set:
date_set.add(news_date)
print(news_date)
try:
export_file = open(destination_path+'/'+news_date[:4]+'/'+news_date+'.json', 'a')
except:
os.makedirs(destination_path+'/'+news_date[:4])
export_file = open(destination_path+'/'+news_date[:4]+'/'+news_date+'.json', 'a')
counter = 0
export_file.write('[')
for line in json_file:
if line['date'] is not None:
line_date = line['date'][:line['date'].rfind('T')]
if len(line_date) > 10:
line_date = line['date'][:line['date'].rfind(' ')]
if line_date == news_date:
counter += 1
if counter == 1:
export_file.write(json.dumps(line))
elif counter > 1:
export_file.write(','+'\n'+json.dumps(line))
export_file.write(']')
export_file.close()
if news['date'] is not None:
news_date = news['date'][:news['date'].rfind('T')]
if len(news_date) > 10:
news_date = news['date'][:news['date'].rfind(' ')]
if not news_date in date_set:
date_set.add(news_date)
print(news_date)
try:
export_file = open(destination_path+'/'+news_date[:4]+'/'+news_date+'.json', 'a')
except:
os.makedirs(destination_path+'/'+news_date[:4])
export_file = open(destination_path+'/'+news_date[:4]+'/'+news_date+'.json', 'a')
counter = 0
export_file.write("[")
for line in json_file:
if line['date'] is not None:
line_date = line['date'][:line['date'].rfind('T')]
if len(line_date) > 10:
line_date = line['date'][:line['date'].rfind(' ')]
if line_date == news_date:
counter += 1
if counter == 1:
export_file.write(json.dumps(line))
elif counter > 1:
export_file.write(",\n" + json.dumps(line))
export_file.write("]")
export_file.close()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment