Skip to content

Instantly share code, notes, and snippets.

@kyu999
Created August 10, 2014 15:42
Show Gist options
  • Save kyu999/dc1576ce8c7e41831213 to your computer and use it in GitHub Desktop.
Save kyu999/dc1576ce8c7e41831213 to your computer and use it in GitHub Desktop.
改行からのjson化
def json_articles(self):
"""
複数動作確認用
"""
f = open("sample_title.txt", "r")
lines = f.readlines()
cleaner = title_cleaner.TitleCleaner()
articles = []
for line in lines:
unicoded_line = cleaner.normalize(unicode(line, "utf-8"))
breaks = self.get_break_points(unicoded_line)
json_data = {"title": unicoded_line, "title_break_position": breaks}
articles.append(json_data)
f.close()
return {"response": {"article": articles}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment