Ejemplo n.º 1
0
    def __init__(self):
        settings = dict(
            blog_title = u"ttx",
            template_path = os.path.join(os.path.dirname(__file__), "templates"),
            static_path = os.path.join(os.path.dirname(__file__), "static"),
            root_path = os.path.join(os.path.dirname(__file__), "/"),
            xsrf_cookies = False,
            cookie_secret = "cookie_secret_code",
            login_url = "/login",
            autoescape = None,
            jinja2 = Environment(loader = FileSystemLoader(os.path.join(os.path.dirname(__file__), "templates")), trim_blocks = True),
            reserved = ["user", "topic", "home", "setting", "forgot", "login", "logout", "register", "admin"],
            debug=True,
        )

        handlers = [
            (r"/(favicon\.ico)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(sitemap.*$)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(bdsitemap\.txt)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(orca\.txt)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),

            (r"/", handler.index.IndexHandler),
            (r"/p/(\d+)", handler.index.PostHandler),
            (r"/baicai", handler.index.ListHandler),
            (r"/baicai/items", handler.index.GetListItemsHandler),
            (r"/item", handler.index.TaobaoHandler),
            (r"/coupon", handler.index.CouponHandler),
            (r"/prompt", handler.index.TaobaoPromptHandler),
        ]

        tornado.web.Application.__init__(self, handlers, **settings)

        # Have one global connection to the blog DB across all handlers
        self.db = torndb.Connection(
            host = options.mysql_host, database = options.mysql_database,
            user = options.mysql_user, password = options.mysql_password
        )

        # Have one global loader for loading models and handles
        self.loader = Loader(self.db)

        # Have one global model for db query
        self.user_model = self.loader.use("user.model")
        self.post_model = self.loader.use("post.model")

        # Have one global session controller
        self.session_manager = SessionManager(settings["cookie_secret"], ["127.0.0.1:11211"], 0)

        # Have one global memcache controller
        self.mc = memcache.Client(["127.0.0.1:11211"])

        DEBUG_FLAG = False
        if DEBUG_FLAG:
            self.debug_flag = True
            self.static_path = "/static"
            self.template_path = ""
        else:
            self.debug_flag = False
            self.static_path = "/static/dist"
            self.template_path = "dist/"
Ejemplo n.º 2
0
    def _mount(self):
        if self._children:
            self._mode |= MODE_VIRT

        if self._mode & MODE_VIRT or self._index == None:
            mode = None
            freq = None
            prof = None
        else:
            mode = self._mode
            freq = self._freq
            prof = self.d_profile
            path = get_mnt_path(self._uid, self._name)
            if os.path.exists(path):
                loader = Loader(self._uid)
                curr_prof = loader.get_profile(self._name)
                if curr_prof['type'] == prof['type']:
                    curr_mode = loader.get_attr(self._name, ATTR_MODE, int)
                    if ((curr_mode | MODE_SYNC) == (mode | MODE_SYNC)) and curr_prof.get('spec') == prof.get('spec'):
                        mode = None
                        freq = None
                        prof = None
                    else:
                        if not (curr_mode & MODE_SYNC):
                            mode &= ~MODE_SYNC
                        else:
                            mode |= MODE_SYNC
                        freq = loader.get_attr(self._name, ATTR_FREQ, float)

        if not self._children:
            api_mount(self._uid, name=self.d_name, mode=mode, freq=freq, prof=prof)
            self._log('mount %s [%s*]' % (self.d_type, self.d_name[:8]))
Ejemplo n.º 3
0
class Application(tornado.web.Application):
    def __init__(self):
        settings = dict(
            blog_title = u"mifan.tv",
            template_path = os.path.join(os.path.dirname(__file__), "templates"),
            static_path = os.path.join(os.path.dirname(__file__), "static"),
            xsrf_cookies = False,
            cookie_secret = "cookie_secret_code",
            login_url = "/login",
            autoescape = None,
            jinja2 = Environment(loader = FileSystemLoader(os.path.join(os.path.dirname(__file__), "templates")), trim_blocks = True),
            reserved = ["user", "topic", "home", "setting", "forgot", "login", "logout", "register", "admin"],
            debug=True,
        )

        handlers = [
            (r"/", handler.index.IndexHandler),
            (r"/community", handler.community.CommunityHandler),
            (r"/p/(\d+)", handler.post.PostHandler),
            (r"/create", handler.post.CreatePostHandler),

            (r"/(favicon\.ico)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(sitemap.*$)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(bdsitemap\.txt)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(orca\.txt)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
        ]

        tornado.web.Application.__init__(self, handlers, **settings)

        # Have one global connection to the blog DB across all handlers
        self.db = torndb.Connection(
            host = options.mysql_host, database = options.mysql_database,
            user = options.mysql_user, password = options.mysql_password
        )

        # Have one global loader for loading models and handles
        self.loader = Loader(self.db)

        # Have one global model for db query
        self.user_model = self.loader.use("user.model")
        self.post_model = self.loader.use("post.model")
        self.head1_model = self.loader.use("head1.model")
        self.head2_model = self.loader.use("head2.model")
        self.std_model = self.loader.use("std.model")
        self.hot_model = self.loader.use("hot.model")
        self.comment_model = self.loader.use("comment.model")

        # Have one global session controller
        self.session_manager = SessionManager(settings["cookie_secret"], ["127.0.0.1:11211"], 0)

        # Have one global memcache controller
        self.mc = memcache.Client(["127.0.0.1:11211"])
Ejemplo n.º 4
0
    def __init__(self):
        self.screen = pygame.display.set_mode((800, 600), 1)
        pygame.display.set_caption("Music Painter")
        pygame.init()
        loader = Loader()
        self.canvas = Canvas(800, 600)
        self.brush = PaintBrush(self.screen)
        self.brush.set_brush(loader.load_image("brush_6.png", True))
        self.brush.set_follow_angle(True)
        self.brush.set_color(pygame.Color("Blue"))
        self.brush.set_alpha(0.2)

        self.screen.fill((255, 255, 255))
Ejemplo n.º 5
0
    def __init__(self):
        self.screen = pygame.display.set_mode((800, 600),1)
        pygame.display.set_caption("PaintBrush simple demo v1.0 - Press space to clear paper")
        
        loader = Loader()
                        
        self.brush = PaintBrush(self.screen)
        self.brush.set_brush(loader.load_image("brush_6.png", True))
        self.brush.set_follow_angle(True)
        self.brush.set_color(pygame.Color("Blue"))
        self.brush.set_alpha(0.2)

        self.screen.fill((255,255,255))
Ejemplo n.º 6
0
	def __init__(self):
		self.screen = pygame.display.set_mode((800, 600),1)
		pygame.display.set_caption("Music Painter")
		pygame.init()
		loader = Loader()
		self.canvas = Canvas(800, 600)				
		self.brush = PaintBrush(self.screen)
		self.brush.set_brush(loader.load_image("brush_6.png", True))
		self.brush.set_follow_angle(True)
		self.brush.set_color(pygame.Color("Blue"))
		self.brush.set_alpha(0.2)

		self.screen.fill((255,255,255))
Ejemplo n.º 7
0
    def __init__(self):
        settings = dict(
            template_path=os.path.join(os.path.dirname(__file__), "templates"),
            static_path=os.path.join(os.path.dirname(__file__),
                                     "templates/spa/static"),
            #xsrf_cookies = True,
            xsrf_cookies=False,
            cookie_secret="cookie_secret_code",
            login_url="/login",
            autoescape=None,
            jinja2=Environment(loader=FileSystemLoader(
                os.path.join(os.path.dirname(__file__), "templates")),
                               trim_blocks=True),
        )

        handlers = [
            (r"/", handler.index.IndexHandler),
            (r"/signup/", handler.signup.SignupHandler),
            (r"/home/", handler.home.HomeHandler),
            (r"/history/(.*)/", handler.history.HistoryHandler),
            (r"/spa/(.*)/", handler.note.NoteHandler),
            # signup
            (r"/api/signup/", handler.usi.UsiSignupHandler),
            # login
            (r"/api/login/", handler.usi.UsiLoginHandler),
            # logout
            (r"/api/logout/", handler.usi.UsiLogoutHandler),
            # get_note_list
            (r"/api/note-list/", handler.usi.UsiGetNoteListHandler),

            # new api
            (r"/api/new-note/", handler.api.ApiNewNoteHandler),
            # get note api
            (r"/api/get-note/", handler.api.ApiGetNoteHandler),
            # delete api
            (r"/api/delete-note/", handler.api.ApiDeleteNoteHandler),
            #save api
            (r"/api/heartbeat/", handler.api.ApiHeartbeatHandler),
            # websocket api
            (r"/api/ws/echo/(.*)", handler.api.EchoWebSocket),
        ]

        tornado.web.Application.__init__(self, handlers, **settings)

        self.db = sqlite3.connect('db/youdao.db')

        self.redis = redis.Redis(host='127.0.0.1', port=6379)

        self.loader = Loader(self.db)
        self.user_model = self.loader.use("user.model")
        self.note_model = self.loader.use("note.model")
Ejemplo n.º 8
0
class Mode(object):
    def __init__(self, uid):
        self._mode = {}
        self._loader = Loader(uid)

    def _log(self, text):
        if LOG_MODE:
            log_debug(self, text)

    def _get(self, name):
        mode = self._loader.get_attr(name, ATTR_MODE, int)
        if mode != None:
            self._mode[name] = mode
            self._log('name=%s, mode=%s' % (str(name), str(mode)))
            return mode

    def get(self, name):
        if self._mode.has_key(name):
            ret = self._mode.get(name)
            if ret != None:
                return ret
        return self._get(name)

    def remove(self, name):
        if self._mode.has_key(name):
            del self._mode[name]
Ejemplo n.º 9
0
class Freq(object):
    def __init__(self, uid):
        self._freq = {}
        self._loader = Loader(uid)

    def _log(self, text):
        if LOG_FREQ:
            log_debug(self, text)

    def _get(self, name):
        freq = self._loader.get_attr(name, ATTR_FREQ, float)
        if freq:
            self._freq[name] = freq
            self._log('name=%s, freq=%s' % (str(name), str(freq)))
            return freq

    def get(self, name):
        if self._freq.has_key(name):
            return self._freq.get(name)
        else:
            return self._get(name)

    def remove(self, name):
        if self._freq.has_key(name):
            del self._freq[name]
Ejemplo n.º 10
0
    def __init__(self):
        settings = dict(
            blog_title = u"Home of 360",
            template_path = os.path.join(os.path.dirname(__file__), "templates"),
            static_path = os.path.join(os.path.dirname(__file__), "static"),
            xsrf_cookies = False,
            cookie_secret = "cookie_secret_code",
            login_url = "/login",
            autoescape = None,
            jinja2 = Environment(loader = FileSystemLoader(os.path.join(os.path.dirname(__file__), "templates")), trim_blocks = True),
            reserved = ["user", "topic", "home", "setting", "forgot", "login", "logout", "register", "admin"],
        )

        handlers = [
            (r"/", handler.home.IndexHandler),
            (r"/register", handler.user.RegisterHandler),
            (r"/u/(\w+)", handler.user.UserDetailHandler),
            (r"/edit", handler.user.UserModifyHandler),
            (r"/b", handler.blog.BlogHandler),
        ]

        tornado.web.Application.__init__(self, handlers, **settings)

        conn = MongoClient("localhost", 27017)
        self.db = conn.example

        self.loader = Loader(self.db)

        self.user_model = self.loader.use("user.model")

        self.blog_model = self.loader.use("blog.model")

        self.session_manager = SessionManager(settings["cookie_secret"], ["127.0.0.1:11211"], 0)

        self.mc = memcache.Client(["127.0.0.1:11211"])
Ejemplo n.º 11
0
class Application(tornado.web.Application):
	def __init__(self):
		settings = dict(
			blog_title = u"Dota2Ark Community",
			template_path = os.path.join(os.path.dirname(__file__), "templates"),
			static_path = os.path.join(os.path.dirname(__file__), "static"),
			avatar_path = os.path.join(os.path.dirname(__file__), 'static/avatar'),
			xsrf_cookies = True,
			cookie_secret = "cookie_secret_code",
			login_url = "/login",
			autoescape = None,
			jinja2 = Environment(loader = FileSystemLoader(os.path.join(os.path.dirname(__file__), "templates")), trim_blocks = True),
			reserved = ["user", "topic", "home", "setting", "forgot", "login", "logout", "register", "admin"],
			# debug = True,
		)

		tornado.web.Application.__init__(self, routes, **settings)

		# Have one global connection to the blog DB across all handlers
		self.db = torndb.Connection(
			host = options.mysql_host, database = options.mysql_database,
			user = options.mysql_user, password = options.mysql_password
		)

		# Have one global loader for loading models and handles
		self.loader = Loader(self.db)

		# Have one global model for db query
		self.user_model = self.loader.use("user.model")
		self.topic_model = self.loader.use("topic.model")
		self.reply_model = self.loader.use("reply.model")
		self.plane_model = self.loader.use("plane.model")
		self.node_model = self.loader.use("node.model")
		self.notification_model = self.loader.use("notification.model")
		self.vote_model = self.loader.use("vote.model")
		self.favorite_model = self.loader.use("favorite.model")

		self.panel_model = self.loader.use('panel.model')
		self.item_model = self.loader.use('item.model')
		self.inventory_model = self.loader.use('inventory.model')
		# Have one global session controller
		self.session_manager = SessionManager(settings["cookie_secret"], ["127.0.0.1:11211"], 0)

		# Have one global memcache controller
		self.mc = memcache.Client(["127.0.0.1:11211"])
Ejemplo n.º 12
0
    def __init__(self):
        self.screen = pygame.display.set_mode((800, 600),1)
        pygame.display.set_caption("PaintBrush advanced demo v1.1")
        
        self.loader = Loader()
        
        self.simple_pal = self.loader.load_image("simple.png",False)
        self.advanced_pal = self.loader.load_image("advanced.png",False)
        self.simple = True
        
        self.knob = self.loader.load_image("knob.png",True)
        self.knob_rect = self.knob.get_rect()
        self.knob_rect.topleft = (14,215)
        
        self.back = self.loader.load_image("back.png", False)

        self.help = self.loader.load_image("help.png", True)
                        
        self.b1 = self.loader.load_image("brush_1.png", True) 
        self.b2 = self.loader.load_image("brush_2.png", True) 
        self.b3 = self.loader.load_image("brush_3.png", True) 
        self.b4 = self.loader.load_image("brush_4.png", True) 
        self.b5 = self.loader.load_image("brush_5.png", True) 
        self.b6 = self.loader.load_image("brush_6.png", True) 
        self.b7 = self.loader.load_image("brush_7.png", True)
        self.b8 = self.loader.load_image("brush_8.png", True)
        self.b9 = self.loader.load_image("brush_9.png", True)
        self.cur_color = pygame.Color(0,0,0)
        
        self.paper_rect = pygame.Rect(127,12,659,574)
        self.paper = (pygame.Surface(self.paper_rect.size,1)).convert()
        self.paper.fill((255,255,255))
        self.painting = False
        self.undo_cache = []
        
        self.pal_rect = pygame.Rect(12,12,101,200)
        
        self.brush_rect = pygame.Rect(12,231,101,355)
        self.brush_rects = [] 
        self.brush_rects.append(pygame.Rect(12,231,101,200))
        self.brush_rects.append(pygame.Rect(12,332,50,50))
        self.brush_rects.append(pygame.Rect(63,332,50,50))
        self.brush_rects.append(pygame.Rect(12,332+51*1,50,50))
        self.brush_rects.append(pygame.Rect(63,332+51*1,50,50))
        self.brush_rects.append(pygame.Rect(12,332+51*2,50,50))
        self.brush_rects.append(pygame.Rect(63,332+51*2,50,50))
        self.brush_rects.append(pygame.Rect(12,332+51*3,50,50))
        self.brush_rects.append(pygame.Rect(63,332+51*3,50,50))
        self.brush_rects.append(pygame.Rect(12,332+51*4,50,50))
        self.brush_rects.append(pygame.Rect(63,332+51*4,50,50))
        
        self.brush = PaintBrush(self.paper)
        
        self.set_brush(2)
Ejemplo n.º 13
0
class Application(tornado.web.Application):
    def __init__(self):
        settings = dict(
            blog_title = u"Git Eye",
            template_path = os.path.join(os.path.dirname(__file__), "templates"),
            static_path = os.path.join(os.path.dirname(__file__), "static"),
            xsrf_cookies = True,
            cookie_secret = "cookie_secret_code",
            login_url = "/login",
            autoescape = None,
            jinja2 = Environment(loader = FileSystemLoader(os.path.join(os.path.dirname(__file__), "templates")), trim_blocks = True),
            reserved = ["user", "topic", "home", "setting", "forgot", "login", "logout", "register", "admin"],
        )

        handlers.append(
            (r"/(favicon\.ico)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
        )

        tornado.web.Application.__init__(self, handlers, **settings)

        # Have one global connection to the DB across all handlers
        self.db = torndb.Connection(
            host = options.mysql_host, database = options.mysql_database,
            user = options.mysql_user, password = options.mysql_password
        )

        # Have one global loader for loading models and handles
        self.loader = Loader(self.db)

        # Have one global model for db query
        self.user_model = self.loader.use("user.model")
        self.socialauth_model = self.loader.use("socialauth.model")

        # Have one global redis controller
        pool = redis.ConnectionPool(host=options.redis_host, port=options.redis_port, db=options.redis_db)
        self.rc = redis.StrictRedis(connection_pool=pool)

        # Have one global session controller
        self.session_manager = SessionManager(settings["cookie_secret"], self.rc, 86400 * 15)
Ejemplo n.º 14
0
 def __init__(self, uid, channel, core, addr=PROC_ADDR):
     self._uid = uid
     self._queue = []
     self._paths = {}
     self._hidden = {}
     self._core = core
     self._addr = addr
     self._pool = None
     self._visible = {}
     self._dispatchers = {}
     self._channel = channel
     self._lock = NamedLock()
     self._loader = Loader(self._uid)
     self._pool = DispatcherPool(core)
Ejemplo n.º 15
0
class Handler(object):
    def __init__(self, uid, addr=PROC_ADDR):
        self._handlers = {}
        self._loader = Loader(uid)
        self._addr = addr

    def _get_code(self, name):
        buf = self._handlers.get(name)
        if not buf:
            buf = self._loader.get_attr(name, ATTR_HANDLER, str)
            self._handlers.update({name:buf})
        return buf

    def remove(self, name):
        if self._handlers.has_key(name):
            del self._handlers[name]

    def check(self, name):
        if self._handlers.get(name):
            return True
        else:
            buf = self._loader.get_attr(name, ATTR_HANDLER, str)
            if buf:
                self._handlers.update({name:buf})
                return True

    def put(self, name, buf):
        try:
            code = self._get_code(name)
            if code == None:
                code = self._get_code(name)
                if not code:
                    return
            return proc.put(self._addr, HANDLER_PORT, code, buf)
        except:
            log_err(self, 'failed to put')
Ejemplo n.º 16
0
    def load_scores(csv_file):
        scores = Loader(csv_file, [], None)

        tags = scores.raw["tag"].values.tolist()
        scores = scores.raw["score"].values.tolist()

        score_meta = list()

        for idx in range(len(tags)):
            if tags[idx] != "empty":
                res = str(tags[idx]).split()
            else:
                res = [""]
            score_meta.append({"keys": res, "score": scores[idx]})

        return score_meta
Ejemplo n.º 17
0
class Lo(UDI):
    def get_name(self, device, child=None):
        return _get_name(device)

    def get_mode(self, device):
        return _get_mode(device)

    def setup(self):
        self._active = False
        self._loader = Loader(self.get_uid())
        Thread(target=create_server, args=(LO_ADDR, LO_PORT, LoDaemon)).start()

    def _get_device(self, name):
        mode = self._core.get_mode(name)
        prof = self._loader.get_profile(name)
        if prof:
            return device_name(prof['type'], name, mode)

    def scan(self):
        device_list = []
        if not self._active:
            self._active = True
            names = get_devices(self._uid, sort=True)
            if names:
                for name in names:
                    device = self._get_device(name)
                    if device and device not in _devices:
                        device_list.append(device)
        return device_list

    def connect(self, device):
        return (connect(device), True)

    @property
    def compute_unit(self):
        if not _devices:
            return
        keys = _devices.keys()
        length = len(keys)
        i = randint(0, length - 1)
        for _ in range(length):
            device = _devices[keys[i]]
            if device.get_mode() & MODE_CTRL:
                return device
            i += 1
            if i == length:
                i = 0
Ejemplo n.º 18
0
def main():
    L = Loader('models/schemas/')

    decryptor = L.load_schema('decryptor')
    matrix = L.load_schema('storage_matrix')
    multiplexer = L.load_schema('multiplexer')
    and1 = L.load_schema('and')
    and2 = L.load_schema('and')

    decryptor.connector.add(
        matrix, {
            'Y0': 'Y0',
            'Y1': 'Y1',
            'Y2': 'Y2',
            'Y3': 'Y3',
            'Y4': 'Y4',
            'Y5': 'Y5',
            'Y6': 'Y6',
            'Y7': 'Y7'
        })
    matrix.connector.add(
        multiplexer, {
            'X0': 'X0',
            'X1': 'X1',
            'X2': 'X2',
            'X3': 'X3',
            'X4': 'X4',
            'X5': 'X5',
            'X6': 'X6',
            'X7': 'X7'
        })
    multiplexer.connector.add(and2, {'Y': 'X1'})
    and1.connector.add(and2, {'Y': 'X2'})

    cm = CollectManager(decryptor)
    cm.add(matrix)
    cm.add(multiplexer)
    cm.add(and1)
    cm.add(and2)

    mw = MainWindow(cm)
    mw.canvas.schema(decryptor, [50, 50]).draw()
    mw.canvas.matrix(matrix, [200, 50]).draw()
    mw.canvas.schema(multiplexer, [360, 250]).draw()
    mw.canvas.schema(and1, [360, 460]).draw()
    mw.canvas.schema(and2, [520, 420]).draw()
    connections = mw.canvas.connections()
    for connection in connections:
        connection.draw()

    mw.execute()
Ejemplo n.º 19
0
 def __init__(self):
     self.screen = pygame.display.set_mode((800, 600),1)
     pygame.display.set_caption("Memory v1.0")
             
     self.loader = Loader()
                     
     self.game_board = GameBoard()        
     self.side_panel = SidePanel()
     self.robot_mouse = RobotMouse() 
     self.ai_player = AIPlayer(3)
     
     self.side_panel.ai_level = self.ai_player.level
     self.side_panel.update_stats()
     self.pair_snd = self.loader.load_sound("pair.wav")
     self.win_snd = self.loader.load_sound("win.wav")
     self.win_snd.set_volume(0.5)
     self.boom_snd = self.loader.load_sound("boom.wav")
     self.boom_snd.set_volume(0.3)
     
     self.stardust = StarDustAnim()
     self.starburst = StarBurstAnim()
Ejemplo n.º 20
0
class Timeout(object):
    def __init__(self, uid):
        self._timeout = {}
        self._loader = Loader(uid)

    def _get(self, name):
        timeout = self._loader.get_attr(name, ATTR_TIMEOUT, float)
        if timeout != None:
            self._timeout[name] = timeout
            return timeout

    def get(self, name):
        if self._timeout.has_key(name):
            ret = self._timeout.get(name)
            if ret != None:
                return ret
        return self._get(name)

    def remove(self, name):
        if self._timeout.has_key(name):
            del self._timeout[name]
Ejemplo n.º 21
0
class Parent(object):
    def __init__(self, uid):
        self._parent = {}
        self._loader = Loader(uid)

    def _get(self, name):
        parent = self._loader.get_attr(name, ATTR_PARENT, str)
        if parent != None:
            self._parent[name] = parent
            return parent

    def get(self, name):
        if self._parent.has_key(name):
            ret = self._parent.get(name)
            if ret != None:
                return ret
        return self._get(name)

    def remove(self, name):
        if self._parent.has_key(name):
            del self._parent[name]
Ejemplo n.º 22
0
    ]

    # train_data = Loader(csv_file=train_file, split_pairs=splitters, filter_headers=filters)
    # print(train_data.data)

    knn_filters = [
        "category", "num-comments", "feedback-karma", "ratings-given",
        "ratings-received", "num-authors", "prev-games", "fun-average",
        "innovation-average", "theme-average", "graphics-average",
        "audio-average", "humor-average", "mood-average", "fun-rank",
        "innovation-rank", "theme-rank", "graphics-rank", "audio-rank",
        "humor-rank", "mood-rank", "label"
    ]

    train_data = Loader(csv_file=train_file,
                        split_pairs=splitter,
                        filter_headers=knn_filters)
    df = train_data.splits["category"]["jam"]  # TODO : Split here

    X = df.iloc[:, :-1].values
    y = df.iloc[:, 20].values

    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20)

    test_data = Loader(csv_file=test_file,
                       split_pairs=splitter,
                       filter_headers=knn_filters[:-1])
    real_X_test = test_data.splits["category"]["jam"]  # TODO : Split here

    scaler = StandardScaler()
    scaler.fit(X_train)
Ejemplo n.º 23
0
    sets = list()
    for key in buks:
        top = top_words(buks[key])
        print(key, top.most_common(5))
        # all_words = list(map(lambda x: x[0], top.most_common(50)))
        sets.append(set(top))
    intersect = sets[0]
    uni = list()
    for s in sets:
        intersect = s.intersection(intersect)
    for s in sets:
        uni.append(s.difference(intersect))


if __name__ == '__main__':
    train_data = Loader("../kaggle/train.csv", [], ["id", "description", "label"])
    IDs = train_data.raw["id"].values.tolist()
    texts = train_data.raw["description"].values.tolist()
    labels = train_data.raw["label"].values.tolist()

    # IDs = IDs[:550]
    # texts = texts[:550]
    # labels = labels[:550]

    gists = list(map(lambda x: merge(get_gist_text(x)), texts))
    X_train, X_test, y_train, y_test = train_test_split(gists, labels, test_size=0.2)
    vectorizer = TfidfVectorizer(stop_words='english')
    X = vectorizer.fit_transform(X_train)

    target = 500
    reduced_x = list()
Ejemplo n.º 24
0
class AdvancedDemo(object):
    def __init__(self):
        self.screen = pygame.display.set_mode((800, 600),1)
        pygame.display.set_caption("PaintBrush advanced demo v1.1")
        
        self.loader = Loader()
        
        self.simple_pal = self.loader.load_image("simple.png",False)
        self.advanced_pal = self.loader.load_image("advanced.png",False)
        self.simple = True
        
        self.knob = self.loader.load_image("knob.png",True)
        self.knob_rect = self.knob.get_rect()
        self.knob_rect.topleft = (14,215)
        
        self.back = self.loader.load_image("back.png", False)

        self.help = self.loader.load_image("help.png", True)
                        
        self.b1 = self.loader.load_image("brush_1.png", True) 
        self.b2 = self.loader.load_image("brush_2.png", True) 
        self.b3 = self.loader.load_image("brush_3.png", True) 
        self.b4 = self.loader.load_image("brush_4.png", True) 
        self.b5 = self.loader.load_image("brush_5.png", True) 
        self.b6 = self.loader.load_image("brush_6.png", True) 
        self.b7 = self.loader.load_image("brush_7.png", True)
        self.b8 = self.loader.load_image("brush_8.png", True)
        self.b9 = self.loader.load_image("brush_9.png", True)
        self.cur_color = pygame.Color(0,0,0)
        
        self.paper_rect = pygame.Rect(127,12,659,574)
        self.paper = (pygame.Surface(self.paper_rect.size,1)).convert()
        self.paper.fill((255,255,255))
        self.painting = False
        self.undo_cache = []
        
        self.pal_rect = pygame.Rect(12,12,101,200)
        
        self.brush_rect = pygame.Rect(12,231,101,355)
        self.brush_rects = [] 
        self.brush_rects.append(pygame.Rect(12,231,101,200))
        self.brush_rects.append(pygame.Rect(12,332,50,50))
        self.brush_rects.append(pygame.Rect(63,332,50,50))
        self.brush_rects.append(pygame.Rect(12,332+51*1,50,50))
        self.brush_rects.append(pygame.Rect(63,332+51*1,50,50))
        self.brush_rects.append(pygame.Rect(12,332+51*2,50,50))
        self.brush_rects.append(pygame.Rect(63,332+51*2,50,50))
        self.brush_rects.append(pygame.Rect(12,332+51*3,50,50))
        self.brush_rects.append(pygame.Rect(63,332+51*3,50,50))
        self.brush_rects.append(pygame.Rect(12,332+51*4,50,50))
        self.brush_rects.append(pygame.Rect(63,332+51*4,50,50))
        
        self.brush = PaintBrush(self.paper)
        
        self.set_brush(2)

    def save_paper(self):
        self.undo_cache.append(self.paper.copy())
        self.undo_cache = self.undo_cache[-30:]

    def undo_paper(self):
        if len(self.undo_cache):
            p = self.undo_cache.pop()
            self.paper.blit(p,(0,0))

    def set_color(self,c):
        self.cur_color = c
        self.brush.set_color(c)
        
    def set_alpha(self,a):
        if a <= 0.0:
            a = 0.005
            x = 14
        elif a >= 1.0:
            a = 1.0
            x = 97
        else:
            x = int(round(14.0+83.0*a))
        self.brush.set_alpha(a)
        self.knob_rect.left = x

    def set_brush(self,idx):
        if idx == 0:
            self.brush.set_brush(self.b1)
            self.brush.set_space(5.0)
            self.brush.set_color(self.cur_color)
            self.set_alpha(1.0)
        elif idx == 1:
            self.brush.set_brush(self.b2)
            self.brush.set_space(2.0)
            self.brush.set_color(self.cur_color)
            self.set_alpha(1.0)
        elif idx == 2:
            self.brush.set_brush(self.b3)
            self.brush.set_space(1.0)
            self.brush.set_color(self.cur_color)
            self.set_alpha(1.0)
        elif idx == 3:
            self.brush.set_brush(self.b4)
            self.brush.set_space(1.0)
            self.brush.set_color(self.cur_color)
            self.set_alpha(1.0)
        elif idx == 4:
            self.brush.set_brush(self.b5)
            self.brush.set_space(1.0)
            self.brush.set_color(self.cur_color)
            self.set_alpha(0.06)
        elif idx == 5:
            self.brush.set_brush(self.b6)
            self.brush.set_space(1.0)
            self.brush.set_color(self.cur_color)
            self.set_alpha(0.2)
        elif idx == 6:
            self.brush.set_brush(self.b6)
            self.brush.set_space(1.0)
            self.brush.set_color(self.cur_color)
            self.brush.set_follow_angle(True)
            self.set_alpha(0.2)
        elif idx == 7:
            self.brush.set_brush(self.b7)
            self.brush.set_space(1.0)
            self.brush.set_color(self.cur_color)
            self.set_alpha(0.15)
        elif idx == 8:
            self.brush.set_brush(self.b3)
            self.brush.set_space(1.0)
            self.brush.set_color(self.cur_color)
            self.brush.set_pattern([30,20,8,20])
            self.set_alpha(1.0)
        elif idx == 9:
            self.brush.set_brush(self.b8,True)
            self.brush.set_space(65.0)
            self.set_alpha(1.0)
        elif idx == 10:            
            self.brush.set_brush(self.b9,True)
            self.brush.set_space(20.0)
            self.brush.set_follow_angle(True)
            self.set_alpha(1.0)
        
    def paint_start(self):
        self.painting = True
        self.save_paper()
        
    def paint_stop(self):
        self.painting = False
    
    def swap_palette(self):
        self.simple = not self.simple
        if self.simple:
            self.back.blit(self.simple_pal,(12,12))
        else:
            self.back.blit(self.advanced_pal,(12,12))
                
    def main_loop(self):            
        clock = pygame.time.Clock()
        
        line_from = None
        line_to = None

        cur_color = pygame.Color(0,0,0)

        next_update = pygame.time.get_ticks()
        drag_knob = False
        
        view_help = True
        
        while 1:            
            for event in pygame.event.get():
                
                if view_help:
                    if event.type == QUIT:
                        return
                    elif event.type == KEYDOWN:
                        if event.key == K_ESCAPE:
                            return                    
                        else:
                            view_help = False
                    elif event.type == MOUSEBUTTONDOWN:
                        view_help=False
                else:
                    if event.type == QUIT:
                        return
                    elif event.type == KEYDOWN:
                        if event.key == K_ESCAPE:
                            return                    
                        elif event.key == K_SPACE:
                            self.paint_start()
                            self.paper.fill((255,255,255))
                            self.paint_stop()    
                        elif event.key == K_F1:
                            view_help = True
                        elif event.key == K_F2:
                            self.swap_palette()
                        elif event.key == 122 and event.mod == 64:
                            self.undo_paper()
                    
                    elif event.type == MOUSEBUTTONDOWN:
                        if event.button == 1:
                            if self.pal_rect.collidepoint(event.pos):
                                c = self.back.get_at(event.pos)
                                self.set_color(c)
                            elif self.brush_rect.collidepoint(event.pos):
                                i = 0
                                for r in self.brush_rects:
                                    if r.collidepoint(event.pos):
                                        self.set_brush(i)
                                    i+=1
                            elif self.knob_rect.collidepoint(event.pos):
                                drag_knob = True
                            elif self.paper_rect.collidepoint(event.pos):
                                self.paint_start()
                                x = event.pos[0]-self.paper_rect.x
                                y = event.pos[1]-self.paper_rect.y
                                self.brush.paint_from((x,y))
                        elif event.button == 3:
                            if self.paper_rect.collidepoint(event.pos):
                                line_from = event.pos
                            elif self.pal_rect.collidepoint(event.pos):
                                self.swap_palette()
                    elif event.type == MOUSEMOTION:
                        if event.buttons[0]:
                            if drag_knob:
                                self.knob_rect.left+=event.rel[0]
                                if self.knob_rect.left < 14:
                                    self.knob_rect.left = 14
                                if self.knob_rect.left > 97:
                                    self.knob_rect.left = 97
                            elif self.paper_rect.collidepoint(event.pos):
                                if self.painting:
                                    x = event.pos[0]-self.paper_rect.x
                                    y = event.pos[1]-self.paper_rect.y
                                    self.brush.paint_to((x,y))                            
                        elif event.buttons[2]:
                            if self.paper_rect.collidepoint(event.pos):
                                line_to = event.pos
                                painting = False                            
                    elif event.type == MOUSEBUTTONUP:
                        if drag_knob:
                            drag_knob = False
                            a = float(self.knob_rect.left-14)/83.0
                            self.set_alpha(a)
                        if event.button == 1 and self.painting:
                            self.paint_stop()
                        if event.button == 3:
                            if line_from:
                                self.paint_start()
                                fx = line_from[0]-self.paper_rect.x
                                fy = line_from[1]-self.paper_rect.y
                                tx = event.pos[0]-self.paper_rect.x
                                ty = event.pos[1]-self.paper_rect.y
                                self.brush.paint_line((fx,fy),(tx,ty))
                                self.paint_stop()
                                line_from = None
                                line_to = None
                                                          
            if pygame.time.get_ticks() >= next_update:
                next_update+=33
                self.screen.blit(self.back,(0,0))
                self.screen.blit(self.paper,self.paper_rect.topleft)
                if not view_help:
                    if line_from and line_to:
                        pygame.draw.line(self.screen, (0,0,0), line_from, line_to)
                self.screen.blit(self.knob,self.knob_rect.topleft)
                
                if view_help:
                    self.screen.blit(self.help,(0,0))
                
                pygame.display.flip()            
Ejemplo n.º 25
0
 def __init__(self, uid, addr=PROC_ADDR):
     self._addr = addr
     self._filters = {}
     self._loader = Loader(uid)
currentFullRoute = os.path.abspath(
    os.path.join(os.path.dirname(__file__), "./"))
currentDir = os.path.basename(os.getcwd())
currentFileName = os.path.basename(__file__)

libDir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../"))
sys.path.append(libDir)
print libDir

from lib.router import Router
router = Router()
ROUTES = router.getRoutes()

from lib.loader import Loader
loader = Loader(currentFullRoute, ROUTES)

from lib.helper import Helper
helper = Helper()

from lib.filewriter import FileWriter
filewriter = FileWriter()

from lib.reporter import Reporter
reporter = Reporter(ROUTES)

# return to current path

sys.path.append(currentFullRoute)

# ---------------------------------------------------------------------- CUSTOM LIBS
Ejemplo n.º 27
0
 def __init__(self, mnemonicos_table):
     self.mnemonicos_table = mnemonicos_table
     self.assembler = Assembler(mnemonicos_table)
     self.loader = Loader(mnemonicos_table)
Ejemplo n.º 28
0
class SimuladorMVN:
    STATES = ["on", "off"]
    STATUS = "status"
    EXIT = "exit"
    ON = "on"
    OFF = "off"
    BOOT = "boot"
    RUN = "run"
    STOP = "stop"
    CLEAR = "clear"
    MEM_SIZE = 4_000
    MNE_TABLE = "mnemonics"
    ASSEMBLER_STATUS = "assembler"
    LOADER_STATUS = "loader"
    HELP = "help"
    state = "off"
    mnemonicos_table = None
    program_name = ""
    program_lines = []
    mem = {}
    run_auto = False
    assembler = None
    loader = None

    def __init__(self, mnemonicos_table):
        self.mnemonicos_table = mnemonicos_table
        self.assembler = Assembler(mnemonicos_table)
        self.loader = Loader(mnemonicos_table)

    def print_program(self):
        line_number = 1
        for line in self.program_lines:
            print(f"line {line_number}. {line}", end="")
            line_number = line_number + 1
        print()

    def load_program(self, program_filepath):
        print(f"loading program {program_filepath}...")
        with open(program_filepath) as program_file:
            self.program_name = program_filepath
            self.program_lines = program_file.readlines()
            self.assembler.load_program_lines(self.program_lines)
            self.assembler.treat_program_lines()
            self.assembler.process_fase_1()
            self.assembler.process_fase_2()
            self.loader.object_code = self.assembler.object_code
            self.loader.load_program()
            self.state = "program_loaded"
            program_file.close()
        print_div()

    def simulator_is_off(self):
        print_red("Simulador MVN off")
        print(f"to turn on: {self.ON}")
        print(f"to exit:    {self.EXIT}")
        print(f"to help:    {self.HELP}")
        print_div()

    def simulator_is_on(self):
        print_green("Simulador MVN on")
        print(f"to print internal status:       {self.STATUS}")
        print(f"to print table of mnemonics:    {self.MNE_TABLE}")
        print(f"to print assembler status:      {self.ASSEMBLER_STATUS}")
        print(f"to print loader status:         {self.LOADER_STATUS}")
        print(f"to load a program:              {self.BOOT}")
        print(f"to run the program in memory:   {self.RUN}")
        print(f"to clear:                       {self.CLEAR}")
        print(f"to help:                        {self.HELP}")
        print(f"to turn off:                    {self.OFF}")
        print_div()

    def cmd_run(self):
        if self.state == "program_loaded":
            self.loader.run()
        else:
            print_red(f"no program in memory")
            print_red(f"to load a program, enter '{self.BOOT}'")
            return

    def cmd_help(self):
        if self.state == "off":
            self.simulator_is_off()
        else:
            self.simulator_is_on()

    def cmd_on(self):
        if self.state == "off":
            self.state = "on"
            self.simulator_is_on()

    def cmd_off(self):
        if self.state != "off":
            self.state = "off"
            self.simulator_is_off()

    def cmd_boot(self):
        program_filename = input("enter program path: ")
        try:
            program_filepath = program_filename
            self.load_program(program_filepath)
        except OSError as e:
            print_red(f"error while opening the file: {e}")
            return

    def cmd_clear(self):
        self.assembler.clear_all()
        self.loader.clear_all()
        self.mem = {}
        self.program_name = ""
        self.program_lines = []
        self.process_end = False

    def cmd_mne_table(self):
        print_green("Table of mnemonics")
        pprint(self.mnemonicos_table)
        print_div()

    def cmd_assembler_status(self):
        self.assembler.print_status()
        print_div()

    def cmd_loader_status(self):
        self.loader.print_status()
        print_div()

    def cmd_status(self):
        print_green("Simulator status")
        print_yellow(f"state:        {self.state}")
        print_yellow(f"program name: {self.program_name}")
        print_yellow(f"program:")
        if self.program_name == "":
            pass
        else:
            self.print_program()
        print_yellow("memory:")
        pprint(self.mem)
        print_div()

    def cmd_invalid(self):
        print_red("invalid command")

    def start(self):
        self.simulator_is_off()
        while True:
            if self.state == "off":
                input_cmd = input(": ")
                if input_cmd == self.EXIT:
                    break
                elif input_cmd == self.ON:
                    self.cmd_on()
                    continue
                elif input_cmd == self.HELP:
                    self.cmd_help()
                    continue
                else:
                    self.cmd_invalid()
                    continue
            else:
                input_cmd = input(": ")
                if input_cmd == self.HELP:
                    self.cmd_help()
                    continue
                elif input_cmd == self.MNE_TABLE:
                    self.cmd_mne_table()
                    continue
                elif input_cmd == self.ASSEMBLER_STATUS:
                    self.cmd_assembler_status()
                    continue
                elif input_cmd == self.LOADER_STATUS:
                    self.cmd_loader_status()
                    continue
                elif input_cmd == self.BOOT:
                    self.cmd_boot()
                    continue
                elif input_cmd == self.OFF:
                    self.cmd_off()
                    continue
                elif input_cmd == self.CLEAR:
                    self.cmd_clear()
                    continue
                elif input_cmd == self.STATUS:
                    self.cmd_status()
                    continue
                elif input_cmd == self.RUN:
                    self.cmd_run()
                    continue
                else:
                    self.cmd_invalid()
                    continue
Ejemplo n.º 29
0
class Application(tornado.web.Application):
    def __init__(self):
        settings = dict(
            blog_title = u"AI系统运维",
            template_path = os.path.join(os.path.dirname(__file__), "templates"),
            static_path = os.path.join(os.path.dirname(__file__), "static"),
            xsrf_cookies = True,
            cookie_secret = "cookie_secret_code",
            login_url = "/login",
            autoescape = None,
            jinja2 = Environment(loader = FileSystemLoader(os.path.join(os.path.dirname(__file__), "templates")), trim_blocks = True),
            reserved = ["user", "topic", "home", "setting", "forgot", "login", "logout", "register", "admin"],
            debug=True,
        )

        handlers = [
            (r"/", handler.topic.IndexHandler),
            (r"/t/(\d+)", handler.topic.ViewHandler),
            (r"/t/create/(.*)", handler.topic.CreateHandler),
            (r"/t/edit/(.*)", handler.topic.EditHandler),
            (r"/reply/edit/(.*)", handler.topic.ReplyEditHandler),
            (r"/node/(.*)", handler.topic.NodeTopicsHandler),
            (r"/college/(.*)", handler.topic.CollegeTopicsHandler),
            (r"/u/(.*)/topics", handler.topic.UserTopicsHandler),
            (r"/u/(.*)/replies", handler.topic.UserRepliesHandler),
            (r"/u/(.*)/favorites", handler.topic.UserFavoritesHandler),
            (r"/u/(.*)", handler.topic.ProfileHandler),
            (r"/vote", handler.topic.VoteHandler),
            (r"/favorite", handler.topic.FavoriteHandler),
            (r"/notifications", handler.notification.ListHandler),
            (r"/members", handler.topic.MembersHandler),
            (r"/nodes", handler.topic.NodesHandler),
            (r"/admin", handler.admin.AdminIndexnHandler),
            (r"/admin/home", handler.admin.AdminHomeHandler),
            (r"/admin/usermanage", handler.admin.AdminUserDataHandler),
            (r"/admin/userdata", handler.admin.AdminUserIndexHandler),
            (r"/demo/table/user", handler.admin.AdminDataHandler),
            (r"/api/tiecontrol", handler.admin.AdminDataHandler),
            (r"/api/usercontrol", handler.admin.AdminUserDataHandler),
            (r"/colleges", handler.topic.CollegesHandler),
            (r"/setting", handler.user.SettingHandler),
            (r"/setting/avatar", handler.user.SettingAvatarHandler),
            (r"/setting/avatar/gravatar", handler.user.SettingAvatarFromGravatarHandler),
            (r"/setting/password", handler.user.SettingPasswordHandler),
            (r"/forgot", handler.user.ForgotPasswordHandler),
            (r"/login", handler.user.LoginHandler),
            (r"/logout", handler.user.LogoutHandler),
            (r"/register", handler.user.RegisterHandler),
            (r"/register/college", handler.user.RegisterCollegeHandler),
            (r"/register/college/(.*)", handler.user.SetCollegeHandler),
            (r"/s/college/(.*)", handler.topic.CollegesHandler),
            (r"/s/node/(.*)", handler.topic.NodesHandler),
            (r"/f/node/(.*)", handler.topic.FollowNodeHandler),
            (r"/f/user/(.*)", handler.topic.FollowUserHandler),
            (r"/m/(.*)", handler.message.CreateMessageHandler),
            (r"/messages", handler.message.MessagesHandler),
            (r"/about", handler.page.AboutHandler),
            (r"/license", handler.page.AboutHandler),
            (r"/feedback", handler.page.AboutHandler),
            (r"/guide", handler.page.AboutHandler),

            (r"/(favicon\.ico)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(sitemap.*$)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(bdsitemap\.txt)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(orca\.txt)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(.*)", handler.topic.ProfileHandler),
        ]

        tornado.web.Application.__init__(self, handlers, **settings)

        # Have one global connection to the blog DB across all handlers
        self.db = torndb.Connection(
            host = options.mysql_host, database = options.mysql_database,
            user = options.mysql_user, password = options.mysql_password
        )

        # Have one global loader for loading models and handles
        self.loader = Loader(self.db)

        # Have one global model for db query
        self.user_model = self.loader.use("user.model")
        self.topic_model = self.loader.use("topic.model")
        self.reply_model = self.loader.use("reply.model")
        self.plane_model = self.loader.use("plane.model")
        self.node_model = self.loader.use("node.model")
        self.college_model = self.loader.use("college.model")
        self.province_model = self.loader.use("province.model")
        self.notification_model = self.loader.use("notification.model")
        self.vote_model = self.loader.use("vote.model")
        self.favorite_model = self.loader.use("favorite.model")
        self.interest_model = self.loader.use("interest.model")
        self.follow_model = self.loader.use("follow.model")
        self.message_model = self.loader.use("message.model")

        # Have one global session controller
        self.session_manager = SessionManager(settings["cookie_secret"], ["127.0.0.1:11211"], 0)

        # Have one global memcache controller
        self.mc = memcache.Client(["127.0.0.1:11211"])
Ejemplo n.º 30
0
 def __init__(self, uid):
     self._parent = {}
     self._loader = Loader(uid)
Ejemplo n.º 31
0
currentFullRoute = os.path.abspath(
    os.path.join(os.path.dirname(__file__), "./"))
currentDir = os.path.basename(os.getcwd())
currentFileName = os.path.basename(__file__)

libDir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../"))
sys.path.append(libDir)
print libDir

from lib.router import Router
router = Router()
ROUTES = router.getRoutes()

from lib.loader import Loader
loader = Loader(currentFullRoute, ROUTES)

from lib.helper import Helper
helper = Helper()

from lib.filewriter import FileWriter
filewriter = FileWriter()

from lib.reporter import Reporter
reporter = Reporter(ROUTES)

# return to current path

sys.path.append(currentFullRoute)

# ---------------------------------------------------------------------- CUSTOM LIBS
Ejemplo n.º 32
0
    def __init__(self):
        settings = dict(
            blog_title=u"1024nj",
            template_path=os.path.join(os.path.dirname(__file__), "templates"),
            static_path=os.path.join(os.path.dirname(__file__), "static"),
            root_path=os.path.join(os.path.dirname(__file__), "/"),
            xsrf_cookies=False,
            cookie_secret="cookie_secret_code",
            login_url="/login",
            autoescape=None,
            jinja2=Environment(loader=FileSystemLoader(
                os.path.join(os.path.dirname(__file__), "templates")),
                               trim_blocks=True),
            reserved=[
                "user", "topic", "home", "setting", "forgot", "login",
                "logout", "register", "admin"
            ],
            debug=True,
        )

        handlers = [
            (r"/(favicon\.ico)", tornado.web.StaticFileHandler,
             dict(path=settings["static_path"])),
            (r"/(sitemap.*$)", tornado.web.StaticFileHandler,
             dict(path=settings["static_path"])),
            (r"/(bdsitemap\.txt)", tornado.web.StaticFileHandler,
             dict(path=settings["static_path"])),
            (r"/(orca\.txt)", tornado.web.StaticFileHandler,
             dict(path=settings["static_path"])),
            (r"/(baidu_verify_cNFzOIiNxf\.html)",
             tornado.web.StaticFileHandler,
             dict(path=settings["static_path"])),
            (r"/(google4a4f69878d81fc8a\.html)", tornado.web.StaticFileHandler,
             dict(path=settings["static_path"])),
            (r"/", handler.index.BbsHandler),
            (r"/p/(\d+)", handler.index.PostHandler),
            (r"/new", handler.index.NewHandler),
            (r"/t/(.*)", handler.index.TagHandler),
            (r"/tags", handler.index.TagsHandler),
            (r"/reply/(\d+)", handler.index.ReplyHandler),
            (r"/follow", handler.index.FollowHandler),
            (r"/vote/reply/(\d+)", handler.index.VoteReplyHandler),
            (r"/vote/post/(\d+)", handler.index.VotePostHandler),
            (r"/thank/(\d+)", handler.index.ThankHandler),
            (r"/report/(\d+)", handler.index.ReportHandler),
            (r"/delete/reply/(\d+)", handler.index.DeleteReplyHandler),
            (r"/edit/reply/(\d+)", handler.index.EditReplyHandler),
            (r"/delete/post/(\d+)", handler.index.DeletePostHandler),
            (r"/edit/(\d+)", handler.index.EditHandler),
            (r"/u/(.*)", handler.user.UserHandler),
            (r"/signin", handler.user.SigninHandler),
            (r"/signout", handler.user.SignoutHandler),
            (r"/signup", handler.user.SignupHandler),
            (r"/setting", handler.user.SettingHandler),
            (r"/setting/avatar", handler.user.SettingAvatarHandler),
            (r"/setting/cover", handler.user.SettingCoverHandler),
            (r"/setting/password", handler.user.SettingPasswordHandler),
            (r"/forgot", handler.user.ForgotPasswordHandler),
            (r"/social", handler.user.SocialHandler),
            (r"/notifications", handler.index.NoticeHandler),
            (r"/follows/(.*)", handler.index.FollowsHandler),
            (r"/get/users/(\d+)", handler.index.GetInviteUsersHandler),
            (r"/invite/to/answer/(\d+)", handler.index.InviteToAnswerHandler),
            (r"/invitations", handler.index.InvitationsHandler),
            (r"/invite/to/email/(\d+)", handler.index.InviteToEmailHandler),
            (r"/invite/to/join", handler.index.InviteToJoinHandler),
            (r"/invite/(.*)", handler.index.InviteHandler),
            (r"/edit/tag/(\d+)", handler.index.EditTagHandler),
            (r"/upload", handler.index.UploadHandler),
            (r"/list", handler.index.ListHandler),
            (r"/balance", handler.index.BalanceHandler),
            (r"/update/user/view/follow",
             handler.index.UpdateUserViewFollowHandler),
            (r"/get/youku/(.*)", handler.index.GetYoukuHandler),
            (r"/get/user/(.*)", handler.index.GetUserHandler),
            (r"/get/tag/(.*)", handler.index.GetTagHandler),
            (r"/get/tags", handler.index.GetTagsHandler),
            (r"/additem", handler.index.AddItemHandler),
            (r"/item/(\d+)", handler.index.ItemHandler),
            (r"/like/(\d+)", handler.index.LikeItemHandler),
            #(r".*", handler.index.PageNotFoundHandler)
            (r"/get/nav/(\d+)", handler.index.NavListNewsHandler),
            (r"/nba", handler.index.NbaHandler),
            (r"/football", handler.index.FootballHandler),
            (r"/bbs", handler.index.BbsHandler),
            (r"/hot", handler.index.HotHandler),
            (r"/live", handler.index.LiveHandler),
            (r"/get/nodes", handler.index.GetNodesHandler),
            (r"/go/(.*)", handler.index.NodeHandler),
            (r"/pages/(.*)", handler.index.PageHandler),
            (r"/admin", handler.admin.IndexAdminHandler),
        ]

        tornado.web.Application.__init__(self, handlers, **settings)

        # Have one global connection to the blog DB across all handlers
        self.db = torndb.Connection(host=options.mysql_host,
                                    database=options.mysql_database,
                                    user=options.mysql_user,
                                    password=options.mysql_password)

        # Have one global loader for loading models and handles
        self.loader = Loader(self.db)

        # Have one global model for db query
        self.user_model = self.loader.use("user.model")
        self.feed_model = self.loader.use("feed.model")
        self.post_model = self.loader.use("post.model")
        self.reply_model = self.loader.use("reply.model")
        self.feed_type_model = self.loader.use("feed_type.model")
        self.like_item_model = self.loader.use("like_item.model")
        self.vote_model = self.loader.use("vote.model")
        self.post_tag_model = self.loader.use("post_tag.model")
        self.tag_model = self.loader.use("tag.model")
        self.category_model = self.loader.use("category.model")
        self.follow_model = self.loader.use("follow.model")
        self.thank_model = self.loader.use("thank.model")
        self.report_model = self.loader.use("report.model")
        self.notice_model = self.loader.use("notice.model")
        self.invite_model = self.loader.use("invite.model")
        self.tag_type_model = self.loader.use("tag_type.model")
        self.tag_parent_model = self.loader.use("tag_parent.model")
        self.icode_model = self.loader.use("icode.model")
        self.avatar_model = self.loader.use("avatar.model")
        self.balance_model = self.loader.use("balance.model")
        self.balance_type_model = self.loader.use("balance_type.model")
        self.ads_model = self.loader.use("ads.model")
        self.item_model = self.loader.use("item.model")
        self.live_model = self.loader.use("live.model")
        self.video_model = self.loader.use("video.model")
        self.section_model = self.loader.use("section.model")
        self.object_video_model = self.loader.use("object_video.model")
        self.section_video_model = self.loader.use("section_video.model")
        self.nav_model = self.loader.use("nav.model")
        self.post_node_model = self.loader.use("post_node.model")
        self.node_model = self.loader.use("node.model")

        # Have one global session controller
        self.session_manager = SessionManager(settings["cookie_secret"],
                                              ["127.0.0.1:11211"], 0)

        # Have one global memcache controller
        self.mc = memcache.Client(["127.0.0.1:11211"])
Ejemplo n.º 33
0
    def __init__(self):
        settings = dict(
            blog_title=u"F2E Community",
            template_path=os.path.join(os.path.dirname(__file__), "templates"),
            static_path=os.path.join(os.path.dirname(__file__), "static"),
            xsrf_cookies=True,
            cookie_secret="cookie_secret_code",
            login_url="/login",
            autoescape=None,
            jinja2=Environment(loader=FileSystemLoader(
                os.path.join(os.path.dirname(__file__), "templates")),
                               trim_blocks=True),
            reserved=[
                "user", "topic", "home", "setting", "forgot", "login",
                "logout", "register", "admin"
            ],
        )

        handlers = [
            (r"/", handler.topic.IndexHandler),
            (r"/t/(\d+)", handler.topic.ViewHandler),
            (r"/t/create/(.*)", handler.topic.CreateHandler),
            (r"/t/edit/(.*)", handler.topic.EditHandler),
            (r"/reply/edit/(.*)", handler.topic.ReplyEditHandler),
            (r"/node/(.*)", handler.topic.NodeTopicsHandler),
            (r"/u/(.*)/topics", handler.topic.UserTopicsHandler),
            (r"/u/(.*)/replies", handler.topic.UserRepliesHandler),
            (r"/u/(.*)/favorites", handler.topic.UserFavoritesHandler),
            (r"/u/(.*)", handler.topic.ProfileHandler),
            (r"/vote", handler.topic.VoteHandler),
            (r"/favorite", handler.topic.FavoriteHandler),
            (r"/unfavorite", handler.topic.CancelFavoriteHandler),
            (r"/notifications", handler.notification.ListHandler),
            (r"/members", handler.topic.MembersHandler),
            (r"/setting", handler.user.SettingHandler),
            (r"/setting/avatar", handler.user.SettingAvatarHandler),
            (r"/setting/avatar/gravatar",
             handler.user.SettingAvatarFromGravatarHandler),
            (r"/setting/password", handler.user.SettingPasswordHandler),
            (r"/forgot", handler.user.ForgotPasswordHandler),
            (r"/login", handler.user.LoginHandler),
            (r"/logout", handler.user.LogoutHandler),
            (r"/register", handler.user.RegisterHandler),
            (r"/(favicon\.ico)", tornado.web.StaticFileHandler,
             dict(path=settings["static_path"])),
            (r"/(sitemap.*$)", tornado.web.StaticFileHandler,
             dict(path=settings["static_path"])),
            (r"/(bdsitemap\.txt)", tornado.web.StaticFileHandler,
             dict(path=settings["static_path"])),
            (r"/(.*)", handler.topic.ProfileHandler),
        ]

        tornado.web.Application.__init__(self, handlers, **settings)

        # Have one global connection to the blog DB across all handlers
        self.db = torndb.Connection(host=options.mysql_host,
                                    database=options.mysql_database,
                                    user=options.mysql_user,
                                    password=options.mysql_password)

        # Have one global loader for loading models and handles
        self.loader = Loader(self.db)

        # Have one global model for db query
        self.user_model = self.loader.use("user.model")
        self.topic_model = self.loader.use("topic.model")
        self.reply_model = self.loader.use("reply.model")
        self.plane_model = self.loader.use("plane.model")
        self.node_model = self.loader.use("node.model")
        self.notification_model = self.loader.use("notification.model")
        self.vote_model = self.loader.use("vote.model")
        self.favorite_model = self.loader.use("favorite.model")

        # Have one global session controller
        self.session_manager = SessionManager(settings["cookie_secret"],
                                              ["127.0.0.1:11211"], 0)

        # Have one global memcache controller
        self.mc = memcache.Client(["127.0.0.1:11211"])
Ejemplo n.º 34
0
    def __init__(self):
        settings = dict(
            blog_title = u"webeta",
            template_path = os.path.join(os.path.dirname(__file__), "templates"),
            static_path = os.path.join(os.path.dirname(__file__), "static"),
            root_path = os.path.join(os.path.dirname(__file__), "/"),
            xsrf_cookies = False,
            cookie_secret = "cookie_secret_code",
            login_url = "/login",
            autoescape = None,
            jinja2 = Environment(loader = FileSystemLoader(os.path.join(os.path.dirname(__file__), "templates")), trim_blocks = True),
            reserved = ["user", "topic", "home", "setting", "forgot", "login", "logout", "register", "admin"],
            debug=True,
        )

        handlers = [
            (r"/(favicon\.ico)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(sitemap.*$)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(bdsitemap\.txt)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(orca\.txt)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),

            (r"/", handler.index.IndexHandler),
            (r"/weixin", handler.index.WeixinHandler),
            (r"/shareit", handler.index.ShareItHandler),
            (r"/t/(.*)", handler.index.TopicHandler),
            (r"/addad", handler.index.AddAdHandler),
            (r"/myshares", handler.index.MySharesHandler),
            (r"/myads", handler.index.MyAdsHandler),
            (r"/tb/(.*)", handler.index.TaobaoHandler),
            (r"/prompt/(.*)", handler.index.TaobaoPromptHandler),
            (r"/addtb", handler.index.AddTbHandler),
            (r"/get/shop", handler.index.GetShopUUIDHandler),
            (r"/shop/(.*)", handler.index.ShopHandler),
            (r"/api/shop/(.*)", handler.index.GetShopItemsHandler),
            (r"/mytbs", handler.index.MyTabaosHandler),
            (r"/edit/tb/(.*)", handler.index.TaobaoEditHandler),
        ]

        tornado.web.Application.__init__(self, handlers, **settings)

        # Have one global connection to the blog DB across all handlers
        self.db = torndb.Connection(
            host = options.mysql_host, database = options.mysql_database,
            user = options.mysql_user, password = options.mysql_password
        )

        # Have one global loader for loading models and handles
        self.loader = Loader(self.db)

        # Have one global model for db query
        self.user_model = self.loader.use("user.model")
        self.topic_model = self.loader.use("topic.model")
        self.ad_model = self.loader.use("ad.model")
        self.taobao_model = self.loader.use("taobao.model")
        self.shop_model = self.loader.use("shop.model")

        # Have one global session controller
        self.session_manager = SessionManager(settings["cookie_secret"], ["127.0.0.1:11211"], 0)

        # Have one global memcache controller
        self.mc = memcache.Client(["127.0.0.1:11211"])
Ejemplo n.º 35
0
        "humor-average",
        "mood-average",
        "fun-rank",
        "innovation-rank",
        "theme-rank",
        "graphics-rank",
        "audio-rank",
        "humor-rank",
        "mood-rank",
        "label"
    ]

    # Data prep
    scorer = Score("data/tag_scores.csv")
    train_IDs = Loader(csv_file=train_file,
                       split_pairs=[],
                       filter_headers=["id"])
    train_IDs = train_IDs.raw["id"].values.tolist()
    test_IDs = Loader(csv_file=test_file,
                      split_pairs=[],
                      filter_headers=["id"])
    test_IDs = test_IDs.raw["id"].values.tolist()

    train_data = Loader(csv_file=train_file,
                        split_pairs=[],
                        filter_headers=filters)
    train_data.apply_category_encoding()
    train_data.map_column("link-tags", scorer.score_tag)

    # Description clustering
    train_labels = train_data.raw["label"].values.tolist()
Ejemplo n.º 36
0
    def __init__(self):
        settings = dict(
            blog_title=u"分知网",
            template_path=os.path.join(os.path.dirname(__file__), "templates"),
            static_path=os.path.join(os.path.dirname(__file__), "static"),
            xsrf_cookies=True,
            cookie_secret="F66eavGATJy49AopMxnMBJ5PTVabo0ZujPWT4ZJVJnU=",
            login_url="/login",
            autoescape=None,
            jinja2=Environment(loader = FileSystemLoader(os.path.join(os.path.dirname(__file__), "templates")), trim_blocks = True),
            reserved=["user", "topic", "home", "setting", "forgot", "login", "logout", "register", "admin"],
            debug=False,
        )

        handlers = [
            (r"/", handler.topic.IndexHandler),
            (r"/t/(\d+)", handler.topic.ViewHandler),
            (r"/t/create/(.*)", handler.topic.CreateHandler),
            (r"/t/edit/(.*)", handler.topic.EditHandler),
            (r"/reply/edit/(.*)", handler.topic.ReplyEditHandler),
            (r"/node/(.*)", handler.topic.NodeTopicsHandler),
            (r"/college/(.*)", handler.topic.CollegeTopicsHandler),
            (r"/u/(.*)/topics", handler.topic.UserTopicsHandler),
            (r"/u/(.*)/replies", handler.topic.UserRepliesHandler),
            (r"/u/(.*)/favorites", handler.topic.UserFavoritesHandler),
            (r"/u/(.*)", handler.topic.ProfileHandler),
            (r"/vote", handler.topic.VoteHandler),
            (r"/favorite", handler.topic.FavoriteHandler),
            (r"/notifications", handler.notification.ListHandler),
            (r"/members", handler.topic.MembersHandler),
            (r"/nodes", handler.topic.NodesHandler),
            (r"/colleges", handler.topic.CollegesHandler),
            (r"/setting", handler.user.SettingHandler),
            (r"/setting/avatar", handler.user.SettingAvatarHandler),
            (r"/setting/avatar/gravatar", handler.user.SettingAvatarFromGravatarHandler),
            (r"/setting/password", handler.user.SettingPasswordHandler),
            (r"/forgot", handler.user.ForgotPasswordHandler),
            (r"/login", handler.user.LoginHandler),
            (r"/logout", handler.user.LogoutHandler),
            (r"/register", handler.user.RegisterHandler),
            (r"/register/college", handler.user.RegisterCollegeHandler),
            (r"/register/college/(.*)", handler.user.SetCollegeHandler),
            (r"/s/college/(.*)", handler.topic.CollegesHandler),
            (r"/s/node/(.*)", handler.topic.NodesHandler),
            (r"/f/node/(.*)", handler.topic.FollowNodeHandler),
            (r"/f/user/(.*)", handler.topic.FollowUserHandler),
            (r"/m/(.*)", handler.message.CreateMessageHandler),
            (r"/messages", handler.message.MessagesHandler),
            (r"/about", handler.page.AboutHandler),
            (r"/license", handler.page.AboutHandler),
            (r"/feedback", handler.page.AboutHandler),
            (r"/guide", handler.page.AboutHandler),

            (r"/square", handler.image.ImageHandler),

            (r"/(favicon\.ico)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(sitemap.*$)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(bdsitemap\.txt)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(orca\.txt)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            # (r"/(.*)", handler.topic.ProfileHandler),
            (r"/upload", handler.upload.UploadHandler),
        ]

        tornado.web.Application.__init__(self, handlers, **settings)

        # Have one global connection to the blog DB across all handlers
        self.db = tornado.database.Connection(
            host = options.mysql_host, database = options.mysql_database,
            user = options.mysql_user, password = options.mysql_password
        )

        # Have one global loader for loading models and handles
        self.loader = Loader(self.db)

        # Have one global model for db query
        self.user_model = self.loader.use("user.model")
        self.topic_model = self.loader.use("topic.model")
        self.reply_model = self.loader.use("reply.model")
        self.plane_model = self.loader.use("plane.model")
        self.node_model = self.loader.use("node.model")
        self.college_model = self.loader.use("college.model")
        self.province_model = self.loader.use("province.model")
        self.notification_model = self.loader.use("notification.model")
        self.vote_model = self.loader.use("vote.model")
        self.favorite_model = self.loader.use("favorite.model")
        self.interest_model = self.loader.use("interest.model")
        self.follow_model = self.loader.use("follow.model")
        self.message_model = self.loader.use("message.model")
        self.image_model = self.loader.use("image.model")
        self.roll_model = self.loader.use("roll.model")

        # Have one global session controller
        self.session_manager = SessionManager(settings["cookie_secret"], ["127.0.0.1:11211"], 0)

        # Have one global memcache controller
        self.mc = memcache.Client(["127.0.0.1:11211"])
Ejemplo n.º 37
0
    def __init__(self):
        settings = dict(
            blog_title = u"wanzhu",
            template_path = os.path.join(os.path.dirname(__file__), "templates"),
            static_path = os.path.join(os.path.dirname(__file__), "static"),
            root_path = os.path.join(os.path.dirname(__file__), "/"),
            xsrf_cookies = False,
            cookie_secret = "cookie_secret_code",
            login_url = "/login",
            autoescape = None,
            jinja2 = Environment(loader = FileSystemLoader(os.path.join(os.path.dirname(__file__), "templates")), trim_blocks = True),
            reserved = ["user", "topic", "home", "setting", "forgot", "login", "logout", "register", "admin"],
            debug=True,
        )

        handlers = [
            (r"/(favicon\.ico)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(sitemap.*$)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(bdsitemap\.txt)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(orca\.txt)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),

            (r"/", handler.index.IndexHandler),
            (r"/bbs", handler.index.BbsHandler),
            (r"/new", handler.index.NewHandler),
            (r"/t/(.*)", handler.index.TagHandler), 
            (r"/p/(\d+)", handler.index.PostHandler),
            (r"/d/(.*)", handler.index.PostHandler),
            (r"/reply/(\d+)", handler.index.ReplyHandler),
            (r"/upload/image", handler.index.UploadImageHandler),
            (r"/signin", handler.user.SigninHandler),
            (r"/signout", handler.user.SignoutHandler),
            (r"/signup", handler.user.SignupHandler),
            (r"/admin", handler.admin.IndexAdminHandler),
            (r"/admin/signin", handler.admin.SigninAdminHandler),
            (r"/admin/signout", handler.admin.SignoutAdminHandler),
            (r"/admin/signup", handler.admin.SignupAdminHandler),
            (r"/admin/users", handler.admin.UsersAdminHandler),
            (r"/admin/user/new", handler.admin.UserNewAdminHandler),
            (r"/admin/user/edit/(\d+)", handler.admin.UserEditAdminHandler),
            (r"/admin/user/delete/(\d+)", handler.admin.UserDeleteAdminHandler),
            (r"/admin/tags", handler.admin.TagsAdminHandler),
            (r"/admin/tag/new", handler.admin.TagNewAdminHandler),
            (r"/admin/tag/edit/(\d+)", handler.admin.TagEditAdminHandler),
            (r"/admin/tag/delete/(\d+)", handler.admin.TagDeleteAdminHandler),
            (r"/api/signin", handler.api.SigninApiHandler),
            (r"/api/signout", handler.api.SignoutApiHandler),
            (r"/api/setting/password", handler.api.SettingPasswordApiHandler),
            (r"/api/get/user/base", handler.api.GetUserBaseInfoApiHandler),
            (r"/api/update/user/base", handler.api.UpdateUserBaseInfoApiHandler),
            (r"/get/tags", handler.index.GetTagsHandler),
            (r"/tags", handler.index.TagsHandler),
        ]

        tornado.web.Application.__init__(self, handlers, **settings)

        # Have one global connection to the blog DB across all handlers
        self.db = torndb.Connection(
            host = options.mysql_host, database = options.mysql_database,
            user = options.mysql_user, password = options.mysql_password
        )

        # Have one global loader for loading models and handles
        self.loader = Loader(self.db)

        # Have one global model for db query
        self.user_model = self.loader.use("user.model")
        self.post_model = self.loader.use("post.model")
        self.reply_model = self.loader.use("reply.model")
        self.tag_model = self.loader.use("tag.model")
        self.post_tag_model = self.loader.use("post_tag.model")

        # Have one global session controller
        self.session_manager = SessionManager(settings["cookie_secret"], ["127.0.0.1:11211"], 0)

        # Have one global memcache controller
        self.mc = memcache.Client(["127.0.0.1:11211"])

        DEBUG_FLAG = True
        if DEBUG_FLAG:
            self.debug_flag = True
            self.static_path = "/static"
            self.template_path = ""
        else:
            self.debug_flag = False
            self.static_path = "/static/dist"
            self.template_path = "dist/"
Ejemplo n.º 38
0
    def __init__(self):
        settings = dict(
            blog_title=u"mifan.tv",
            template_path=os.path.join(os.path.dirname(__file__), "templates"),
            static_path=os.path.join(os.path.dirname(__file__), "static"),
            xsrf_cookies=False,
            cookie_secret="cookie_secret_code",
            login_url="/login",
            autoescape=None,
            jinja2=Environment(loader=FileSystemLoader(
                os.path.join(os.path.dirname(__file__), "templates")),
                               trim_blocks=True),
            reserved=[
                "user", "topic", "home", "setting", "forgot", "login",
                "logout", "register", "admin"
            ],
            debug=True,
        )

        handlers = [
            (r"/", handler.topic.IndexHandler),
            (r"/video", handler.topic.VideoHandler),
            (r"/c/(\d+)", handler.topic.ChannelHandler),
            (r"/u/(.*)", handler.topic.UserHandler),
            (r"/login", handler.user.LoginHandler),
            (r"/register", handler.user.RegisterHandler),
            (r"/forgot", handler.user.ForgotPasswordHandler),
            (r"/f/(\d+)", handler.topic.FollowHandler),
            (r"/p/(\d+)", handler.topic.PlusChannelHandler),
            (r"/comment", handler.topic.CommentHandler),
            (r"/(favicon\.ico)", tornado.web.StaticFileHandler,
             dict(path=settings["static_path"])),
            (r"/(sitemap.*$)", tornado.web.StaticFileHandler,
             dict(path=settings["static_path"])),
            (r"/(bdsitemap\.txt)", tornado.web.StaticFileHandler,
             dict(path=settings["static_path"])),
            (r"/(orca\.txt)", tornado.web.StaticFileHandler,
             dict(path=settings["static_path"])),
        ]

        tornado.web.Application.__init__(self, handlers, **settings)

        # Have one global connection to the blog DB across all handlers
        self.db = torndb.Connection(host=options.mysql_host,
                                    database=options.mysql_database,
                                    user=options.mysql_user,
                                    password=options.mysql_password)

        # Have one global loader for loading models and handles
        self.loader = Loader(self.db)

        # Have one global model for db query
        self.user_model = self.loader.use("user.model")
        self.follow_model = self.loader.use("follow.model")
        self.post_model = self.loader.use("post.model")
        self.channel_model = self.loader.use("channel.model")
        self.plus_model = self.loader.use("plus.model")
        self.comment_model = self.loader.use("comment.model")

        # Have one global session controller
        self.session_manager = SessionManager(settings["cookie_secret"],
                                              ["127.0.0.1:11211"], 0)

        # Have one global memcache controller
        self.mc = memcache.Client(["127.0.0.1:11211"])
Ejemplo n.º 39
0
 def __init__(self, uid, addr=PROC_ADDR):
     self._handlers = {}
     self._loader = Loader(uid)
     self._addr = addr
Ejemplo n.º 40
0
    def __init__(self):
        app_settings = dict(
            blog_title=settings.site['title'],
            login_url="/login",
            jinja2=Environment(loader=FileSystemLoader(os.path.join(os.path.dirname(__file__), "templates")),
                               trim_blocks=True),
            reserved=["user", "topic", "home", "setting", "forgot", "login", "logout", "register", "admin"],
        )
        app_settings.update(settings.app_settings)

        handlers = [
            (r"/", handler.topic.IndexHandler),
            (r"/t/(\d+)", handler.topic.ViewHandler),
            (r"/t/create/(.*)", handler.topic.CreateHandler),
            (r"/t/edit/(.*)", handler.topic.EditHandler),
            (r"/reply/edit/(.*)", handler.topic.ReplyEditHandler),
            (r"/node/(.*)", handler.topic.NodeTopicsHandler),
            (r"/u/(.*)/topics", handler.topic.UserTopicsHandler),
            (r"/u/(.*)/replies", handler.topic.UserRepliesHandler),
            (r"/u/(.*)/favorites", handler.topic.UserFavoritesHandler),
            (r"/u/(.*)", handler.topic.ProfileHandler),
            (r"/vote", handler.topic.VoteHandler),
            (r"/favorite", handler.topic.FavoriteHandler),
            (r"/unfavorite", handler.topic.CancelFavoriteHandler),
            (r"/notifications", handler.notification.ListHandler),
            (r"/members", handler.topic.MembersHandler),
            (r"/setting", handler.user.SettingHandler),
            (r"/setting/avatar", handler.user.SettingAvatarHandler),
            (r"/setting/avatar/gravatar", handler.user.SettingAvatarFromGravatarHandler),
            (r"/setting/password", handler.user.SettingPasswordHandler),
            (r"/forgot", handler.user.ForgotPasswordHandler),
            (r"/login", handler.user.LoginHandler),
            (r"/logout", handler.user.LogoutHandler),
            (r"/register", handler.user.RegisterHandler),

            (r'/admin/user$', handler.user.UserAdminHandler),
            (r'/admin/node$', handler.topic.NodeAdminHandler),
            (r'/admin/node/new$', handler.topic.NodeEditHandler),
            (r'/admin/node/(\d+)$', handler.topic.NodeEditHandler),
            (r'/admin/plane$', handler.topic.PlaneAdminHandler),
            (r'/admin/plane/new$', handler.topic.PlaneEditHandler),
            (r'/admin/plane/(\d+)$', handler.topic.PlaneEditHandler),

            (r'/resource/picture/upload_async', handler.page.PictureIframeUploadHandler),

            (r"/(favicon\.ico)", tornado.web.StaticFileHandler, dict(path=app_settings["static_path"])),
            (r"/(sitemap.*$)", tornado.web.StaticFileHandler, dict(path=app_settings["static_path"])),
            (r"/(bdsitemap\.txt)", tornado.web.StaticFileHandler, dict(path=app_settings["static_path"])),
            (r"/(.*)", handler.topic.ProfileHandler),
        ]

        tornado.web.Application.__init__(self, handlers, **app_settings)

        # Have one global connection to the blog DB across all handlers
        self.db = torndb.Connection(
            host=db_default['host'], database=db_default['db_name'],
            user=db_default['user'], password=db_default['password']
        )

        # Have one global loader for loading models and handles
        self.loader = Loader(self.db)

        # Have one global model for db query
        self.user_model = self.loader.use("user.model")
        self.topic_model = self.loader.use("topic.model")
        self.reply_model = self.loader.use("reply.model")
        self.plane_model = self.loader.use("plane.model")
        self.node_model = self.loader.use("node.model")
        self.notification_model = self.loader.use("notification.model")
        self.vote_model = self.loader.use("vote.model")
        self.favorite_model = self.loader.use("favorite.model")
        self.picture_model = self.loader.use('picture.model')

        # Have one global session controller
        self.session_manager = SessionManager(app_settings["cookie_secret"], settings.memcached, 0)

        # Have one global memcache controller
        self.mc = memcache.Client(settings.memcached)
Ejemplo n.º 41
0
 def setup(self):
     self._active = False
     self._loader = Loader(self.get_uid())
     Thread(target=create_server, args=(LO_ADDR, LO_PORT, LoDaemon)).start()
Ejemplo n.º 42
0
    def __init__(self):
        settings = dict(
            blog_title = u"youxia",
            template_path = os.path.join(os.path.dirname(__file__), "templates"),
            static_path = os.path.join(os.path.dirname(__file__), "static"),
            root_path = os.path.join(os.path.dirname(__file__), "/"),
            xsrf_cookies = False,
            cookie_secret = "cookie_secret_code",
            login_url = "/login",
            autoescape = None,
            jinja2 = Environment(loader = FileSystemLoader(os.path.join(os.path.dirname(__file__), "templates")), trim_blocks = True),
            reserved = ["user", "topic", "home", "setting", "forgot", "login", "logout", "register", "admin"],
            debug=True,
        )

        handlers = [
            (r"/(favicon\.ico)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(sitemap.*$)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(bdsitemap\.txt)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(orca\.txt)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),

            (r"/", handler.index.IndexHandler),
            (r"/reviews", handler.index.ReviewsHandler),
            (r"/bbs", handler.index.BbsHandler),
            (r"/new", handler.index.NewHandler),
            (r"/tag/(.*)", handler.index.TagHandler), 
            (r"/user/(.*)", handler.user.UserHandler), 
            (r"/p/(\d+)", handler.index.PostHandler),
            (r"/post/(\d+)", handler.index.PostHandler),
            (r"/d/(.*)", handler.index.PostHandler),
            (r"/reply/(\d+)", handler.index.ReplyHandler),
            (r"/like/(\d+)", handler.index.LikeHandler),
            (r"/upload/image", handler.index.UploadImageHandler),
            (r"/signin", handler.user.SigninHandler),
            (r"/signout", handler.user.SignoutHandler),
            (r"/signup", handler.user.SignupHandler),
            (r"/settings", handler.user.SettingsHandler),
            (r"/admin", handler.admin.IndexAdminHandler),
            (r"/admin/signin", handler.admin.SigninAdminHandler),
            (r"/admin/signout", handler.admin.SignoutAdminHandler),
            (r"/admin/signup", handler.admin.SignupAdminHandler),
            (r"/admin/users", handler.admin.UsersAdminHandler),
            (r"/admin/user/new", handler.admin.UserNewAdminHandler),
            (r"/admin/user/edit/(\d+)", handler.admin.UserEditAdminHandler),
            (r"/admin/user/delete/(\d+)", handler.admin.UserDeleteAdminHandler),
            (r"/admin/newsfeeds", handler.admin.NewsfeedsAdminHandler),
            (r"/admin/newsfeed/new", handler.admin.NewsfeedNewAdminHandler),
            (r"/admin/newsfeed/edit/(\d+)", handler.admin.NewsfeedEditAdminHandler),
            (r"/admin/nowfeeds", handler.admin.NowfeedsAdminHandler),
            (r"/admin/nowfeed/new", handler.admin.NowfeedNewAdminHandler),
            (r"/admin/nowfeed/edit/(\d+)", handler.admin.NowfeedEditAdminHandler),
            (r"/admin/nowfeed/delete/(\d+)", handler.admin.NowfeedDeleteAdminHandler),
            (r"/admin/tags", handler.admin.TagsAdminHandler),
            (r"/admin/tag/new", handler.admin.TagNewAdminHandler),
            (r"/admin/tag/edit/(\d+)", handler.admin.TagEditAdminHandler),
            (r"/admin/tag/delete/(\d+)", handler.admin.TagDeleteAdminHandler),
            (r"/admin/carbrands", handler.admin.CarBrandsAdminHandler),
            (r"/admin/carvenders", handler.admin.CarVendersAdminHandler),
            (r"/admin/carmodels", handler.admin.CarModelsAdminHandler),
            (r"/admin/cardata/new", handler.admin.CarDataNewAdminHandler),
            (r"/admin/cardata/edit/(\d+)", handler.admin.CarDataEditAdminHandler),
            (r"/api/signin", handler.api.SigninApiHandler),
            (r"/api/signout", handler.api.SignoutApiHandler),
            (r"/api/setting/password", handler.api.SettingPasswordApiHandler),
            (r"/api/get/user/base", handler.api.GetUserBaseInfoApiHandler),
            (r"/api/update/user/base", handler.api.UpdateUserBaseInfoApiHandler),
            (r"/tags", handler.index.TagsHandler),
            (r"/api/get/posts", handler.api.GetPostsApiHandler),
            (r"/api/get/tags", handler.api.GetTagsApiHandler),
            (r"/api/get/cars", handler.api.GetCarsApiHandler),
            (r"/api/get/user/posts/(.*)", handler.api.GetUserPostsApiHandler),
        ]

        tornado.web.Application.__init__(self, handlers, **settings)

        # Have one global connection to the blog DB across all handlers
        self.db = torndb.Connection(
            host = options.mysql_host, database = options.mysql_database,
            user = options.mysql_user, password = options.mysql_password
        )

        # Have one global loader for loading models and handles
        self.loader = Loader(self.db)

        # Have one global model for db query
        self.user_model = self.loader.use("user.model")
        self.post_model = self.loader.use("post.model")
        self.nowfeed_model = self.loader.use("nowfeed.model")
        self.newsfeed_model = self.loader.use("newsfeed.model")
        self.reply_model = self.loader.use("reply.model")
        self.tag_model = self.loader.use("tag.model")
        self.post_tag_model = self.loader.use("post_tag.model")
        self.car_data_model = self.loader.use("car_data.model")
        self.ylike_model = self.loader.use("ylike.model")
        self.item_model = self.loader.use("item.model")
        self.color_model = self.loader.use("color.model")

        # Have one global session controller
        self.session_manager = SessionManager(settings["cookie_secret"], ["127.0.0.1:11211"], 0)

        # Have one global memcache controller
        self.mc = memcache.Client(["127.0.0.1:11211"])

        DEBUG_FLAG = True
        if DEBUG_FLAG:
            self.debug_flag = True
            self.static_path = "/static"
            self.template_path = ""
        else:
            self.debug_flag = False
            self.static_path = "/static/dist"
            self.template_path = "dist/"
Ejemplo n.º 43
0
    def __init__(self):
        settings = dict(
            blog_title = u"1024nj",
            template_path = os.path.join(os.path.dirname(__file__), "templates"),
            static_path = os.path.join(os.path.dirname(__file__), "static"),
            root_path = os.path.join(os.path.dirname(__file__), "/"),
            xsrf_cookies = False,
            cookie_secret = "cookie_secret_code",
            login_url = "/login",
            autoescape = None,
            jinja2 = Environment(loader = FileSystemLoader(os.path.join(os.path.dirname(__file__), "templates")), trim_blocks = True),
            reserved = ["user", "topic", "home", "setting", "forgot", "login", "logout", "register", "admin"],
            debug=True,
        )

        handlers = [
            (r"/(favicon\.ico)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(sitemap.*$)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(bdsitemap\.txt)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(orca\.txt)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(baidu_verify_cNFzOIiNxf\.html)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(google4a4f69878d81fc8a\.html)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),

            (r"/", handler.index.BbsHandler),
            (r"/p/(\d+)", handler.index.PostHandler),
            (r"/new", handler.index.NewHandler),
            (r"/t/(.*)", handler.index.TagHandler),   
            (r"/tags", handler.index.TagsHandler),
            (r"/reply/(\d+)", handler.index.ReplyHandler),
            (r"/follow", handler.index.FollowHandler),
            (r"/vote/reply/(\d+)", handler.index.VoteReplyHandler),
            (r"/vote/post/(\d+)", handler.index.VotePostHandler),
            (r"/thank/(\d+)", handler.index.ThankHandler),
            (r"/report/(\d+)", handler.index.ReportHandler),
            (r"/delete/reply/(\d+)", handler.index.DeleteReplyHandler),
            (r"/edit/reply/(\d+)", handler.index.EditReplyHandler),
            (r"/delete/post/(\d+)", handler.index.DeletePostHandler),
            (r"/edit/(\d+)", handler.index.EditHandler),

            (r"/u/(.*)", handler.user.UserHandler),
            (r"/signin", handler.user.SigninHandler),
            (r"/signout", handler.user.SignoutHandler),
            (r"/signup", handler.user.SignupHandler),
            (r"/setting", handler.user.SettingHandler),
            (r"/setting/avatar", handler.user.SettingAvatarHandler),
            (r"/setting/cover", handler.user.SettingCoverHandler),
            (r"/setting/password", handler.user.SettingPasswordHandler),
            (r"/forgot", handler.user.ForgotPasswordHandler),
            (r"/social", handler.user.SocialHandler),
            (r"/notifications", handler.index.NoticeHandler),
            (r"/follows/(.*)", handler.index.FollowsHandler),
            (r"/get/users/(\d+)", handler.index.GetInviteUsersHandler),
            (r"/invite/to/answer/(\d+)", handler.index.InviteToAnswerHandler),
            (r"/invitations", handler.index.InvitationsHandler),
            (r"/invite/to/email/(\d+)", handler.index.InviteToEmailHandler),
            (r"/invite/to/join", handler.index.InviteToJoinHandler),
            (r"/invite/(.*)", handler.index.InviteHandler),

            (r"/edit/tag/(\d+)", handler.index.EditTagHandler),
            (r"/upload", handler.index.UploadHandler),
            (r"/list", handler.index.ListHandler),
            (r"/balance", handler.index.BalanceHandler),
            (r"/update/user/view/follow", handler.index.UpdateUserViewFollowHandler),  
            (r"/get/youku/(.*)", handler.index.GetYoukuHandler),
            (r"/get/user/(.*)", handler.index.GetUserHandler),
            (r"/get/tag/(.*)", handler.index.GetTagHandler),
            (r"/get/tags", handler.index.GetTagsHandler),

            (r"/additem", handler.index.AddItemHandler),
            (r"/item/(\d+)", handler.index.ItemHandler),
            (r"/like/(\d+)", handler.index.LikeItemHandler),
            #(r".*", handler.index.PageNotFoundHandler)

            (r"/get/nav/(\d+)", handler.index.NavListNewsHandler),

            (r"/nba", handler.index.NbaHandler),
            (r"/football", handler.index.FootballHandler),
            (r"/bbs", handler.index.BbsHandler),
            (r"/hot", handler.index.HotHandler),
            (r"/live", handler.index.LiveHandler),
            (r"/get/nodes", handler.index.GetNodesHandler),
            (r"/go/(.*)", handler.index.NodeHandler),

            (r"/pages/(.*)", handler.index.PageHandler),
            (r"/admin", handler.admin.IndexAdminHandler),
        ]

        tornado.web.Application.__init__(self, handlers, **settings)

        # Have one global connection to the blog DB across all handlers
        self.db = torndb.Connection(
            host = options.mysql_host, database = options.mysql_database,
            user = options.mysql_user, password = options.mysql_password
        )

        # Have one global loader for loading models and handles
        self.loader = Loader(self.db)

        # Have one global model for db query
        self.user_model = self.loader.use("user.model")
        self.feed_model = self.loader.use("feed.model")
        self.post_model = self.loader.use("post.model")
        self.reply_model = self.loader.use("reply.model")
        self.feed_type_model = self.loader.use("feed_type.model")
        self.like_item_model = self.loader.use("like_item.model")
        self.vote_model = self.loader.use("vote.model")
        self.post_tag_model = self.loader.use("post_tag.model")
        self.tag_model = self.loader.use("tag.model")
        self.category_model = self.loader.use("category.model")
        self.follow_model = self.loader.use("follow.model")
        self.thank_model = self.loader.use("thank.model")
        self.report_model = self.loader.use("report.model")
        self.notice_model = self.loader.use("notice.model")
        self.invite_model = self.loader.use("invite.model")
        self.tag_type_model = self.loader.use("tag_type.model")
        self.tag_parent_model = self.loader.use("tag_parent.model")
        self.icode_model = self.loader.use("icode.model")
        self.avatar_model = self.loader.use("avatar.model")
        self.balance_model = self.loader.use("balance.model")
        self.balance_type_model = self.loader.use("balance_type.model")
        self.ads_model = self.loader.use("ads.model")
        self.item_model = self.loader.use("item.model")
        self.live_model = self.loader.use("live.model")
        self.video_model = self.loader.use("video.model")
        self.section_model = self.loader.use("section.model")
        self.object_video_model = self.loader.use("object_video.model")
        self.section_video_model = self.loader.use("section_video.model")
        self.nav_model = self.loader.use("nav.model")
        self.post_node_model = self.loader.use("post_node.model")
        self.node_model = self.loader.use("node.model")


        # Have one global session controller
        self.session_manager = SessionManager(settings["cookie_secret"], ["127.0.0.1:11211"], 0)

        # Have one global memcache controller
        self.mc = memcache.Client(["127.0.0.1:11211"])
Ejemplo n.º 44
0
    def __init__(self):
        settings = dict(
            blog_title = u"mifan.tv",
            template_path = os.path.join(os.path.dirname(__file__), "templates"),
            static_path = os.path.join(os.path.dirname(__file__), "static"),
            xsrf_cookies = False,
            cookie_secret = "cookie_secret_code",
            login_url = "/login",
            autoescape = None,
            jinja2 = Environment(loader = FileSystemLoader(os.path.join(os.path.dirname(__file__), "templates")), trim_blocks = True),
            reserved = ["user", "topic", "home", "setting", "forgot", "login", "logout", "register", "admin"],
            debug=True,
        )

        handlers = [
            (r"/", handler.topic.IndexHandler),
            (r"/video", handler.channel.VideoHandler),
            (r"/favorite", handler.topic.FavoriteHandler),
            (r"/later", handler.topic.LaterHandler),
            (r"/later/clear", handler.topic.LaterClearHandler),
            (r"/watch", handler.topic.WatchHandler),
            (r"/watch/clear", handler.topic.WatchClearHandler),
            (r"/follow", handler.channel.FollowsHandler),
            (r"/notification", handler.topic.NotificationsHandler),
            (r"/n/(\d+)", handler.topic.NotificationHandler),
            (r"/c/(\d+)", handler.channel.ChannelHandler),
            (r"/u/(.*)", handler.topic.UserHandler),
            (r"/channels/u/(.*)", handler.channel.UserOtherChannelsHandler),
            (r"/login", handler.user.LoginHandler),
            (r"/logout", handler.user.LogoutHandler),
            (r"/signup", handler.user.RegisterHandler),
            (r"/forgot", handler.user.ForgotPasswordHandler),
            (r"/f/(\d+)", handler.channel.FollowHandler),
            (r"/p/(\d+)", handler.topic.PostHandler),
            (r"/s/(\d+)", handler.topic.SpamPostHandle),
            (r"/d/(\d+)", handler.topic.DeletePostHandle),
            (r"/comment/(\d+)", handler.topic.CommentHandler),
            (r"/rate/(\d+)", handler.topic.RateHandler),
            (r"/setting", handler.user.SettingHandler),
            (r"/setting/avatar", handler.user.SettingAvatarHandler),
            (r"/setting/cover", handler.user.SettingCoverHandler),
            (r"/setting/password", handler.user.SettingPasswordHandler),
            (r"/c/(\d+)/setting", handler.channel.ChannelSettingHandler),
            (r"/c/(\d+)/setting/avatar", handler.channel.ChannelSettingAvatarHandler),
            (r"/c/(\d+)/setting/cover", handler.channel.ChannelSettingCoverHandler),
            (r"/micro", handler.channel.MicroHandler),
            (r"/movie", handler.channel.MovieHandler),
            (r"/tv", handler.channel.TVHandler),
            (r"/star", handler.channel.StarHandler),
            (r"/favorite/(\d+)", handler.topic.FavoriteManagerHandler),
            (r"/later/(\d+)", handler.topic.LaterManagerHandler),
            (r"/watch/(\d+)", handler.topic.WatchManagerHandler),
            (r"/suggestions", handler.channel.SuggestionsHandler),
            (r"/hot", handler.channel.HotChannelsHandler),
            (r"/searchchannel", handler.channel.SearchChannelHandler),

            (r"/forum", handler.topic.ForumHandler),
            (r"/t/create", handler.topic.CreateTopicHandler),
            (r"/t/(\d+)", handler.topic.ViewHandler),
            (r"/t/edit/(.*)", handler.topic.EditHandler),
            (r"/reply/edit/(.*)", handler.topic.ReplyEditHandler),

            (r"/(favicon\.ico)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(sitemap.*$)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(bdsitemap\.txt)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(orca\.txt)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
        ]

        tornado.web.Application.__init__(self, handlers, **settings)

        # Have one global connection to the blog DB across all handlers
        self.db = torndb.Connection(
            host = options.mysql_host, database = options.mysql_database,
            user = options.mysql_user, password = options.mysql_password
        )

        # Have one global loader for loading models and handles
        self.loader = Loader(self.db)

        # Have one global model for db query
        self.user_model = self.loader.use("user.model")
        self.follow_model = self.loader.use("follow.model")
        self.post_model = self.loader.use("post.model")
        self.channel_model = self.loader.use("channel.model")
        self.plus_model = self.loader.use("plus.model")
        self.comment_model = self.loader.use("comment.model")
        self.nav_model = self.loader.use("nav.model")
        self.subnav_model = self.loader.use("subnav.model")
        self.video_model = self.loader.use("video.model")
        self.favorite_model = self.loader.use("favorite.model")
        self.later_model = self.loader.use("later.model")
        self.watch_model = self.loader.use("watch.model")
        self.rate_model = self.loader.use("rate.model")
        self.notification_model = self.loader.use("notification.model")

        self.topic_model = self.loader.use("topic.model")
        self.reply_model = self.loader.use("reply.model")

        # Have one global session controller
        self.session_manager = SessionManager(settings["cookie_secret"], ["127.0.0.1:11211"], 0)

        # Have one global memcache controller
        self.mc = memcache.Client(["127.0.0.1:11211"])
Ejemplo n.º 45
0
 def __init__(self, uid):
     self._timeout = {}
     self._loader = Loader(uid)
Ejemplo n.º 46
0
from os.path import isfile, join

currentFullRoute = os.path.abspath(os.path.join(os.path.dirname(__file__),"./"))
currentDir = os.path.basename(os.getcwd())
currentFileName = os.path.basename(__file__)

libDir = os.path.abspath(os.path.join(os.path.dirname(__file__),"../"))
sys.path.append( libDir )
print libDir

from lib.router import Router
router = Router( )
ROUTES =  router.getRoutes()

from lib.loader import Loader
loader = Loader( currentFullRoute, ROUTES  )

from lib.helper import Helper
helper = Helper( )

from lib.filewriter import FileWriter
filewriter = FileWriter( )

from lib.reporter import Reporter
reporter = Reporter(  ROUTES  )

# return to current path

sys.path.append( currentFullRoute )

#_______________________________________________________________________________ CUSTOM LIBS
Ejemplo n.º 47
0
    def __init__(self):
        settings = dict(
            blog_title = u"snowy",
            template_path = os.path.join(os.path.dirname(__file__), "templates"),
            static_path = os.path.join(os.path.dirname(__file__), "static"),
            xsrf_cookies = True,
            cookie_secret = "cookie_secret_code",
            login_url = "/login",
            autoescape = None,
            jinja2 = Environment(loader = FileSystemLoader(os.path.join(os.path.dirname(__file__), "templates")), trim_blocks = True),
            reserved = ["user", "topic", "home", "setting", "forgot", "login", "logout", "register", "admin"],
        )

        handlers = [
            (r"/", handler.topic.IndexHandler),
            (r"/t/(\d+)", handler.topic.ViewHandler),
            (r"/t/create/(.*)", handler.topic.CreateHandler),
            (r"/t/edit/(.*)", handler.topic.EditHandler),
            (r"/t/(.*)/delete", handler.topic.DeleteTopicHandler),
            (r"/reply/edit/(.*)", handler.topic.ReplyEditHandler),
            (r"/reply/(.*)/delete", handler.topic.DeleteReplyHandler),
            (r"/node/(.*)", handler.topic.NodeTopicsHandler),
            (r"/u/(.*)/topics", handler.topic.UserTopicsHandler),
            (r"/u/(.*)/delete", handler.user.DeleteUserHandler),
            (r"/u/(.*)/replies", handler.topic.UserRepliesHandler),
            (r"/u/(.*)/favorites", handler.topic.UserFavoritesHandler),
            (r"/u/(.*)", handler.topic.ProfileHandler),
            (r"/vote", handler.topic.VoteHandler),
            (r"/favorite", handler.topic.FavoriteHandler),
            (r"/unfavorite", handler.topic.CancelFavoriteHandler),
            (r"/notifications", handler.notification.ListHandler),
            (r"/members", handler.topic.MembersHandler),
            (r"/setting", handler.user.SettingHandler),
            (r"/setting/avatar", handler.user.SettingAvatarHandler),
            (r"/setting/avatar/gravatar", handler.user.SettingAvatarFromGravatarHandler),
            (r"/setting/password", handler.user.SettingPasswordHandler),
            (r"/forgot", handler.user.ForgotPasswordHandler),
            (r"/login", handler.user.LoginHandler),
            (r"/logout", handler.user.LogoutHandler),
            (r"/register", handler.user.RegisterHandler),
            (r"/admin", handler.admin.AdminHandler),
            (r"/admin/members", handler.admin.MembersHandler),

            (r"/(favicon\.ico)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(sitemap.*$)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(bdsitemap\.txt)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
            (r"/(.*)", handler.topic.ProfileHandler),
        ]

        tornado.web.Application.__init__(self, handlers, **settings)

        # Have one global connection to the blog DB across all handlers
        self.db = torndb.Connection(
            host = options.mysql_host, database = options.mysql_database,
            user = options.mysql_user, password = options.mysql_password
        )

        # Have one global loader for loading models and handles
        self.loader = Loader(self.db)

        # Have one global model for db query
        self.user_model = self.loader.use("user.model")
        self.topic_model = self.loader.use("topic.model")
        self.reply_model = self.loader.use("reply.model")
        self.plane_model = self.loader.use("plane.model")
        self.node_model = self.loader.use("node.model")
        self.notification_model = self.loader.use("notification.model")
        self.vote_model = self.loader.use("vote.model")
        self.favorite_model = self.loader.use("favorite.model")

        # Have one global session controller
        self.session_manager = SessionManager(settings["cookie_secret"], ["127.0.0.1:11211"], 0)

        # Have one global memcache controller
        self.mc = memcache.Client(["127.0.0.1:11211"])
Ejemplo n.º 48
0
from os.path import isfile, join

currentFullRoute = os.path.abspath(os.path.join(os.path.dirname(__file__),"./"))
currentDir = os.path.basename(os.getcwd())
currentFileName = os.path.basename(__file__)

libDir = os.path.abspath(os.path.join(os.path.dirname(__file__),"../"))
sys.path.append( libDir )
print libDir

from lib.router import Router
router = Router( )
ROUTES =  router.getRoutes()

from lib.loader import Loader
loader = Loader( currentFullRoute, ROUTES  )

from lib.helper import Helper
helper = Helper( )

from lib.filewriter import FileWriter
exporter = FileWriter( )

 # Optional module 1
# from lib.social import Social
# social = Social( )

from lib.reporter import Reporter
reporter = Reporter(  ROUTES  )

#Extend the Reporter with the desired Report-Class