<commit_before>#!/usr/bin/python

import json, sys, xml.sax.saxutils, os

def escape_text(string):
	return xml.sax.saxutils.escape(string.encode('utf-8'))

def get_child_urls(node):
	for c in node['children']:
		if 'url' in c and not c['url'].startswith('javascript:'):
			out.write('<dd><a href="%s">%s</a></dd>' % (escape_text(c['url']), escape_text(c['name'])))
		if 'children' in c:
			out.write("<dt>%s</dt><dd><dl>" % escape_text(c['name']))
			get_child_urls(c)
			out.write("</dl></dd>")

in_file = os.path.expanduser(sys.argv[1])
out_file = os.path.expanduser(sys.argv[2])

f = open(in_file, 'r')
file_contents = f.read()
f.close()

j = json.loads(file_contents)

out = open(out_file, 'w')

out.write("<html><head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8' /><title>Chrome Bookmarks</title></head><body><dl>")

out.write("<dt>Bookmark Bar</dt><dd><dl>")
get_child_urls(j['roots']['bookmark_bar'])
out.write("</dl></dd>")

out.write("<dt>Other</dt><dd><dl>")
get_child_urls(j['roots']['other'])
out.write("</dl></dd>")

out.write("</dl></body></html>")

out.close()
<commit_msg>Use heredoc for output<commit_after>#!/usr/bin/python

import json, sys, xml.sax.saxutils, os

def escape_text(string):
	return xml.sax.saxutils.escape(string.encode('utf-8'))

def get_child_urls(node):
	for c in node['children']:
		if 'url' in c and not c['url'].startswith('javascript:'):
			out.write('<dd><a href="%s">%s</a></dd>' % (escape_text(c['url']), escape_text(c['name'])))
		if 'children' in c:
			out.write("<dt>%s</dt><dd><dl>" % escape_text(c['name']))
			get_child_urls(c)
			out.write("</dl></dd>")

in_file = os.path.expanduser(sys.argv[1])
out_file = os.path.expanduser(sys.argv[2])

f = open(in_file, 'r')
file_contents = f.read()
f.close()

j = json.loads(file_contents)

out = open(out_file, 'w')

out.write("""<html>

<head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
<title>Chrome Bookmarks</title>
</head>

<body>

<dl>

<dt>Bookmark Bar</dt><dd><dl>
%(bookmark_bar)s
</dl></dd>

<dt>Other</dt><dd><dl>
%(other)s
</dl></dd>

</dl></body></html>"""
	% {'bookmark_bar': get_child_urls(j['roots']['bookmark_bar']),
		'other': get_child_urls(j['roots']['other'])})

out.close()

{'fraction_non_alphanumeric': 0.2516763522574877, 'fraction_numerical': 0.003576218149307108, 'mean_word_length': 5.907407407407407, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4756041', 'n_tokens_mistral': 945, 'n_tokens_neox': 931, 'n_words': 142}