• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python model.connect_db函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中model.connect_db函数的典型用法代码示例。如果您正苦于以下问题:Python connect_db函数的具体用法?Python connect_db怎么用?Python connect_db使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: __init__

 def __init__(self, params):
     self.params = params
     # load configuration
     model.load_config(params.config, basepath=params.path)
     # connect to database
     model.connect_db()
     # clear db
     model.ue.UE.drop_collection()
     model.location.Location.drop_collection()
     model.accesspoint.AccessPoint.drop_collection()
     # setup zero mq receiver
     self.setup_zmq()
     # load access point definitions from configuration file
     # and from remote AP manager component.
     # Deletes all current AP definitions at first.
     # If connection to remote AP manage API is not possible,
     # the system will run without any AP object and thus
     # no APs are assigned to UEs.
     model.accesspoint.AccessPoint.refresh(
         model.CONFIG["accesspoints"], ap_manager_client.get_accesspoints())
     # load management algorithm
     plugin.load_algorithms(
         model.CONFIG["algorithm"]["available"],
         model.CONFIG["algorithm"]["default"])
     # kick of AP state fetcher thread
     self.apFetcherThread = updater.AccessPointStateFetcher()
     self.apFetcherThread.start()
     # enable "always_on_macs" on all access points
     if "always_on_macs" in model.CONFIG:
         for mac in model.CONFIG["always_on_macs"].itervalues():
             ap_manager_client.set_mac_list(
                 mac, [ap.uuid for ap in model.accesspoint.AccessPoint.objects], [])
             logging.info("Enabled MAC %s on all APs." % str(mac))
开发者ID:mpeuster,项目名称:mt_backend,代码行数:33,代码来源:__init__.py


示例2: save_task

def save_task():
	title = request.form['title']
	db = model.connect_db()
	#Assume that all tasks are attached to user Christian Fernandez
	#task ID below
	task_id = model.new_task(db, title, 'Christian', 'Fernandez')
	return redirect("/tasks")
开发者ID:mmahnken,项目名称:Flask_to_do_list,代码行数:7,代码来源:tipsy.py


示例3: populate_sets_fans

def populate_sets_fans(batch):
    
    db = model.connect_db()

    for set_id, seo_title in batch:

        model.enter_new_sets_fans(db, set_id)
开发者ID:byslee3,项目名称:final_project_prep,代码行数:7,代码来源:seed_oldversion.py


示例4: list_of_unique_items

def list_of_unique_items(batch):

    # Make a tuple of the relevant sets to pass into the query
    relevant_sets = tuple([ b[0] for b in batch ])
    question_marks = ["?"] * len(relevant_sets)
    question_marks_string = ", ".join(question_marks)

    # Connecting to database
    db = model.connect_db()

    # Format and execute the SQL query
    query_template = """SELECT * FROM Sets_Items WHERE set_id IN (%s)"""
    query = query_template % (question_marks_string)
    result = db.execute(query, relevant_sets)
    
    # Get a list of records, where each item is a fan name
    list_of_item_ids = []
    list_of_item_seo_titles = []

    for row in result.fetchall():

        if not row[2] in list_of_item_ids:  # Check for duplicates
                                            # We need to delay zipping until the end b/c of this.

            list_of_item_ids.append(row[2])
            list_of_item_seo_titles.append(row[3])

    list_of_items = zip(list_of_item_ids, list_of_item_seo_titles)

    return list_of_items
开发者ID:byslee3,项目名称:final_project_prep,代码行数:30,代码来源:seed_oldversion.py


示例5: list_of_unique_fans

def list_of_unique_fans(batch):

    # Make a tuple of the relevant sets to pass into the query
    relevant_sets = tuple([ b[0] for b in batch ])
    question_marks = ["?"] * len(relevant_sets)
    question_marks_string = ", ".join(question_marks)

    # Connecting to database
    db = model.connect_db()

    # Format and execute the SQL query
    query_template = """SELECT * FROM Sets_Fans WHERE set_id IN (%s)"""
    query = query_template % (question_marks_string)
    result = db.execute(query, relevant_sets)
    
    # Get a list of records, where each item is a fan name
    list_of_fans = []

    for row in result.fetchall():

        if not row[3] in list_of_fans:   # Check for duplicates

            if not row[2] == "0":          # If fan_id is 0, means they don't have an actual account

                list_of_fans.append(row[3])

    return list_of_fans
