当前位置: 首页>>代码示例>>Python>>正文


Python config.db方法代码示例

本文整理汇总了Python中config.db方法的典型用法代码示例。如果您正苦于以下问题:Python config.db方法的具体用法?Python config.db怎么用?Python config.db使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在config的用法示例。


在下文中一共展示了config.db方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: check_db_sane

# 需要导入模块: import config [as 别名]
# 或者: from config import db [as 别名]
def check_db_sane():
    """ Ensure DB tables exist, create them if they don't. """
    check_db_schema_version()

    missing_table_models = []

    for model in db_models():
        if not getattr(model, 'table_exists')():
            missing_table_models.append(model)
            printdbg("[warning]: Table for %s (%s) doesn't exist in DB." % (model, model._meta.db_table))

    if missing_table_models:
        printdbg("[warning]: Missing database tables. Auto-creating tables.")
        try:
            db.create_tables(missing_table_models, safe=True)
        except (peewee.InternalError, peewee.OperationalError, peewee.ProgrammingError) as e:
            print("[error] Could not create tables: %s" % e)

    update_schema_version()
    purge_invalid_amounts() 
开发者ID:dashpay,项目名称:sentinel,代码行数:22,代码来源:models.py

示例2: check_db_schema_version

# 需要导入模块: import config [as 别名]
# 或者: from config import db [as 别名]
def check_db_schema_version():
    """ Ensure DB schema is correct version. Drop tables if not. """
    db_schema_version = None

    try:
        db_schema_version = Setting.get(Setting.name == 'DB_SCHEMA_VERSION').value
    except (peewee.OperationalError, peewee.DoesNotExist, peewee.ProgrammingError) as e:
        printdbg("[info]: Can't get DB_SCHEMA_VERSION...")

    printdbg("[info]: SCHEMA_VERSION (code) = [%s]" % SCHEMA_VERSION)
    printdbg("[info]: DB_SCHEMA_VERSION = [%s]" % db_schema_version)
    if (SCHEMA_VERSION != db_schema_version):
        printdbg("[info]: Schema version mis-match. Syncing tables.")
        try:
            existing_table_names = db.get_tables()
            existing_models = [m for m in db_models() if m._meta.db_table in existing_table_names]
            if (existing_models):
                printdbg("[info]: Dropping tables...")
                db.drop_tables(existing_models, safe=False, cascade=False)
        except (peewee.InternalError, peewee.OperationalError, peewee.ProgrammingError) as e:
            print("[error] Could not drop tables: %s" % e) 
开发者ID:dashpay,项目名称:sentinel,代码行数:23,代码来源:models.py

示例3: is_database_correctly_configured

# 需要导入模块: import config [as 别名]
# 或者: from config import db [as 别名]
def is_database_correctly_configured():
    import peewee
    import config

    configured = False

    cannot_connect_message = "Cannot connect to database. Please ensure database service is running and user access is properly configured in 'sentinel.conf'."

    try:
        db = config.db
        db.connect()
        configured = True
    except (peewee.ImproperlyConfigured, peewee.OperationalError, ImportError) as e:
        print("[error]: %s" % e)
        print(cannot_connect_message)
        sys.exit(1)

    return configured 
开发者ID:dashpay,项目名称:sentinel,代码行数:20,代码来源:init.py

示例4: get_urls

# 需要导入模块: import config [as 别名]
# 或者: from config import db [as 别名]
def get_urls(self):
    # fills in URLs for papers that are for some reason missing them. Determines URLs
    # by resolving the DOI.
    self.log.record('Fetching URLs for papers without them', 'info')
    to_save = []
    with self.connection.db.cursor() as cursor:
      cursor.execute(f"SELECT id, doi FROM {config.db['schema']}.articles WHERE url IS NULL OR url='';")
      for x in cursor:
        try:
          r = requests.get(f"https://doi.org/{x[1]}", timeout=10)
        except Exception as e:
          self.log.record(f'Problem resolving DOI: {e}', 'error')
          continue
        if r.status_code != 200:
          self.log.record(f"Got weird status code resolving DOI {x[1]}: {r.status_code}", "error")
          continue
        to_save.append((r.url, x[0]))
        self.log.record(f'Found URL for {x[0]}: {r.url}', 'debug')
    with self.connection.db.cursor() as cursor:
      self.log.record(f'Saving {len(to_save)} URLS.', 'info')
      cursor.executemany(f"UPDATE {config.db['schema']}.articles SET url=%s WHERE id=%s;", to_save) 
开发者ID:blekhmanlab,项目名称:rxivist,代码行数:23,代码来源:spider.py

