Ejemplo n.º 1
0
def haslinkrel(htmlfile):
    p = "<link rel=stylesheet href="
    filedata = list("".join(u.readfile(htmlfile)).partition(p))
    if filedata[1] == "":
        return False
    else:
        return True
def loadtables():
    a = u.readfile("/home/umar/yqltables")
    curls = [eval(x.replace("\n","")).items()
             for x in a if x.startswith("{") == True]
    strings = [x.replace("\n","")
               for x in a if x.startswith("{") != True]
    return [curls,strings]
def quotesfile(qf):
    a = "".join(u.readfile(qf)[:-1]).split("\n\n")
    b = [x.split("\n") for x in a]
    for x in b:
        x.insert(-1,"--")
    c = ["".join(x) for x in b]
    return c
def matchprojections(data,randomprojections,digitizations,
                     directory):
    labels = []
    for x in randomprojectiondigitizehash(data,
                                          randomprojections,
                                          digitizations):
        labels.append(u.readfile(directory+str(hash(x))))
    return labels
Ejemplo n.º 5
0
def changelinkrel(htmlfile, cssfile):
    p = "<link rel=stylesheet href="
    original = list("".join(u.readfile(htmlfile)).partition(p))
    original.remove(p)
    firstpart = original[0]
    secondpart = list(original[1].partition(' type="text/css">'))[2:]
    final = "".join([firstpart, linkrel(cssfile), secondpart[0]])
    u.writefile("".join(final), htmlfile)
    print htmlfile + " written"
def googlevideosearches():
    f = "".join(u.readfile("/home/umar/googlevideosearch"))
    parts = f.partition("\n\n") 
    sites = [x.split(",") for x in parts[0].split("\n")]
    searches = [x.split(",") for x in parts[2].split("\n")][:-1]
    for x in searches:
        for y in sites:
            if x[1] == y[1]:
                x[1] = y[0]
    a = [[[x[0],x[1]],x[2:]] for x in searches]
    return h.tabularize([
        h.newtabopen("".join(["http://www.google.com/search?q=",
                              "&".join([googlesitesearchvideo(x[0]),
                                        "tbm=vid",
                                        "tbs="+",".join([
        googlevideosearchattribute(y)
        for y in x[1]]),
                                        ])]),x[0][0])
        for x in a],2)
def urlfiles():
    files =  [imagenetdir+x for x in os.listdir(imagenetdir)
            if x.endswith(".urls") == True]
    return [[x,len(u.readfile(x))] for x in files]
Ejemplo n.º 8
0
def writelinkrel(htmlfile, cssfile):
    original = list("".join(u.readfile(htmlfile)).partition("<head>"))
    original.insert(2, linkrel(cssfile))
    u.writefile("".join(original), htmlfile)
    print htmlfile + " written"
def reddits():
    return [[y[0],"".join(y[1:]).split(",")] for y in
            [x.split("\n") for x in
             "".join(u.readfile("/home/umar/reddits")).split("\n\n")]]