<commit_before>import os, re, requests
rootdir = '_posts'

for subdir, dirs, files in os.walk(rootdir):
    for file in files:
        filename = os.path.join(subdir, file)

    	f = open(filename, "r")
    	contents = f.readlines()
    	f.close()

    	# Find first image
    	for key, line in enumerate(contents):
    		src = re.search('\!\[.*?\]\((.*?)\)', line)
    		if src:
    			if re.search('\.(gif|png|jpg|jpeg)', src.group(1)):
    				print src.group(1)
	    			image = "hero: " + src.group(1) + "\n"
	    			contents[5] = "hero: " + src.group(1) + "\n"
	    			f = open(filename, "w")
			    	contents = "".join(contents)
			    	f.write(contents)
			    	f.close()
			    	break<commit_msg>Better wordpress image import<commit_after>import os, re, requests
rootdir = '_posts'

for subdir, dirs, files in os.walk(rootdir):
    for file in files:
        filename = os.path.join(subdir, file)

    	f = open(filename, "r")
    	contents = f.readlines()
    	f.close()

    	# Find first image
    	for key, line in enumerate(contents):
    		src = re.search('\!\[.*\]\((.*?)\)', line)
    		if src:
    			wordpress_src = re.search('/blog/images/wordpress/(.*)', src.group(1))
    			if wordpress_src:
    				print 'Retrieving ' + src.group(1) + '...'
	    			image_src = wordpress_src.group(1)
	    			f = open('images/wordpress/'+image_src, "w")
	    			f.write(requests.get("http://blog.stackoverflow.com/wp-content/uploads/" + wordpress_src.group(1)).content)
	    			f.close()

    	continue
    	f = open(filename, "w")
    	contents = "".join(contents)
    	f.write(contents)
    	f.close()
{'fraction_non_alphanumeric': 0.17515527950310558, 'fraction_numerical': 0.0055900621118012426, 'mean_word_length': 2.3702928870292888, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '6218164', 'n_tokens_mistral': 636, 'n_tokens_neox': 590, 'n_words': 123}