def post_reply(index):
    directory = "data/posts/posts.csv"
    reply = request.form["reply"]
    #post_dic = reader.make_postdic("data/posts/posts.csv")
    text = reader.read_file(directory)


    i = 1
    count = 0
    
    while ((count <= int(index)) and (i < len(text))):
        if reader.string_at(i,"\\<end>\n",text):
            count+=1
            
        i+=1
    #if count != 0:
    #    print "WAHT THAS IASJDSOJHAMNIK"
    #    i-=1



    i -= 1 #8 is the length of string "/<end>\n"
    text = text[:i] + reply + "{,}" + session["username"] + "{{,}}" + text[i:]
    reader.replace_file(directory,text)
    return redirect("/post")
def account_change_profile_img():
    directory = "data/users/user_auth.csv"
    url = request.form["image"]
    text = reader.read_file(directory)
    index = text[( text.find(session['username']) ):].find("\n")
    print "TEXT AFTER USERNAME: "******"TEXT UNTIL NEWLINE: " + str(text[( text.find(session['username']) ):index]) #works
    i = 0
    while(text[index - i] != ","): #From the end of the user line, it goes down until it finds a comma.
        i+=1
    print "TEXT OF IMAGE: " + str(text[index-i:index])
    text = text[:(index-i)] + "," + url + text[(index):]
    reader.replace_file(directory,text)
    return redirect("/")