def command_serve(self, options, args):
     '''Starts a local server'''
 
     static_app = DirectoryApp("static", index_page=None)
     
     # Create a cascade that looks for static files first, 
     #  then tries the other apps
     cascade_app = ExceptionMiddleware(cascade.Cascade([static_app, fever.setup_app(), frontend.setup_app()]))
     
     address = '0.0.0.0' if options.allow_remote_access else 'localhost'        
     httpd = make_server(address, options.port, cascade_app)
     print 'Serving on http://%s:%s' % (address, options.port)
     try:
         httpd.serve_forever()
     except KeyboardInterrupt:
         print 'Interrupted by user'            
Beispiel #2
0
def setup_app():
    # Postpone import to avoid circular dependencies
    import fever, frontend, cascade
    return ExceptionMiddleware(
        cascade.Cascade([fever.setup_app(),
                         frontend.setup_app()]))
Beispiel #3
0
def load_cascades(filename,
                  users,
                  type='tree',
                  count=200000,
                  threshold=10000000,
                  DEBUG=False):
    cascades = []
    file = open(filename)
    read, total, line_num, cascade_num = 0, 0, 0, 0
    while True:
        if read == 1:
            line = forward_line
            read = 0
        else:
            line = file.readline()
            line_num += 1
        if line.startswith(codecs.BOM_UTF8):
            line = line[3:]
        if line == "" or len(cascades) >= count:
            break

        values = line.strip('\n').split('\t')
        mid = values[0]
        try:
            url = values[1]
            user = users[url]
        except:
            continue
        root = cs.User(user.name,
                       gender=user.gender,
                       loc=user.loc,
                       weibo_num=user.weibo_num,
                       following_num=user.following_num,
                       follower_num=user.follower_num,
                       verification=user.verification,
                       created_at=WTime(values[7]),
                       text=values[8])
        forward_num = int(values[5])
        cascade = cs.Cascade(root,
                             mid,
                             comment=int(values[4]),
                             forward=forward_num,
                             like=int(values[6]),
                             start_time=WTime(values[7]),
                             type=type)
        while (True):
            forward_line = file.readline()

            line_num += 1
            forward_values = forward_line.strip('\n').split('\t')

            if forward_values[0] != mid:
                read = 1
                break
            if len(cascade.nodes) >= threshold:
                continue
            forward_name = forward_values[2]
            forward_created_at = WTime(forward_values[3])
            forward_text = forward_values[4]
            parents = trace_parents(forward_text)
            node = cs.Node(forward_name,
                           created_at=forward_created_at,
                           text=forward_text)

            if len(parents) == 0:
                cascade.add_child(node, cascade.root)
            else:
                for parent_node in cascade.nodes:
                    if parent_node.name == parents[0]:
                        cascade.add_child(node, parent_node)
                        break
        if len(cascade.nodes) >= 10:
            cascade_num += 1
            cascades.append(cascade)

    file.close()
    return cascades