开发者ID:byslee3,项目名称:final_project_prep,代码行数:27,代码来源:seed_oldversion.py


示例6: save_task

def save_task():
	task_title = request.form['task_title']
	user_id = request.form['user_id']
	db = model.connect_db()
# assume all tasks are attached to user 1 :(
	task_id = model.new_task(db, task_title, user_id)
	return redirect("/tasks")
开发者ID:jesslattif,项目名称:Hackbright-Curriculum,代码行数:7,代码来源:tipsy.py


示例7: login

def login():
	email = request.form['email']
	password = request.form['password']
	db = model.connect_db()
	auth_user = model.authenticate(db, email, password)
	if auth_user != None:
		return redirect("/Tasks")
开发者ID:Eleonore9,项目名称:Tipsy,代码行数:7,代码来源:tipsy.py


示例8: save_participant

def save_participant():
	participant_name = request.form['participant_name']
	number_entries = request.form['number_entries']
	db = model.connect_db()
	participant_id = model.new_participant(db, participant_name, number_entries)
	print participant_id
	return redirect("/the_lottery")
开发者ID:coderkat,项目名称:office_lottery,代码行数:7,代码来源:lottery.py


示例9: winners

def winners():
	db = model.connect_db()
	participants_from_db = model.get_participants(db)
	games_from_db = model.get_games(db)
	print participants_from_db

	entries = []

	for item in participants_from_db:
		entry = item['number_entries']
		person = item['participant_name']
		for i in range(entry):
			entries.append(person)
	random.shuffle(entries)
	
	games_list = []
	for game in games_from_db:
		games_list.append(game["game"])
	random.shuffle(games_list)

	decisions = {}
	a = 0
	while a < len(entries):
		if entries[a] in decisions:
			decisions[entries[a]].append(games_list[a])
		else:
			decisions[entries[a]] = [games_list[a]]
		a +=1
	print decisions



	return render_template("winners.html", winners = decisions)
开发者ID:coderkat,项目名称:office_lottery,代码行数:33,代码来源:lottery.py


示例10: sets_per_item

def sets_per_item():

    db = model.connect_db()
    query = """SELECT COUNT(set_id) from Items_Sets GROUP BY item_id"""
    result = db.execute(query)

    result_list = [  row[0] for row in result.fetchall()  ]

    # Create a histogram
    histogram = [0] * 23
    print histogram

    for num in result_list:
        if num <= 22:
            histogram[num] += 1
        elif num > 22:
            histogram[22] += 1

    print histogram

    # Print out the histogram
    for bucket in range(1, len(histogram)):
        if bucket <= 21:
            print "%d items <-----> belong to %d sets" % (histogram[bucket], bucket)
        elif bucket == 22:
            print "%d items <-----> belong to 22 or more sets" % histogram[bucket]

    # Check against total # of Items_Sets records by doing SumProduct
    sum_p = 0
    for bucket in range(1, len(histogram)):
        sum_p += bucket * histogram[bucket]

    print sum_p

    db.close()
开发者ID:byslee3,项目名称:final_project_prep,代码行数:35,代码来源:seed.py


示例11: new_user

def new_user():
    user_name= request.form['user_name']
    email= request.form['user_email']
    db = model.connect_db()
    #new_user(db, email, password, name)
    user_id = model.new_user(db, email, None, user_name)
    return redirect("/new_task")
开发者ID:ArcTanSusan,项目名称:Task_List,代码行数:7,代码来源:tipsy.py


示例12: print_overlap

def print_overlap():

    db = model.connect_db()

    # Creates a table with 2 columns -- (a) fan_name (b) num out of 5 sets in batch_1 that they fanned
    cursor = db.execute("SELECT fan_name, COUNT(fan_name) FROM Sets_Fans GROUP BY fan_name")

    # Doing the rest in Python instead of SQL for now --> need to look up how to query the result of a query
    total_fans = 0.0
    sets_rated_by_each_fan = ["Not Applicable", 0.0, 0.0, 0.0, 0.0, 0.0]

    for row in cursor.fetchall():

        number_rated = row[1]
        sets_rated_by_each_fan[number_rated] += 1

        total_fans += 1

    # Transform frequency counts into percentages

    print "LEVEL OF OVERLAP"
    print "Out of " + str(int(total_fans)) + " total fans who rated 5 'Popular' sets"
    print "--------------------------------------------------"

    for x in range(1,6):
        percentage = int(round(sets_rated_by_each_fan[x]/total_fans*100))
        print str(int(sets_rated_by_each_fan[x])) + " out of " + str(int(total_fans)) + " -- (" + str(percentage) + "%) -- rated " + str(x) + " out of 5 sets"

    db.close()
