def update(cls, **update): cls._meta.database = Database.get_adapter(Database.WRITE) return super(Model, cls).update(**update)
def raw(cls, sql, *params): cls._meta.database = Database.get_adapter(Database.READ) return super(Model, cls).raw(sql, *params)
def select(cls, *selection): cls._meta.database = Database.get_adapter(Database.READ) return super(Model, cls).select(*selection)
# 加入第三方类库搜索路径 sys.path.append(os.path.join(os.path.dirname(__file__), 'modules')) # 加载程序配置 from wiki import config from xcat import cache, Database # 取缓存实例 cache.client = getattr( cache, config.settings['xcat_cache'][config.settings['run_mode']] )() # 加载数据库配置 Database.load_config( config.settings['database'].get(config.settings['run_mode'], False) ) import xcat.web import xcat.plugins from wiki import uimodules # 加载UImodel config.settings['ui_modules'] = uimodules # run app from wiki.handlers import * application = xcat.web.Application([], **config.settings) # 为插件注册 application
#coding=utf-8 from peewee import * from xcat import Database Model._meta.database = Database.get_adapter(Database.READ) class Model(Model): """ 基础模型 """ class Meta: database = Database.get_adapter(Database.READ) @classmethod def raw(cls, sql, *params): cls._meta.database = Database.get_adapter(Database.READ) return super(Model,cls).raw(sql, *params) @classmethod def select(cls, *selection): cls._meta.database = Database.get_adapter(Database.READ) return super(Model,cls).select(*selection) @classmethod def update(cls, **update): cls._meta.database = Database.get_adapter(Database.WRITE) return super(Model,cls).update(**update) @classmethod def insert(cls, **insert): cls._meta.database = Database.get_adapter(Database.WRITE)
def create(cls, **query): cls._meta.database = Database.get_adapter(Database.WRITE) return super(Model, cls).create(**query)
def save(self, force_insert=False): self._meta.database = Database.get_adapter(Database.WRITE) return super(Model, self).save(force_insert)
def create(cls, **query): cls._meta.database = Database.get_adapter(Database.WRITE) return super(Model,cls).create(**query)
def drop_table(cls, fail_silently=False): cls._meta.database = Database.get_adapter(Database.WRITE) return super(Model,cls).drop_table(fail_silently)
def insert(cls, **insert): cls._meta.database = Database.get_adapter(Database.WRITE) return super(Model,cls).insert(**insert)
def delete(cls): cls._meta.database = Database.get_adapter(Database.WRITE) return super(Model,cls).delete()
def update(cls, **update): cls._meta.database = Database.get_adapter(Database.WRITE) return super(Model,cls).update(**update)
def select(cls, *selection): cls._meta.database = Database.get_adapter(Database.READ) return super(Model,cls).select(*selection)
def raw(cls, sql, *params): cls._meta.database = Database.get_adapter(Database.READ) return super(Model,cls).raw(sql, *params)
def insert(cls, **insert): cls._meta.database = Database.get_adapter(Database.WRITE) return super(Model, cls).insert(**insert)
def save(self, force_insert=False): self._meta.database = Database.get_adapter(Database.WRITE) return super(Model,self).save(force_insert)
def delete(cls): cls._meta.database = Database.get_adapter(Database.WRITE) return super(Model, cls).delete()
def on__finish(self): # 关闭主从数据库连接 Database.close()
def drop_table(cls, fail_silently=False): cls._meta.database = Database.get_adapter(Database.WRITE) return super(Model, cls).drop_table(fail_silently)
#coding=utf-8 from peewee import * from xcat import Database Model._meta.database = Database.get_adapter(Database.READ) class Model(Model): """ 基础模型 """ class Meta: database = Database.get_adapter(Database.READ) @classmethod def raw(cls, sql, *params): cls._meta.database = Database.get_adapter(Database.READ) return super(Model, cls).raw(sql, *params) @classmethod def select(cls, *selection): cls._meta.database = Database.get_adapter(Database.READ) return super(Model, cls).select(*selection) @classmethod def update(cls, **update): cls._meta.database = Database.get_adapter(Database.WRITE) return super(Model, cls).update(**update) @classmethod def insert(cls, **insert):
class Meta: database = Database.get_adapter(Database.READ)
import sys # 设置系统编码为utf8 reload(sys) sys.setdefaultencoding('utf8') # 加入第三方类库搜索路径 sys.path.append(os.path.join(os.path.dirname(__file__), 'modules')) # 加载程序配置 from wiki import config # 引入Database from xcat import Database # 加载数据库配置 Database.load_config(config.settings['database'].get( config.settings['run_mode'], False)) Database.connect() import wiki.models import wiki.models.wiki for m in dir(wiki.models): model = getattr(wiki.models, m) if m != 'Model' and str(type(model)) == "<class 'peewee.BaseModel'>": if model.table_exists() == False: try: model.create_table() except Exception, e: pass elif str(type(model)) == "<type 'module'>":
reload(sys) sys.setdefaultencoding("utf8") # 加入第三方类库搜索路径 sys.path.append(os.path.join(os.path.dirname(__file__), "modules")) import requests # 加载程序配置 from wiki import config # 引入Database from xcat import Database # 加载数据库配置 Database.load_config(config.settings["database"].get(config.settings["run_mode"], False)) Database.connect() from wiki.models import wiki # 按每个url 3秒超时算, 1分钟要get 20个url for v in wiki.Task.select().order_by(wiki.Task.level.desc()).limit(20): try: requests.get(v.url, timeout=2.8) print "get %s" % v.url # 删除任务 wiki.Task.delete().where(wiki.Task.id == v.id).execute() except Exception, e: pass