def create_app(): configs = conf.configs debug = configs['debug'] logging.info('starting %s mode...' % ('DEBUG' if debug else 'PROD')) logging.info('db conf: %s' % str(configs['db'])) logging.info('cache conf: %s' % str(configs['cache'])) # init db: db.init(db_type='mysql', db_schema=configs['db']['schema'], \ db_host=configs['db']['host'], \ db_port=configs['db']['port'], \ db_user=configs['db']['user'], \ db_password=configs['db']['password'], \ use_unicode=True, charset='utf8') # init cache: cache.client = cache.MemcacheClient(configs['cache']['host']) scan = [ 'apps.article', 'apps.stpage', 'apps.wiki', 'apps.attachment', 'apps.navigation', 'apps.user', 'apps.comment', 'apps.setting', 'core.manage' ] if debug: scan.append('static_handler') return web.WSGIApplication(scan, \ document_root=os.path.dirname(os.path.abspath(__file__)), \ filters=(load_user, ), \ template_engine='jinja2', \ DEBUG=debug)
def create_app(debug): if debug: import conf_dev as conf else: import conf_prod as conf logging.info('db conf: %s' % str(conf.db)) logging.info('cache conf: %s' % str(conf.cache)) # init db: db.init(db_type=conf.db['type'], db_schema=conf.db['schema'], \ db_host=conf.db['host'], db_port=conf.db['port'], \ db_user=conf.db['user'], db_password=conf.db['password'], \ use_unicode=True, charset='utf8') # init cache: if conf.cache['type'] == 'redis': host = conf.cache.get('host', 'localhost') cache.client = cache.RedisClient(host) if conf.cache['type'] == 'memcache': host = conf.cache.get('host', 'localhost') cache.client = cache.MemcacheClient(host) scan = ['apps.article', 'apps.wiki', 'apps.website', 'auth', 'admin'] if debug: scan.append('static_handler') return web.WSGIApplication(scan, \ document_root=os.path.dirname(os.path.abspath(__file__)), \ filters=(load_site, load_user, load_i18n), \ template_engine='jinja2', \ DEBUG=debug)
def create_app(debug): if debug: import conf_dev as conf else: import conf_prod as conf logging.info("db conf: %s" % str(conf.db)) logging.info("cache conf: %s" % str(conf.cache)) # init db: db.init( db_type=conf.db["type"], db_schema=conf.db["schema"], db_host=conf.db["host"], db_port=conf.db["port"], db_user=conf.db["user"], db_password=conf.db["password"], use_unicode=True, charset="utf8", ) # init cache: if conf.cache["type"] == "redis": host = conf.cache.get("host", "localhost") cache.client = cache.RedisClient(host) if conf.cache["type"] == "memcache": host = conf.cache.get("host", "localhost") cache.client = cache.MemcacheClient(host) scan = ["apps.article", "apps.wiki", "apps.website", "auth", "admin"] if debug: scan.append("static_handler") return web.WSGIApplication( scan, document_root=os.path.dirname(os.path.abspath(__file__)), filters=(load_site, load_user, load_i18n), template_engine="jinja2", DEBUG=debug, )
def create_app(): # from conf import dbconf # kwargs = dict([(s, getattr(dbconf, s)) for s in dir(dbconf) if s.startswith('DB_')]) # dbargs = kwargs.pop('DB_ARGS', {}) db.init(db_type = 'sqlite3', db_schema = 'weibo.db', db_host=False) if not os.path.isfile('weibo.db'): db.update('create table settings (id varchar(50) not null, value varchar(1000) not null, primary key(id))') db.update('create table users (id varchar(200) not null, name varchar(50) not null, image_url varchar(1000) not null, statuses_count bigint not null, friends_count bigint not null, followers_count bigint not null, verified bool not null, verified_type int not null, auth_token varchar(2000) not null, expired_time real not null, primary key(id))') return web.WSGIApplication(('urls',), document_root=os.path.dirname(os.path.abspath(__file__)), template_engine='jinja2', DEBUG=True)
def create_app(): db.init(db_type='mysql', db_schema='irunning', db_host='localhost', db_port=3306, db_user='******', db_password='******') return web.WSGIApplication( ('urls', ), document_root=os.path.dirname(os.path.abspath(__file__)), template_engine='jinja2', DEBUG=True)
def create_app(): cache.client = cache.RedisClient('localhost') db.init(db_type = 'mysql', \ db_schema = 'livestreaming', \ db_host = 'localhost', \ db_port = 3306, \ db_user = '******', \ db_password = '******', \ use_unicode = True, \ charset = 'utf8') return web.WSGIApplication(('static_handler', 'auth', 'manage'), \ document_root=os.path.dirname(os.path.abspath(__file__)), \ filters=(load_user, load_i18n), template_engine='jinja2', \ DEBUG=True)
def create_app(): # from conf import dbconf # kwargs = dict([(s, getattr(dbconf, s)) for s in dir(dbconf) if s.startswith('DB_')]) # dbargs = kwargs.pop('DB_ARGS', {}) db.init(db_type='mysql', db_schema='weibo', db_host='localhost', db_port=3306, db_user='******', db_password='') return web.WSGIApplication( ('urls', ), document_root=os.path.dirname(os.path.abspath(__file__)), template_engine='jinja2', DEBUG=True)
def create_app(debug): # init db: db.init(db_type='mysql', db_schema='shici', \ db_host='localhost', db_port=3306, \ db_user='******', db_password='******', \ use_unicode=True, charset='utf8') # init cache: cache.client = cache.MemcacheClient('localhost:11211') scan = ['apis'] if debug: scan.append('static_handler') return web.WSGIApplication(scan, \ document_root=os.path.dirname(os.path.abspath(__file__)), \ template_engine='jinja2', \ filters=(load_user,), \ DEBUG=debug)
def main(): if raw_input('To install iTranswarp, type Y and press ENTER: ') != 'Y': print 'Install cancelled.' exit(1) print 'Prepare to install iTranswarp...' try: print 'Checking Python version...', _check_version() print 'Checking Python Imaging Library...', _check_pil() print 'Checking Redis...', _check_redis() host = raw_input('Database host (localhost): ') port = raw_input('Database port (3306): ') user = raw_input('Database user (root): ') dbpass = raw_input('Database password: '******'': port = '3306' db.init(db_type='mysql', db_schema='itrans', \ db_host=host or 'localhost', db_port=int(port), \ db_user=user or 'root', db_password=dbpass, \ use_unicode=True, charset='utf8') print 'Creating tables . . .', for sql in CREATE_TABLES: if not sql.startswith('--'): db.update(sql) print '.', print '\nInit database ok.' email = raw_input('Super admin email: ').strip().lower() passwd = raw_input('Super admin password: '******'iTranswarp', 'localhost') if db.select_int('select count(*) from mysql.user where user=?', 'www-data') == 0: db.update( 'create user \'www-data\'@\'localhost\' identified by \'www-data\'' ) db.update( 'grant select,insert,update,delete on itrans.* to \'www-data\'@\'localhost\' identified by \'www-data\'' ) db.update('update users set role_id=0, passwd=? where email=?', passwd, email) print 'Install successfully!' except Exception, e: print 'Install failed:', e.message raise
def main(): if raw_input('To install iTranswarp, type Y and press ENTER: ')!='Y': print 'Install cancelled.' exit(1) print 'Prepare to install iTranswarp...' try: print 'Checking Python version...', _check_version() print 'Checking Python Imaging Library...', _check_pil() print 'Checking Redis...', _check_redis() host = raw_input('Database host (localhost): ') port = raw_input('Database port (3306): ') user = raw_input('Database user (root): ') dbpass = raw_input('Database password: '******'': port = '3306' db.init(db_type='mysql', db_schema='itrans', \ db_host=host or 'localhost', db_port=int(port), \ db_user=user or 'root', db_password=dbpass, \ use_unicode=True, charset='utf8') print 'Creating tables . . .', for sql in CREATE_TABLES: if not sql.startswith('--'): db.update(sql) print '.', print '\nInit database ok.' email = raw_input('Super admin email: ').strip().lower() passwd = raw_input('Super admin password: '******'iTranswarp', 'localhost') if db.select_int('select count(*) from mysql.user where user=?', 'www-data')==0: db.update('create user \'www-data\'@\'localhost\' identified by \'www-data\'') db.update('grant select,insert,update,delete on itrans.* to \'www-data\'@\'localhost\' identified by \'www-data\'') db.update('update users set role_id=0, passwd=? where email=?', passwd, email) print 'Install successfully!' except Exception, e: print 'Install failed:', e.message raise
def create_app(): configs = conf.configs debug = configs['debug'] logging.info('starting %s mode...' % ('DEBUG' if debug else 'PROD')) logging.info('db conf: %s' % str(configs['db'])) logging.info('cache conf: %s' % str(configs['cache'])) # init db: db.init(db_type='mysql', db_schema=configs['db']['schema'], \ db_host=configs['db']['host'], \ db_port=configs['db']['port'], \ db_user=configs['db']['user'], \ db_password=configs['db']['password'], \ use_unicode=True, charset='utf8') # init cache: cache.client = cache.MemcacheClient(configs['cache']['host']) scan = ['apps.article', 'apps.stpage', 'apps.wiki', 'apps.attachment', 'apps.navigation', 'apps.user', 'apps.comment', 'apps.setting', 'core.manage'] if debug: scan.append('static_handler') return web.WSGIApplication(scan, \ document_root=os.path.dirname(os.path.abspath(__file__)), \ filters=(load_user, ), \ template_engine='jinja2', \ DEBUG=debug)
from transwarp import db, task, urlfetch from transwarp.web import UTC, UTC_0 from apps.manage import upload_media from apps.article import do_get_categories import util from conf import dbconf kwargs = dict([(s, getattr(dbconf, s)) for s in dir(dbconf) if s.startswith('DB_')]) dbargs = kwargs.pop('DB_ARGS', {}) db.init(db_type=kwargs['DB_TYPE'], db_schema=kwargs['DB_SCHEMA'], db_host=kwargs['DB_HOST'], db_port=kwargs.get('DB_PORT', 0), db_user=kwargs.get('DB_USER'), db_password=kwargs.get('DB_PASSWORD'), **dbargs) def main(): uname, up = util.get_enabled_upload() t = task.fetch_task('import_post') if t: data = json.loads(t.task_data) pubDate = data['pubDate'] site = data['site'] content = data['content'] print site, content urls = _extract_link(content, site)
from transwarp import db, task, urlfetch from transwarp.web import UTC, UTC_0 from apps.manage import upload_media from apps.article import do_get_categories import util from conf import dbconf kwargs = dict([(s, getattr(dbconf, s)) for s in dir(dbconf) if s.startswith('DB_')]) dbargs = kwargs.pop('DB_ARGS', {}) db.init(db_type = kwargs['DB_TYPE'], db_schema = kwargs['DB_SCHEMA'], db_host = kwargs['DB_HOST'], db_port = kwargs.get('DB_PORT', 0), db_user = kwargs.get('DB_USER'), db_password = kwargs.get('DB_PASSWORD'), **dbargs) def main(): uname, up = util.get_enabled_upload() t = task.fetch_task('import_post') if t: data = json.loads(t.task_data) pubDate = data['pubDate'] site = data['site'] content = data['content'] print site, content urls = _extract_link(content, site) print urls
ss = setting.get_smtp_settings() conf = (ss[setting.SMTP_HOST], int(ss[setting.SMTP_PORT]), ss[setting.SMTP_USERNAME], ss[setting.SMTP_PASSWD], bool(ss[setting.SMTP_USE_TLS])) from_addr = ss[setting.SMTP_FROM_ADDR] to_addr = d['to'] try: mail.send_mail(conf, from_addr, d['to'], d['subject'], d['body']) except Exception, e: logging.exception('Send mail failed.') task.set_task_result(t['id'], t['execution_id'], False) else: task.set_task_result(t['id'], t['execution_id'], True, 'sent at %s' % datetime.now().strftime('%Y-%m-%d %H:%M:%S')) def cron_loop(): while True: time.sleep(10) try: cron_job() except BaseException, e: logging.exception('Cron error.') if __name__=='__main__': import conf_prod db.init(db_type = conf_prod.db.get('type', 'mysql'), \ db_schema = conf_prod.db.get('schema', 'itranswarp'), \ db_host = conf_prod.db.get('host', 'localhost'), \ db_port = conf_prod.db.get('port', 3306), \ db_user = conf_prod.db.get('user', 'www-data'), \ db_password = conf_prod.db.get('password', 'www-data'), \ use_unicode = True, charset = 'utf8') cron_loop()
def create_app(): db.init(db_type = 'mysql', db_schema = 'irunning', db_host = 'localhost', db_port = 3306, db_user = '******', db_password = '******') return web.WSGIApplication(('urls',), document_root=os.path.dirname(os.path.abspath(__file__)), template_engine='jinja2', DEBUG=True)
try: mail.send_mail(conf, from_addr, d['to'], d['subject'], d['body']) except Exception, e: logging.exception('Send mail failed.') task.set_task_result(t['id'], t['execution_id'], False) else: task.set_task_result( t['id'], t['execution_id'], True, 'sent at %s' % datetime.now().strftime('%Y-%m-%d %H:%M:%S')) def cron_loop(): while True: time.sleep(10) try: cron_job() except BaseException, e: logging.exception('Cron error.') if __name__ == '__main__': import conf_prod db.init(db_type = conf_prod.db.get('type', 'mysql'), \ db_schema = conf_prod.db.get('schema', 'itranswarp'), \ db_host = conf_prod.db.get('host', 'localhost'), \ db_port = conf_prod.db.get('port', 3306), \ db_user = conf_prod.db.get('user', 'www-data'), \ db_password = conf_prod.db.get('password', 'www-data'), \ use_unicode = True, charset = 'utf8') cron_loop()
def create_app(): # from conf import dbconf # kwargs = dict([(s, getattr(dbconf, s)) for s in dir(dbconf) if s.startswith('DB_')]) # dbargs = kwargs.pop('DB_ARGS', {}) db.init(db_type = 'mysql', db_schema = 'weibo', db_host = 'localhost', db_port = 3306, db_user = '******', db_password = '') return web.WSGIApplication(('urls',), document_root=os.path.dirname(os.path.abspath(__file__)), template_engine='jinja2', DEBUG=True)