Skip to content

Instantly share code, notes, and snippets.

@molcay
Last active March 7, 2017 12:26
Show Gist options
  • Save molcay/6cc49aaa0885a9e81940 to your computer and use it in GitHub Desktop.
Save molcay/6cc49aaa0885a9e81940 to your computer and use it in GitHub Desktop.
24 Bin Haber [from: http://www.kemik.yildiz.edu.tr/?id=28] için dosya içeriğini json olarak veren script
# -*- coding: utf-8 -*-
import os
import json
import io
__basedir__ = os.getcwd()
categories = os.listdir(__basedir__)
files_content = []
for category in categories:
__dir__ = os.path.join(__basedir__, category)
if not os.path.isfile(__dir__): # dosyayı dikkate almamak için
for the_file in os.listdir(__dir__):
with io.open(os.path.join(__dir__, the_file), 'r', encoding='utf8') as f:
title = f.readline().replace("\n", "").strip()
content = f.read().strip()
files_content.append( {
'id': u'{0}-{1}'.format(category, the_file.split('.txt')[0]),
'category': u'{}'.format(category),
'title': u'{}'.format(title),
'content': u'{}'.format(content),
'length': u'uzun' if len(content) > 1748 else u'kısa'
} )
with open('result.json', 'w') as fp:
json.dump(files_content, fp, sort_keys=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment