Beispiel #1
0
 def move_to_archive(UserID, topic):
     file_to_search = str(topic) + ".txt"  #BASE DEFINITIONS
     common_obj = common()
     info = common.get_info(common_obj)
     info_dict = literal_eval(info)
     base_path = info_dict["base_path"]  #GETTING BASE PATH FROM config.txt
     DBconfig = info_dict[
         "DBconfig"]  #GETTING INFO TO CONFIGURE DB CONNECTION
     UIDs = common.getusers(common_obj, DBconfig, base_path)
     if UserID not in UIDs:
         return "404: ID not found", 404
     Notes = common.getnotes(common_obj, DBconfig, base_path, UserID)
     if file_to_search in Notes:
         new_entry_obj = New_Entry()
         New_Entry.delete_note_in_db(new_entry_obj, UserID,
                                     str(topic + ".txt"))
         New_Entry.new_archive_in_db(new_entry_obj, UserID,
                                     str(topic + ".txt"),
                                     str(datetime.datetime.now()))
         New_Entry.close_connections(new_entry_obj)
         src = base_path + "Storage/" + UserID + "_notes/" + file_to_search
         dst = base_path + "Storage/" + UserID + "_notes/Archives/" + file_to_search
         shutil.move(src, dst)  #MOVE TEXT FILE INTO ARCHIVE FOLDER
         with open(dst, 'rb') as f_in, gzip.open(dst + '.gz',
                                                 'wb') as f_out:
             shutil.copyfileobj(f_in, f_out)  #COMPRESS TO .gz
         os.remove((base_path + "Storage/" + UserID + "_notes/Archives/" +
                    file_to_search))
         return "200: archiving successful", 200
     else:
         return "404: file not found", 404
Beispiel #2
0
    def post(UserID):
        note = request.json["content"]
        topic = request.json["topic"] #RECEIVE DATA AS JSON

        common_obj = common()
        info = common.get_info(common_obj)
        info_dict = literal_eval(info) #CONVERT TO DICTIONARY
        base_path = info_dict["base_path"]  #GETTING BASE PATH FROM config.txt
        DBconfig = info_dict["DBconfig"] #GETTING INFO TO CONFIGURE DB CONNECTION
        UIDs = common.getusers(common_obj, DBconfig, base_path)
        if UserID not in UIDs:
            return "404: ID not found", 404

        Notes = common.getnotes(common_obj, DBconfig, base_path, UserID)
        if str(topic + ".txt") in Notes:
            return "404: Note already exists - to edit/delete please use the rewrite/delete functionality.", 404
        Archives = common.getarchives(common_obj, DBconfig, base_path, UserID)
        if str(topic + ".txt") in Archives:
            return "404: Note with same filename exists in archives. Recommended: add \'(n)\' after filename where n is version number.", 404
        new_entry_obj = New_Entry()
        New_Entry.new_note_in_db(new_entry_obj, UserID, str(topic + ".txt"), str(datetime.datetime.now()))
        New_Entry.close_connections(new_entry_obj)

        f = open((base_path + "Storage/" + UserID + "_notes/" + topic + ".txt"), "w") #NEW NOTE FILE
        f.write(note)
        f.close()

        return "201 : posting successful", 201
Beispiel #3
0
    def prepend(UserID):
        addition = request.json["content"]
        topic = request.json["topic"]

        index = 0
        file_found = False
        file_to_search = str(topic) + ".txt"
        common_obj = common()
        info = common.get_info(common_obj)
        info_dict = literal_eval(info)  #CONVERT TO DICTIONARY
        base_path = info_dict[
            "base_path"]  #GATHERING BASE PATH FROM config.txt
        DBconfig = info_dict[
            "DBconfig"]  #GETTING INFO TO CONFIGURE DB CONNECTION
        UIDs = common.getusers(common_obj, DBconfig, base_path)
        if UserID not in UIDs:
            return "404: ID not found", 404
        Notes = common.getnotes(common_obj, DBconfig, base_path, UserID)
        if file_to_search in Notes:
            f = open(
                (base_path + "Storage/" + UserID + "_notes/" + file_to_search),
                "r+")
            old = f.read()
            f.seek(0)
            f.write(addition + " " + old)
            f.close()
            return "201: file updated", 201
        else:
            return "404: file not found", 404
Beispiel #4
0
 def delete_note(UserID, topic):
     file_to_search = str(topic) + ".txt"
     common_obj = common()
     info = common.get_info(common_obj)
     info_dict = literal_eval(info)  #CONVERT TO DICTIONARY
     base_path = info_dict[
         "base_path"]  #GATHERING BASE PATH FROM config.txt
     DBconfig = info_dict["DBconfig"]
     UIDs = common.getusers(common_obj, DBconfig, base_path)
     if UserID not in UIDs:
         return "404: ID not found", 404
     Notes = common.getnotes(common_obj, DBconfig, base_path, UserID)
     if file_to_search in Notes:
         new_entry_obj = New_Entry()
         New_Entry.delete_note_in_db(new_entry_obj, UserID,
                                     file_to_search)  #EXECUTING SQL
         New_Entry.close_connections(new_entry_obj)
         os.remove(
             (base_path + "Storage/" + UserID + "_notes/" + file_to_search))
         return "200 : Operation successful", 200
     else:
         return "404 : file could not be found", 404