开发者ID:byslee3,项目名称:final_project_prep,代码行数:29,代码来源:seed.py


示例13: populate_items

def populate_items(item_list, level):

    db = model.connect_db()

    successfully_entered = 0.0
    no_file_error = 0.0

    for item_id, item_seo_title in item_list:

        try:

            model.enter_new_item(db, item_id, level)
            print item_id
            successfully_entered += 1

        except:

            print "++++++++++++++++++++++++++"
            print "couldn't find file"
            print item_id
            print item_seo_title
            print "++++++++++++++++++++++++++"

            no_file_error += 1

    print "Successfully entered: " + str(successfully_entered)
    print "Errors: " + str(no_file_error)
    print "Error rate: " + str(round(no_file_error / successfully_entered * 100, 2)) + "%"

    db.close()
开发者ID:byslee3,项目名称:final_project_prep,代码行数:30,代码来源:seed.py


示例14: list_tasks

def list_tasks():
	db = model.connect_db()
	tasks_from_db = model.get_tasks(db, None)
	completed_items = request.form.getlist("completed_t_f", type=int)
	if completed_items:
		for task in completed_items:
			model.complete_task(db, task)

	return render_template("tasks.html", tasks_field = tasks_from_db)
开发者ID:cadeParade,项目名称:Hackbright-class-projects,代码行数:9,代码来源:tipsy.py


示例15: list_tasks

def list_tasks():
  db = model.connect_db()
  tasks_from_db = model.get_tasks(db, None)
  user_id_list = []
  for dictionary in tasks_from_db:
    user_id_list.append(dictionary["user_id"])
  for user_id in user_id_list:
    users_from_db = model.get_user(db, user_id)
  return render_template("list_tasks.html", tasks=tasks_from_db,users=users_from_db)
开发者ID:aahluwal,项目名称:flask2,代码行数:9,代码来源:tipsy.py


示例16: authenticate

def authenticate():
    db = model.connect_db()
    email = request.form['email']
    password = request.form['password']
    user_info = model.authenticate(db, email, password)
    if user_info == None:
        return redirect('/')
    else:
        return redirect('/tasks')
开发者ID:ericachang018,项目名称:tipsy,代码行数:9,代码来源:tipsy.py


示例17: populate_items_sets

def populate_items_sets(list_of_ids):

    db = model.connect_db()

    for item_id in list_of_ids:

        model.enter_new_items_sets(db, item_id)

    db.close()
开发者ID:byslee3,项目名称:final_project_prep,代码行数:9,代码来源:seed.py


示例18: unique_records_twocol

def unique_records_twocol(table, col1, col2, level):

    # Format and execute the SQL query
    db = model.connect_db()
    query_template = """SELECT DISTINCT (%s), (%s) FROM (%s) WHERE level = (%d)""" 
    query = query_template % (col1, col2, table, level)
    result = db.execute(query)

    # Get a list of records and return it
    list_of_items = [ row for row in result.fetchall() ]
    db.close()
    return list_of_items
开发者ID:byslee3,项目名称:final_project_prep,代码行数:12,代码来源:seed.py


示例19: get_list_1

def get_list_1():

    list_of_tups = []

    db = model.connect_db()
    query = """SELECT DISTINCT set_id, set_seo_title, set_imgurl FROM Items_Sets"""
    result = db.execute(query)

    result_list = [  row for row in result.fetchall()  ]
    
    db.close()

    return result_list
开发者ID:byslee3,项目名称:final_project_prep,代码行数:13,代码来源:seed.py


示例20: list_of_unique_sets

def list_of_unique_sets(level):

    """ Return a list of unique sets as (set_id, set_seo_title) which will be passed to create_file function """

    # Format and execute the SQL query
    db = model.connect_db()
    query = """SELECT DISTINCT set_id, set_seo_title FROM Items_Sets WHERE level = ?"""
    result = db.execute(query, (level,))

    # Get a list of records and return it
    list_of_sets = [ row for row in result.fetchall() ]
    db.close()
    return list_of_sets
开发者ID:byslee3,项目名称:final_project_prep,代码行数:13,代码来源:seed.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python model.connect_to_db函数代码示例发布时间:2022-05-27
下一篇:
Python model.connect函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap