예제 #1
0
 def _writeEntry(self, callb):
     if self.stopQuery:
         return
     logCount = self.query.getProgress()[1]
     i = 0
     for result in self.query:
         if i >= MAX_LOG_COUNT:
             self.write("[ERROR]log太多,本次获取只显示前面%d条,后面%d条忽略\n"%(MAX_LOG_COUNT, logCount - MAX_LOG_COUNT))
             break
         self.write( result.format( self.showCols ) )
         i += 1
     self.query.resume()
     utils.callback(INTERVAL, callb)
예제 #2
0
    def GET(self,page_name,id):
        access = utils.page_access(page_name,utils.PERM_WRITE)
        if access is not None:  return access

        try:
            content = utils.fetch_file(page_name)
            try:
                obj = json.loads(content) 
                if obj["components"].has_key(id):
                    type = obj["components"][id]["type"]
                    del obj["components"][id]

                    ## Remove from order
                    current_order = obj['order'].split(',')
                    x = 0
                    for i in current_order:
                        if int(i) == int(id):
                            del current_order[x]
                        x = x + 1

                    current_order = ",".join(current_order)
                    obj['order'] = current_order

                    try:
                        utils.save_file(page_name,json.dumps(obj))

                        return utils.callback('{"id":"' + id + '", "type":"' + type +'"}')
                    except IOError:
                        utils.handle_error("failed to save file")
                else:
                    utils.handle_error("key not found")
            except:
                utils.handle_error("failed to read file")
        except IOError:
            utils.handle_error("file not found")
예제 #3
0
    def GET(self,page_name,id):

        access = utils.page_access(page_name,utils.PERM_WRITE)
        if access is not None:  return access

        data = web.input(title="",description="")
        try:
            content = utils.fetch_file(page_name)
            try:
                obj = json.loads(content) 
                if obj["components"].has_key(id):
                    obj["components"][id]["title"] = data.title;
                    if ( obj["components"][id]["type"] == "note"):
                        obj["components"][id]["description"] = data.description
                    try:
                        utils.save_file(page_name,json.dumps(obj))
                        if obj["components"][id]["type"] == "note":
                            obj["components"][id]["description"] = textile.textile(obj["components"][id]["description"])
                        obj["components"][id]["id"] = id
                        return utils.callback(json.dumps(obj["components"][id]))
                    except IOError:
                        utils.handle_error("failed to save file")
            except:
                utils.handle_error("failed to read file")
        except IOError:
            utils.handle_error("file not found")
예제 #4
0
def objective(params):

    for x in params.keys():
        if params[x] == 0:
            params[x] = 1
        elif x == 'choice':
            for y in params[x].keys():
                if params[x][y] == 0:
                    params[x][y] = 1

    K.clear_session()

    print('Params testing: ', params)
    print('\n ')

    layersAndNodes = [x / 100 for x in list(params['choice'].values())
                      ]  # len is number of layers

    input = Input(shape=(784, ))
    next_layer = 784
    prev_layer = input

    output_layers = []

    for x in layersAndNodes:
        next_layer = int(np.ceil(x * next_layer))
        output_layers.append(next_layer)
        enc = Dense(next_layer, activation='relu')(prev_layer)
        prev_layer = enc

    output_layers.reverse()
    for x in output_layers[1:]:
        dec = Dense(x, activation='relu')(prev_layer)
        prev_layer = dec

    dec2 = Dense(784, activation='sigmoid')(prev_layer)
    model = Model(input, dec2)

    model.compile(loss='mean_squared_error', optimizer='adadelta')
    model.fit(x_train,
              x_train,
              epochs=100,
              batch_size=int(params['batch_size']),
              shuffle=True,
              validation_data=(x_val, x_val),
              callbacks=utils.callback(script_name))

    preds = model.predict(x_test)
    loss = tf.keras.backend.sum(
        mean_squared_error(tf.convert_to_tensor(x_test),
                           tf.convert_to_tensor(preds)))
    sess = tf.Session()
    score = round(sess.run(loss) / len(x_test), 4)

    print('Params tested: ', params)
    print('\n ')
    print(model.summary())
    return {'loss': score, 'status': STATUS_OK}
예제 #5
0
    def GET(self,page_name):
    
        data = web.input(email=None, status="public")

        access = utils.page_access(page_name)
        if access is not None:  return access

        db = pytc.HDB()
        db.open(utils.DBNAME, pytc.HDBOWRITER | pytc.HDBOCREAT)

        if data.email is not None:
            email = ""
        else:
            if data.status == "public":
                db.put(page_name + ":public","1")
                return utils.callback('{ "status":"public"}')
            else:
                if db.has_key(page_name + ":public"):
                    db.out(page_name + ":public")
                return utils.callback('{ "status":"private"}')
예제 #6
0
    def _setup_bindings(self):
        text = self.text

        def bind_them(to_bind, prefix='_%s'):
            for tb in to_bind:
                prefix_size = tb.count('<')
                method_name = tb[prefix_size:-prefix_size].replace('-', '_')
                text.bind(tb, getattr(self, prefix % method_name.lower()))

        actions = ('<<help>>', '<<python-docs>>', '<<about-idle>>',
                   '<<open-config-dialog>>', '<<open-module>>', '<<cut>>',
                   '<<copy>>', '<<paste>>', '<<select-all>>',
                   '<<remove-selection>>', '<<del-word-left>>',
                   '<<del-word-right>>', '<<beginning-of-line>>')
        events = ('<<find>>', '<<center-insert>>', '<<find-again>>',
                  '<<find-in-files>>', '<<find-selection>>', '<<replace>>',
                  '<<goto-line>>', '<<smart-backspace>>', '<<smart-indent>>',
                  '<<indent-region>>', '<<dedent-region>>',
                  '<<comment-region>>', '<<tabify-region>>',
                  '<<untabify-region>>', '<<toggle-tabs>>',
                  '<<change-indentwidth>>')
        parent_actions = ('<<new-tab>>', '<<next-tab>>', '<<prev-tab>>')

        bind_them(actions)
        bind_them(events, prefix="_%s_event")
        for action in parent_actions:
            prefix_size = action.count('<')
            method_name = action[prefix_size:-prefix_size].replace('-', '_')
            text.bind(action, getattr(self.editwin, method_name))

        text.bind('<<close-tab>>', self.close_tab)
        text.bind('<<newline-and-indent>>', self.newline_and_indent_event)
        text.bind("<<do-nothing>>", lambda event: "break")
        text.bind("<Left>", self._move_at_edge_if_selection(0))
        text.bind("<Right>", self._move_at_edge_if_selection(1))
        text.bind("<3>", self._right_menu)
        text.bind('<<set-line-and-column>>', self.editwin.set_line_and_column)
        text.event_add("<<set-line-and-column>>", "<KeyRelease>",
                       "<ButtonRelease>")

        if self.editwin.flist:
            text.bind("<<open-new-window>>",
                      utils.callback(self.editwin.new_callback, self))
            text.bind("<<close-all-windows>>",
                      self.editwin.flist.close_all_callback)
            text.bind("<<open-class-browser>>", self._open_class_browser)
            text.bind("<<open-path-browser>>", self._open_path_browser)

        if macosxSupport.runningAsOSXApp():
            # Command-W on editorwindows doesn't work without this.
            text.bind('<<close-window>>', self.editwin.close_event)
예제 #7
0
    def GET(self,page_name,component):
        access = utils.page_access(page_name)
        if access is not None:  return access

        try:
            content = utils.fetch_file(page_name)
            ## We have to textile some fields
            try:
                obj = json.loads(content)
                return utils.callback(json.dumps(obj["components"][component]))
            except:
                utils.handle_error("failed to read file")
        except IOError:
            utils.handle_error("file not found")
예제 #8
0
    def __init__(self, name, hooks=[]):
        """init"""
        self.name = name
        self.hooks = hooks
        self.sensors_cache = {}

        self.time_elapsed = 0
        self.start = 0

        rospy.init_node('basic_thymio_controller', anonymous=True)

        print(self.name)
        # Publish to the topic '/thymioX/cmd_vel'.
        self.velocity_publisher = rospy.Publisher(self.name + '/cmd_vel',
                                                  Twist,
                                                  queue_size=10)

        # A subscriber to the topic '/turtle1/pose'. self.update_pose is called
        # when a message of type Pose is received.
        self.pose_subscriber = rospy.Subscriber(self.name + '/odom', Odometry,
                                                self.update_state)
        self.sensors_names = [
            'right', 'center_right', 'center', 'center_left', 'left',
            'rear_right', 'rear_left'
        ]

        self.sensors_subscribers = [
            rospy.Subscriber(self.name + '/proximity/' + sensor_name, Range,
                             callback(self.sensors_callback, i, sensor_name))
            for i, sensor_name in enumerate(self.sensors_names)
        ]

        # self.camera_subscriber = rospy.Subscriber(self.name + '/camera/image_raw', Image, self.camera_callback, queue_size=1, buff_size=2**30)
        self.camera_subscriber = rospy.Subscriber(
            self.name + '/camera/image_raw/compressed',
            CompressedImage,
            self.camera_callback_compressed,
            queue_size=1,
            buff_size=2**24)

        self.led_subscriber = rospy.Publisher(self.name + '/led',
                                              Led,
                                              queue_size=10)

        self.current_pose = Pose()
        self.current_twist = Twist()
        # publish at this rate
        self.rate = rospy.Rate(10)
        self.vel_msg = Twist()
예제 #9
0
    def _setup_bindings(self):
        text = self.text
        def bind_them(to_bind, prefix='_%s'):
            for tb in to_bind:
                prefix_size = tb.count('<')
                method_name = tb[prefix_size:-prefix_size].replace('-', '_')
                text.bind(tb, getattr(self, prefix % method_name.lower()))
            
        actions = ('<<help>>', '<<python-docs>>',
            '<<about-idle>>', '<<open-config-dialog>>', '<<open-module>>',
            '<<cut>>', '<<copy>>', '<<paste>>', '<<select-all>>',
            '<<remove-selection>>', '<<del-word-left>>', '<<del-word-right>>',
            '<<beginning-of-line>>')
        events = ('<<find>>', '<<center-insert>>', '<<find-again>>',
            '<<find-in-files>>', '<<find-selection>>', '<<replace>>',
            '<<goto-line>>', '<<smart-backspace>>', '<<smart-indent>>',
            '<<indent-region>>', '<<dedent-region>>', '<<comment-region>>',
            '<<tabify-region>>', '<<untabify-region>>', '<<toggle-tabs>>',
            '<<change-indentwidth>>')
        parent_actions = ('<<new-tab>>', '<<next-tab>>', '<<prev-tab>>')

        bind_them(actions)
        bind_them(events, prefix="_%s_event")
        for action in parent_actions:
            prefix_size = action.count('<')
            method_name = action[prefix_size:-prefix_size].replace('-', '_')
            text.bind(action, getattr(self.editwin, method_name))

        text.bind('<<close-tab>>', self.close_tab)
        text.bind('<<newline-and-indent>>', self.newline_and_indent_event)
        text.bind("<<do-nothing>>", lambda event: "break")
        text.bind("<Left>", self._move_at_edge_if_selection(0))
        text.bind("<Right>", self._move_at_edge_if_selection(1))
        text.bind("<3>", self._right_menu)
        text.bind('<<set-line-and-column>>', self.editwin.set_line_and_column)
        text.event_add("<<set-line-and-column>>",
                                    "<KeyRelease>", "<ButtonRelease>")

        if self.editwin.flist:
            text.bind("<<open-new-window>>",
                utils.callback(self.editwin.new_callback, self))
            text.bind("<<close-all-windows>>",
                self.editwin.flist.close_all_callback)
            text.bind("<<open-class-browser>>", self._open_class_browser)
            text.bind("<<open-path-browser>>", self._open_path_browser)

        if macosxSupport.runningAsOSXApp():
            # Command-W on editorwindows doesn't work without this.
            text.bind('<<close-window>>', self.editwin.close_event)
예제 #10
0
파일: pockint.py 프로젝트: wankyou/pockint
    def build(self):
        """Initializes and builds application widgets."""
        text_credits = 'POCKINT\nversion {ver}\n copyright © {year}' \
                       ''.format(year=datetime.datetime.now().year,
                                      ver=__version__)
        author_info = "Written with ♥ by\nNetEvert"

        # create main credits label
        self.lbl_info = tk.Label(self, text=text_credits,
                                 font=('courier', 10, 'normal'))
        self.lbl_author = tk.Label(self, text=author_info,
                                 font=('courier', 10, 'normal'), cursor="hand2")

        self.lbl_info.grid(row=0, column=0, sticky='w', padx=1, pady=1)
        self.lbl_author.grid(row=1, column=0, sticky='w', padx=1, pady=1)
        self.lbl_author.bind("<Button-1>", lambda e: callback("https://twitter.com/netevert"))
예제 #11
0
def objective(params):

    for x in params.keys():
        if params[x] == 0:
            params[x] = 1

    K.clear_session()

    print('Params testing: ', params)
    print('\n ')

    layer1 = int(np.ceil(params['units1'] / 100 * 784))
    layer2 = int(np.ceil(params['units2'] / 100 * layer1))
    layer3 = int(np.ceil(params['units3'] / 100 * layer2))

    input = Input(shape=(784, ))
    enc = Dense(layer1, activation='relu')(input)
    enc2 = Dense(layer2, activation='relu')(enc)
    enc3 = Dense(layer3, activation='relu')(enc2)
    dec0 = Dense(layer2, activation='relu')(enc3)
    dec1 = Dense(layer1, activation='relu')(dec0)
    dec2 = Dense(784, activation='sigmoid')(dec1)
    model = Model(input, dec2)

    model.compile(loss='mean_squared_error', optimizer='adadelta')
    model.fit(x_train,
              x_train,
              epochs=100,
              batch_size=int(params['batch_size']),
              shuffle=True,
              validation_data=(x_val, x_val),
              callbacks=utils.callback(script_name))

    preds = model.predict(x_test)
    loss = tf.keras.backend.sum(
        mean_squared_error(tf.convert_to_tensor(x_test),
                           tf.convert_to_tensor(preds)))
    sess = tf.Session()
    score = round(sess.run(loss) / len(x_test), 4)

    print('Params tested: ', params)
    print('\n ')
    print(model.summary())
    return {'loss': score, 'status': STATUS_OK}
예제 #12
0
    def GET(self,page_name):
        access = utils.page_access(page_name,utils.PERM_WRITE)
        if access is not None:  return access

        data = web.input(order="")
        try:
            content = utils.fetch_file(page_name)
            try:
                obj = json.loads(content) 
                obj["order"] = data.order
                try:
                    utils.save_file(page_name,json.dumps(obj))
                    return utils.callback('{"success":"1"}')
                except IOError:
                    utils.handle_error("failed to save file")
            except:
                utils.handle_error("failed to read file")
        except IOError:
            utils.handle_error("file not found")
예제 #13
0
    def GET(self,page_name):
        
        access = utils.page_access(page_name)
        if access is not None:  return access

        content = utils.fetch_file(page_name)
        ## We have to textile some fields
        try:
            obj = json.loads(content)
            for component in obj["components"]:
                if obj["components"][component]["type"] == "note":
                    obj["components"][component]["description"] = textile.textile(obj["components"][component]["description"])
                elif obj["components"][component]["type"] == "list":
                    if obj["components"][component].has_key("completed"):
                        for c in obj["components"][component]["completed"]:
                            date = datetime.fromtimestamp(obj["components"][component]["completed"][c]["completed"])
                            obj["components"][component]["completed"][c]["completed"] = date.strftime("%b %d")

            return utils.callback(json.dumps(obj))
        except:
            utils.handle_error("failed to read file")
예제 #14
0
    def GET(self,page_name):
        access = utils.page_access(page_name,utils.PERM_WRITE)
        if access is not None:  return access

        data = web.input(new_name="")
        ## Fix name
        try:
            content = utils.fetch_file(page_name)
            try:
                obj = json.loads(content)
                obj["name"] = data.new_name
                try:
                    utils.save_file(page_name,json.dumps(obj))
                    new_name = { 'name' : data.new_name }
                    return utils.callback(json.dumps(new_name))
                except IOError:
                    utils.handle_error("failed to save file")
            except:
                utils.handle_error("failed to read file")
        except IOError:
            utils.handle_error("file not found")
예제 #15
0
    def GET(self,page_name,id,list_item_id):
        access = utils.page_access(page_name,utils.PERM_WRITE)
        if access is not None:  return access

        try:
            content = utils.fetch_file(page_name)
            try:
                obj = json.loads(content)
                component = obj["components"][id]
                ## Check items first
                if component["items"].has_key(list_item_id):
                    del component["items"][list_item_id]
                    ## Remove from order
                    if component['order'] != "":
                        current_order = component['order'].split(',')
                    else:
                        current_order = []

                    x = 0
                    for i in current_order:
                        if int(i) == int(list_item_id):
                            del current_order[x]
                        x = x + 1
                    current_order = ",".join(current_order)
                    component['order'] = current_order
                else:
                    ## In the completed section
                    del component["completed"][list_item_id]
                    ## We don't need to remove from order since it's in completed

                try:
                    utils.save_file(page_name,json.dumps(obj))
                    return utils.callback('{"id":"' + id + '", "list_item_id":"' + list_item_id +'"}')

                except IOError:
                    utils.handle_error("failed to save file")
            except:
                utils.handle_error("failed to read file")
        except IOError:
            utils.handle_error("file not found")
예제 #16
0
파일: train.py 프로젝트: svirmi/prod2vec
def main(n_epochs: int, min_count: int):
    paths = ['cart_df.pkl', 'view_df.pkl']  #, 'combined_sessions.pkl']
    model_names = ['cart', 'view']  #, 'combined']
    for model_name, path in zip(model_names, paths):
        data = load_data(path)

        max_len = max(len(x) for x in data)
        if model_name == 'cart':
            model = init_model(max_len, min_count // 2)
        else:
            model = init_model(max_len, min_count)
        #train model
        model.build_vocab(data, progress_per=200)
        model.train(data,
                    total_examples=model.corpus_count,
                    epochs=n_epochs,
                    report_delay=1,
                    compute_loss=True,
                    callbacks=[callback()])

        model.save(f"weights/{model_name}.model")
    print("Done")
예제 #17
0
    def GET(self,page_name,id):
        access = utils.page_access(page_name,utils.PERM_WRITE)
        if access is not None:  return access

        try:
            content = utils.fetch_file(page_name)
            try:
                obj = json.loads(content)
                if obj["components"][id].has_key("completed"):
                    del obj["components"][id]["completed"]
                else:
                    return "{'error': 'no completed items'}"

                try:
                    utils.save_file(page_name,json.dumps(obj))
                    return utils.callback("{'id': " + id + " }")
                except IOError:
                    utils.handle_error("failed to save file")
            except:
                utils.handle_error("failed to read file")
        except IOError:
            utils.handle_error("file not found")
예제 #18
0
    def GET(self,page_name,id,list_id):
        access = utils.page_access(page_name,utils.PERM_WRITE)
        if access is not None:  return access

        data = web.input(title="")
        try:
            content = utils.fetch_file(page_name)
            try:
                obj = json.loads(content)
                obj["components"][id]["items"][list_id]["title"] = data.title

                try:
                    utils.save_file(page_name,json.dumps(obj))

                    component = obj["components"][id]["items"][list_id]
                    component["id"] = id;
                    component["list_item_id"] = list_id
                    return utils.callback(json.dumps(component))
                except IOError:
                    utils.handle_error("failed to save file")
            except:
                utils.handle_error("failed to read file")
        except IOError:
            utils.handle_error("file not found")
예제 #19
0
파일: echo.py 프로젝트: ginew2000/cmserver
 def startWriteMonitor(self):
     if not self.clientInfo.handler:
         return
     for data in self.getOutput():
         self.write(data)
     utils.callback(0.5, self.startWriteMonitor)
예제 #20
0
input = Input(shape=(784, ))

enc = Dense(layer1, activation='relu')(input)
dec = Dense(784, activation='sigmoid')(enc)
model = Model(input, dec)

encoder = Model(input, enc)

model.compile(loss='mean_squared_error', optimizer='adadelta')
model.fit(x_train,
          x_train,
          epochs=100,
          batch_size=batch_size,
          shuffle=True,
          validation_data=(x_val, x_val),
          callbacks=utils.callback(script_name))

preds = model.predict(x_test)
loss = tf.keras.backend.sum(
    mean_squared_error(tf.convert_to_tensor(x_test),
                       tf.convert_to_tensor(preds)))
sess = tf.Session()
loss = sess.run(loss)
score = round(loss / (len(x_test)), 4)
print("Prediction Score :" + str(score))
print(model.summary())

result = model.predict(x_test)

print('done')
예제 #21
0
 def sendKeepAliveToClient(self):
     if getattr(self, "stopQuery", False):
         return
     self.write("<!--  keep alive -->\n")
     utils.callback(30, self.sendKeepAliveToClient)
예제 #22
0
    def GET(self,page_name,id,list_item_id):
        access = utils.page_access(page_name,utils.PERM_WRITE)
        if access is not None:  return access

        data = web.input(status="")
        try:
            content = utils.fetch_file(page_name)
            try:
                obj = json.loads(content)
                if data.status == "completed":
                    item = obj["components"][id]["items"][list_item_id]
                    # remove the item from items and put in completed

                    if obj["components"][id].has_key("order"):
                        current_order = obj["components"][id]['order'].split(',')
                    else:
                        current_order = ""

                    # remove from the order
                    x = 0
                    for i in current_order:
                        if int(i) == int(list_item_id):
                            del current_order[x]
                        x = x + 1

                    current_order = ",".join(current_order)
                    obj["components"][id]['order'] = current_order
                    item["completed"] = time.time()
                    if obj["components"][id].has_key("completed"): 
                        obj["components"][id]["completed"][list_item_id] = item
                    else:
                        obj["components"][id]["completed"] = {}
                        obj["components"][id]["completed"][list_item_id] = item
                    del  obj["components"][id]["items"][list_item_id]
                else:
                    item = obj["components"][id]["completed"][list_item_id]
                    del item["completed"] 
                    
                    current_order = obj["components"][id]['order'].split(',')
                    current_order.append(list_item_id)
                    current_order = ",".join(current_order)
                    ## How does this happen, an extra comma?
                    current_order = current_order.strip(",")        
 
                    obj["components"][id]['order'] = current_order

                    obj["components"][id]["items"][list_item_id] = item
                    del  obj["components"][id]["completed"][list_item_id]

                try:
                    utils.save_file(page_name,json.dumps(obj))
                    item["id"] = id
                    item["list_item_id"] = list_item_id
                    item["status"] = data.status
                    if item.has_key("completed"):
                        date = datetime.fromtimestamp(item["completed"])
                        item["completed"] = date.strftime("%b %d")
                    return utils.callback(json.dumps(item))
                except IOError:
                    utils.handle_error("failed to save file")
            except:
                utils.handle_error("failed to read file")
        except IOError:
            utils.handle_error("file not found")
예제 #23
0
    def GET(self,page_name):
        access = utils.page_access(page_name,utils.PERM_WRITE)
        if access is not None:  return access

        data = web.input(title="",description="",type="",list_id="",after=0)
        try:
            content = utils.fetch_file(page_name)
            try:
                obj = json.loads(content)

                ## list
                if (data.type == "list"):
                    component = {}
                    ## Move the last id pointer one
                    last_id = obj["last_id"]
                    last_id = last_id + 1
                    obj["last_id"] = last_id

                    component["type"] = "list"
                    component["title"] = data.title;

                    ## Add to order
                    current_order = obj["order"]
                    if current_order != "":
                        current_order = obj['order'].split(',')
                        new_order = []
                        ## Put it after
                        if (int(data.after) == 0):
                            new_order.append(str(last_id))

                        for o in current_order:
                            if (int(o) == int(data.after)):
                                new_order.append(o)
                                new_order.append(str(last_id))
                            else:
                                new_order.append(o)
                    else:
                        new_order = [str(last_id)]

                    obj["components"][str(last_id)] = component
                    obj["order"] = ",".join(new_order)

                    ## Save
                    try:
                        utils.save_file(page_name,json.dumps(obj))
                        component["id"] = last_id
                        return utils.callback(json.dumps(component))
                    except IOError:
                         utils.handle_error("failed to save file")

                ## Divider
                elif (data.type == "divider"):
                    component = {}
                    ## Move the last id pointer one
                    last_id = obj["last_id"]
                    last_id = last_id + 1
                    obj["last_id"] = last_id

                    component["type"] = "divider"
                    component["title"] = data.title;

                    ## Add to order
                    current_order = obj["order"]
                    if current_order != "":
                        current_order = obj['order'].split(',')
                        new_order = []
                        ## Put it after
                        if (int(data.after) == 0):
                            new_order.append(str(last_id))

                        for o in current_order:
                            if (int(o) == int(data.after)):
                                new_order.append(o)
                                new_order.append(str(last_id))
                            else:
                                new_order.append(o)
                    else:
                        new_order = [str(last_id)]

                    obj["components"][str(last_id)] = component
                    obj["order"] = ",".join(new_order)

                    ## Save
                    try:
                        utils.save_file(page_name,json.dumps(obj))
                        component["id"] = last_id
                        return utils.callback(json.dumps(component))
                    except IOError:
                         utils.handle_error("failed to save file")
    
                ## Note
                elif (data.type == "note"):
                    component = {}
                    ## Move the last id pointer one
                    last_id = obj["last_id"]
                    last_id = last_id + 1
                    obj["last_id"] = last_id

                    component["type"] = "note"
                    component["title"] = data.title;
                    component["description"] = data.description 
                    
                    ## Add to order
                    current_order = obj["order"]
                    if current_order != "":
                        current_order = obj['order'].split(',')
                        new_order = []
                        if (int(data.after) == 0):
                            new_order.append(str(last_id))
                        ## Put it after
                        for o in current_order:
                            if (int(o) == int(data.after)):
                                new_order.append(o)
                                new_order.append(str(last_id))
                            else:
                                new_order.append(o)
                    else:
                        new_order = [str(last_id)]

                    obj["components"][str(last_id)] = component
                    obj["order"] = ",".join(new_order)

                    ## Save
                    try:
                        utils.save_file(page_name,json.dumps(obj))
                        component["id"] = last_id
                        component["description"] = textile.textile(component["description"])
                        return utils.callback(json.dumps(component))
                    except IOError:
                         utils.handle_error("failed to save file")

                elif (data.type == "list_item"):
                    component  = obj["components"][data.list_id]

                    # Fine the list and find the next id in the order
                    if component.has_key("order"):
                        current_order = component["order"]
                    else:
                        current_order = ""

                    if component.has_key("last_id"):
                        last_id = int(component["last_id"])
                    else:
                        last_id = 0

                    if current_order != "":
                        current_order = component['order'].split(',')
                    else:
                        current_order = []

                    last_id = int(last_id) + 1
                    component["last_id"] = last_id
                    if component.has_key("items"):
                        component["items"][last_id] = {"title" : data.title}
                    else:
                        component["items"] = {}
                        component["items"][last_id] = {"title" : data.title}

                    current_order.append(str(last_id))
                    component["order"] = ",".join(current_order)

                    ## Save
                    try:
                        utils.save_file(page_name,json.dumps(obj))
                        component["items"][last_id]["order"] = ",".join(current_order)
                        component["items"][last_id]["id"] = data.list_id
                        component["items"][last_id]["item_id"] = last_id
                        return utils.callback(json.dumps(component["items"][last_id]))
                    except IOError:
                        utils.handle_error("failed to save file")
            except:
                utils.handle_error("failed to read file")
        except IOError:
            utils.handle_error("file not found")