<commit_before>'''
File: updateHosts.py
Author: <EMAIL>
Version: 0.0.1
Date: 2012-10-24 14:35:39
'''

import urllib
import os

def GetRemoteHosts(hostsUrl):
    fp = urllib.urlopen(hostsUrl)
    hosts = [line for line in fp]
    fp.close()
    return hosts

if __name__ == "__main__":
    hosts = GetRemoteHosts("http://tx.txthinking.com/hosts")
    hostsPath = "/etc/hosts"

    search = "#TX-HOSTS\n"
    yourHosts = ""
    fp = open(hostsPath, "a+")
    while 1:
        line = fp.readline()
        if line == search or line == "":
            break
        yourHosts += line
    yourHosts += search
    fp.close()

    os.rename(hostsPath, hostsPath + ".BAK")

    fp = open(hostsPath, "w")
    fp.write(yourHosts)
    fp.writelines(hosts) #iterable sequence hosts
    fp.close()

    print "Success"
<commit_msg>fix for reading hosts file<commit_after>'''
File: updateHosts.py
Author: <EMAIL>
Version: 0.0.1
Date: 2012-10-24 14:35:39
'''

import urllib
import os

def GetRemoteHosts(hostsUrl):
    fp = urllib.urlopen(hostsUrl)
    hosts = [line for line in fp]
    fp.close()
    return hosts

if __name__ == "__main__":
    hosts = GetRemoteHosts("http://tx.txthinking.com/hosts")
    hostsPath = "/etc/hosts"

    search = "#TX-HOSTS\n"
    yourHosts = ""
    fp = open(hostsPath, "r")
    while 1:
        line = fp.readline()
        if line == search or line == "":
            break
        yourHosts += line
    yourHosts += search
    fp.close()

    os.rename(hostsPath, hostsPath + ".BAK")

    fp = open(hostsPath, "w")
    fp.write(yourHosts)
    fp.writelines(hosts) #iterable sequence hosts
    fp.close()

    print "Success"

{'fraction_non_alphanumeric': 0.14138349514563106, 'fraction_numerical': 0.021844660194174758, 'mean_word_length': 2.624175824175824, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 5, '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': '7449931', 'n_tokens_mistral': 630, 'n_tokens_neox': 583, 'n_words': 142}