示例5: activate_tables

# 需要导入模块: import config [as 别名]
# 或者: from config import db [as 别名]
def activate_tables(self, table):
    self.log.record(f"Activating tables for {table}", 'debug')
    queries = [
      f"ALTER TABLE {table} RENAME TO {table}_temp",
      f"ALTER TABLE {table}_working RENAME TO {table}",
      f"ALTER TABLE {table}_temp RENAME TO {table}_working"
    ]
    to_delete = f"{table}_working.csv"
    with self.connection.db.cursor() as cursor:
      for query in queries:
        cursor.execute(query)
    if config.delete_csv == True:
      self.log.record(f"Deleting {to_delete}", 'debug')
      try:
        os.remove(to_delete)
      except Exception as e:
        if to_delete not in [ # HACK These aren't there on the last loop
          'category_ranks_working.csv',
          'author_ranks_category_working.csv'
        ]:
          self.log.record(f"Problem deleting {to_delete}: {e}", "warn") 
开发者ID:blekhmanlab,项目名称:rxivist,代码行数:23,代码来源:spider.py

示例6: fill_in_author_vectors

# 需要导入模块: import config [as 别名]
# 或者: from config import db [as 别名]
def fill_in_author_vectors(self):
    self.log.record("Filling in empty author_vector fields.", 'debug')
    article_ids = []
    with self.connection.db.cursor() as cursor:
      cursor.execute("SELECT id FROM articles WHERE author_vector IS NULL;")
      for record in cursor:
        if len(record) > 0:
          article_ids.append(record[0])

    to_do = len(article_ids)
    if to_do > 0:
      self.log.record(f"Obtained {to_do} article IDs.", 'debug')
    with self.connection.db.cursor() as cursor:
      for article in article_ids:
        author_string = ""
        cursor.execute("SELECT authors.name FROM article_authors as aa INNER JOIN authors ON authors.id=aa.author WHERE aa.article=%s;", (article,))
        for record in cursor:
          author_string += f"{record[0]}, "
        cursor.execute(f"UPDATE {config.db['schema']}.articles SET author_vector=to_tsvector(coalesce(%s,'')) WHERE id=%s;", (author_string, article))
        to_do -= 1
        # if to_do % 100 == 0:
        #   self.log.record(f"{datetime.now()} - {to_do} left to go.", 'debug') 
开发者ID:blekhmanlab,项目名称:rxivist,代码行数:24,代码来源:spider.py

示例7: __init__

# 需要导入模块: import config [as 别名]
# 或者: from config import db [as 别名]
def __init__(self, host, db, user, password):
    dbname = db
    self.db = None
    self._ensure_database_exists(dbname, host, user, password)

    self.db = psycopg2.connect(
      host=host,
      dbname=dbname,
      user=user,
      password=password,
      options=f'-c search_path={config.db["schema"]}'
    )
    self.db.set_session(autocommit=True)
    self.cursor = self.db.cursor()

    self._ensure_tables_exist() 
开发者ID:blekhmanlab,项目名称:rxivist,代码行数:18,代码来源:db.py

示例8: createTable

# 需要导入模块: import config [as 别名]
# 或者: from config import db [as 别名]
def createTable(boardid, big=""):
    """
    建表函数 需要传入板块id 和 大表前缀("big"或""),尝试进行建表sql语句,忽视错误(如表已经存在)
    :param boardid: 板块id,如"100"
    :param big: 传入空字符串表示普通表如bbs_100,传入"big"表示历史大表 如bigbbs_100
    :return:
    """
    sql = """
CREATE TABLE `{big}bbs_{boardid}` (
  `id` int(11) NOT NULL,
  `lc` int(255) NOT NULL,
  `posttime` datetime NOT NULL,
  `edittime` datetime NOT NULL,
  `user` varchar(66) NOT NULL,
  `content` longtext NOT NULL,
  `gettime` datetime NOT NULL,
  PRIMARY KEY (`id`,`lc`,`edittime`,`posttime`,`user`),
  KEY `a1` (`posttime`),
  KEY `a2` (`user`),
  KEY `a3` (`gettime`),
  KEY `a4` (`id`),
  KEY `a5` (`lc`),
  KEY `a6` (`edittime`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
""".format(big=big, boardid=boardid)
    global conn
    conn = db()  # 强制重新与数据库重新连接 TODO: 是否有必要?
    cur = conn.cursor()
    try:
        cur.execute(sql)
        conn.commit()
    except:
        pass
    conn = db() 
开发者ID:zjuchenyuan,项目名称:cc98,代码行数:36,代码来源:xinling.py

示例9: runsql

# 需要导入模块: import config [as 别名]
# 或者: from config import db [as 别名]
def runsql():
    global conn
    conn=db()
    cur = conn.cursor()
    cur.execute(sql)
    conn.commit() 
开发者ID:zjuchenyuan,项目名称:cc98,代码行数:8,代码来源:getBoardId.py

示例10: getworkset

# 需要导入模块: import config [as 别名]
# 或者: from config import db [as 别名]
def getworkset():
    conn=db()
    workset=[]
    for i in rawlist2:
        try:
            runsql("desc bigbbs_{}".format(i))
        except:#表不存在就说明我要get咯,加入workset
            workset.append(i)
    return(workset) 
开发者ID:zjuchenyuan,项目名称:cc98,代码行数:11,代码来源:getBoardId.py

示例11: runsql

# 需要导入模块: import config [as 别名]
# 或者: from config import db [as 别名]
def runsql(sql):
    global conn
    conn=db()
    cur = conn.cursor()
    try:
        cur.execute(sql)
        conn.commit()
    except Exception as e:
        print("Error:")
        print(e) 
开发者ID:zjuchenyuan,项目名称:cc98,代码行数:12,代码来源:update_big_data.py

示例12: search

# 需要导入模块: import config [as 别名]
# 或者: from config import db [as 别名]
def search():
	s_tag = request.form.get('search_url')
	if s_tag == "":
		return render_template('index.html', error = "Please enter a search term")
	else:
		conn = MySQLdb.connect(host , user , passwrd, db)
		cursor = conn.cursor()
		
		search_tag_sql = "SELECT * FROM WEB_URL WHERE TAG = %s" 
		cursor.execute(search_tag_sql , (s_tag, ) )
		search_tag_fetch = cursor.fetchall()
		conn.close()
		return render_template('search.html' , host = shorty_host , search_tag = s_tag , table = search_tag_fetch ) 
开发者ID:highoncarbs,项目名称:shorty,代码行数:15,代码来源:app.py

示例13: list_data

# 需要导入模块: import config [as 别名]
# 或者: from config import db [as 别名]
def list_data(shorty_url):
	
	"""
		Takes short_url for input.
		Returns counter , browser , platform ticks. 
	"""
	conn = MySQLdb.connect(host , user , passwrd, db)
	cursor = conn.cursor()
	su =[shorty_url]
	info_sql = "SELECT URL , S_URL ,TAG FROM WEB_URL WHERE S_URL= %s; "
	counter_sql = "SELECT COUNTER FROM WEB_URL WHERE S_URL= %s; "
	browser_sql = "SELECT CHROME , FIREFOX , SAFARI, OTHER_BROWSER FROM WEB_URL WHERE S_URL =%s;"
	platform_sql = "SELECT ANDROID , IOS , WINDOWS, LINUX , MAC , OTHER_PLATFORM FROM WEB_URL WHERE S_URL = %s;"	
	
	
	# MySQLdb's execute() function expects a list
	# of objects to be converted so we use [arg ,]
	# But for sqlite ( args,) works. 
	
	
	cursor.execute(info_sql , su)
	info_fetch = cursor.fetchone()
	cursor.execute(counter_sql , su)
	counter_fetch = cursor.fetchone()
	cursor.execute(browser_sql,su)
	browser_fetch = cursor.fetchone()
	cursor.execute(platform_sql, su)
	platform_fetch = cursor.fetchone()
	conn.close()
	return info_fetch , counter_fetch , browser_fetch , platform_fetch 
开发者ID:highoncarbs,项目名称:shorty,代码行数:32,代码来源:display_list.py

示例14: is_database_connected

# 需要导入模块: import config [as 别名]
# 或者: from config import db [as 别名]
def is_database_connected(self):
        return not db.is_closed() 
开发者ID:dashpay,项目名称:sentinel,代码行数:4,代码来源:models.py

示例15: __init__

# 需要导入模块: import config [as 别名]
# 或者: from config import db [as 别名]
def __init__(self, **kwargs):
        # We creating a new Deposit, the depositid is not known (db autoincrement)
        self.depositid = kwargs.get('depositid', 0)
        self.date = kwargs.get('date', date.today().isoformat())
        self.username = kwargs.get('username', '')
        self.amount = int(kwargs.get('amount'))
        self.method = kwargs.get('method', '')
        self.vsk = kwargs.get('vsk', 0.0)  # percentage
        self.fees = int(kwargs.get('fees', 0))  # amount in isk :/ 
开发者ID:benediktkr,项目名称:lokun-record,代码行数:11,代码来源:model.py


注:本文中的config.db方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。