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

Python session.add函数代码示例

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

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



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

示例1: exec_global

    def exec_global(self, request):
        """
        Execute a global-scoped command.
        """

        command = request["command"]

        if command == "go back to perm":
            liq.set_var("selected", "perm")
            liq.send_command("perm-switch.skip")

            self.send_feedback(request)

        elif command == "rescan":
            result = Utilities.rescan()
            self.send_feedback(request, result)

        elif command == "select":
            studio = session.query(Studio).find_by(slug=request["studio"].decode('utf-8'))

            if studio is not None:
                studio.selected = True
                session.add(studio)
                session.commit()
                liq.set_var("selected", str(studio.slug))
                sylog("INFO: Selecting " + studio.slug)
                self.send_feedback(request)
            else:
                self.send_feedback(request, "error", "Unknown studio %s" % request["studio"])
开发者ID:synopslive,项目名称:sydroid,代码行数:29,代码来源:Control.py


示例2: item_edit

def item_edit(item_title):
    categories = session.query(Category).all()
    item = session.query(Item).filter_by(
        title=item_title).one()
    user = session.query(User).filter_by(
        id=login_session.get('user_id')).one()
    if item.user is not None and item.user.id != user.id:
        return redirect(url_for('home'))
    if request.method == 'POST':
        form = vh.ItemForm(request.form, item)
        file_storage_err = vh.store_item_pic(
            item, request.files['picture'])
        if (not form.validate() or file_storage_err is not None):
            return render_template('item_edit.html',
                                   form=form,
                                   file_err=file_storage_err)
        form.populate_obj(item)
        try:
            session.add(item)
            session.commit()
        except ValueError as e:
            return "Database validation error: " + str(e)
        except SQLAlchemyError as e:
            # todo: log error, but don't display detailed message
            # for security reasons
            return "Database error: " + str(e)
        return redirect(url_for('home'))
    else:
        form = vh.ItemForm(obj=item)
        return render_template('item_edit.html',
                               form=form,
                               file_err=None)
开发者ID:ransomw,项目名称:udacity-fsnd-p3,代码行数:32,代码来源:views.py


示例3: recieve_message

def recieve_message():
    try:
        message = request.form.get('message')
        json_resp = False
        if not message:
            message = request.get_json()['message']
            json_resp = True

        message_data = Message(message=message)
        session.add(message_data)
        session.commit()

        if json_resp:
            resp = {
                'status': 'success',
                'message': message
            }
            return jsonify(**resp)
        else:
            return redirect(url_for('dashboard'))


    except Exception as e:
        resp = {
            'status': 'failed',
            'error': str(e)
        }

        return jsonify(**resp)
开发者ID:yashmehrotra,项目名称:HE-Task-1,代码行数:29,代码来源:app.py


示例4: addEdit

    def addEdit(self, _thread_id, _content, _submitted=False):
        existingList = (
            session.query(bot_comments_anetpool)
            .filter_by(thread_id=_thread_id)
            .order_by(desc(bot_comments_anetpool.edit_id))
            .first()
        )

        if existingList is None:
            row = bot_comments_anetpool()
            row.thread_id = _thread_id
            _from_template = self.anetpool_template.split("	", 1)
            row.content = _from_template[0] + _content + "	" + _from_template[1]
            row.submitted = _submitted
            session.add(row)
        else:
            if len(existingList.content) + len(_content) >= 10000:
                row = bot_comments_anetpool()
                row.thread_id = _thread_id
                _from_template = self.anetpool_template.split("	", 1)
                row.content = _from_template[0] + _content + "	" + _from_template[1]
                row.submitted_id = "e" + str(existingList.edit_id)
                row.submitted = _submitted
                session.add(row)
            else:
                _from_save = existingList.content.split("	", 1)
                session.query(bot_comments_anetpool).filter_by(edit_id=existingList.edit_id).update(
                    {"content": _from_save[0] + _content + "	" + _from_save[1], "submitted": False}
                )
        session.commit()
开发者ID:networkjanitor,项目名称:polarbytebot,代码行数:30,代码来源:polarbytebot.py


示例5: add_comment

 def add_comment(self, _thing_id, _content, _submitted=False, _signature=None):
     if _signature is None:
         _signature = self.signature
     last_id = _thing_id
     extra_len = len("\n\n--- continued below ---") + len(_signature)
     while True:
         if len(_content) <= 0:
             return
         content_parts = _content.split("\n")
         stiched_content = ""
         for part in content_parts:
             if len(stiched_content) + len(part + "\n") + extra_len <= 10000:
                 stiched_content += part + "\n"
             else:
                 break
         row = bot_comments()
         row.thing_id = last_id
         row.submitted = _submitted
         if _content[len(stiched_content) :] == "":
             row.content = stiched_content + _signature
         else:
             row.content = stiched_content + "\n\n--- continued below ---" + _signature
         session.add(row)
         session.commit()
         last_id = "i{}".format(session.query(bot_comments).order_by(desc(bot_comments.id)).first().id)
         _content = _content[len(stiched_content) :]
开发者ID:networkjanitor,项目名称:polarbytebot,代码行数:26,代码来源:polarbytebot.py


示例6: insert_test

def insert_test():
    tom = Teacher(name='Tom', subject='Physics')
    session.add(tom)
    session.commit()
    lucy = Student(name='Lucy', head_teacher_id=tom.id)
    session.add(lucy)
    session.commit()
开发者ID:EmuxEvans,项目名称:py_learn,代码行数:7,代码来源:test.py


示例7: add_admin

def add_admin(emailormobile):
    user = session.query(User).filter(or_(User.email == emailormobile,User.mobile == emailormobile)).first()
    if not user:
        raise
    admin = Admin(admin_id = ut.create_admin_id(),user_id = user.user_id,created = time.time()*1000,updated = time.time()*1000)
    session.add(admin)
    session.commit()
开发者ID:realjade,项目名称:match,代码行数:7,代码来源:shell.py


示例8: addToDatabase

def addToDatabase(parent, subtree, i):

    subComments = subtree["data"]["children"]
    if len(subComments) == 0:
        pass
        # print "List EMPTY"
    w = 0
    for j in subComments:
        comment = Comment()
        comment.reddit_id = j["data"]["id"]
        comment.text = j["data"]["body"]
        comment.user_name = j["data"]["author"]
        comment.upvotes = int(j["data"]["ups"])
        comment.downvotes = j["data"]["downs"]
        comment.date_of_last_sweep = datetime.now()
        comment.parent = parent
        comment.post_id = parent.post_id
        session.add(comment)
        if j["data"]["replies"] == "":
            comment.weight = comment.upvotes
            # print "Dict Empty"
            # print type(j["data"]["replies"])

        else:
            addToDatabase(comment, j["data"]["replies"], i + 1)
            comment.weight = comment.weight + comment.upvotes
        w = comment.weight + w
    parent.weight = w

    """
开发者ID:NSkelsey,项目名称:reddit_sweep,代码行数:30,代码来源:comments.py


示例9: load_baskets

def load_baskets(session):
	user = 1
	basket_names = ["Example 1"]
	for name in basket_names:
		name = models.Baskets(name=name)
		session.add(name)
	session.commit()
开发者ID:bessiec,项目名称:SNAPBasket,代码行数:7,代码来源:seed.py


示例10: message_good

def message_good(form):
    global __HEXDIGEST__
    _json = json.dumps(form.to_dict())
    mess = EmailMessage(_json)
    mess.hexdigest = __HEXDIGEST__
    session.add(mess)
    session.commit()
开发者ID:NSkelsey,项目名称:verdant,代码行数:7,代码来源:app.py


示例11: get_page_links1

def get_page_links1(webUrl):
    '''
        Description: get images' first layer links
    '''
    init_db()
    htmlContent = requests.get(webUrl, headers=headers)
    soup = BeautifulSoup(htmlContent.text, "html.parser")
    wp_page_numbers_div = soup.find("div", {"id":"wp_page_numbers"})
    endPageTag = wp_page_numbers_div.find_all("a")[-1]
    endPageLink = endPageTag.get('href')
    if endPageLink: 
        regex = r"(\D+\d+\D+)(\d+)(\D+)"
        m = re.match(regex, endPageLink)
        if m:
            pageNumber = int(m.groups()[1])  #get page number
            for index in xrange(1, pageNumber+1):
                pageLink = "%s"*4 %(webUrl, m.group(1), index, m.group(3))
                #pageLinks.append(pageLink)
                page_link1_queue.put(pageLink)
                query = session.query(FirstLevelLinks)
                query_result = query.filter(FirstLevelLinks.url==pageLink).first()
                if query_result:
                    continue 
                else:
                    first_level_links = FirstLevelLinks(url=pageLink)
                    session.add(first_level_links)
            session.flush()
            session.commit()
            return page_link1_queue
        else:
            return None
开发者ID:zhengze,项目名称:imagecrawler,代码行数:31,代码来源:crawler.py


示例12: mod

def mod():
    global __HEXDIGEST__
    if request.method == "GET":
        mess = session.query(EmailMessage).get(__HEXDIGEST__)
        if mess is None or mess.approved == True:
            flash('No new messages to edit')
            return render_template('edit.html')
        dct = json.loads(mess.everything)
        form = EditForm()
        form.subject.data = dct.get('subject')
        form.text.data = dct.get('body-plain')
        form.approved.data = mess.approved
        return render_template('edit.html', form=form) 
    else:
        form = EditForm(request.form)
        mess = session.query(EmailMessage).get(__HEXDIGEST__)
        if form.approved.data == True:
            send_message(form.data)
            mess.approved = True
            session.add(mess)
            session.commit()
            flash('message sent')
            return render_template('edit.html')
        flash("bad form")
        return "bad form"
开发者ID:NSkelsey,项目名称:verdant,代码行数:25,代码来源:app.py


示例13: websocket_to_database

def websocket_to_database():
    try:
        websocket = yield from websockets.connect("wss://ws-feed.exchange.coinbase.com")
    except gaierror:
        db_logger.error('socket.gaierror - had a problem connecting to Coinbase feed')
        return
    yield from websocket.send('{"type": "subscribe", "product_id": "BTC-USD"}')
    while True:
        message = yield from websocket.recv()
        if message is None:
            file_logger.error('Websocket message is None!')
            break
        try:
            message = json.loads(message)
        except TypeError:
            db_logger.error('JSON did not load, see ' + str(message))
            continue
        if message['type'] != 'match':
            continue
        new_message = Messages()
        for key in message:
            if hasattr(new_message, key):
                setattr(new_message, key, message[key])
            else:
                db_logger.error(str(key) + ' is missing, see ' + str(message))
                continue
        try:
            session.add(new_message)
            session.commit()
        except IntegrityError:
            session.rollback()
        except DatabaseError:
            file_logger.error('Database Error')
            session.rollback()
开发者ID:PierreRochard,项目名称:big-dipper,代码行数:34,代码来源:websocket_feed.py


示例14: get_whole_page_content

def get_whole_page_content(amount):
	'''
	get_whold_page_content()
	amount : get_page_amount()
	return : write sqlite
	'''
	count = 0
	for page_num in range(1, amount+1):
		print u'Scraping page <%3d>...' % page_num


		url = build_url(page_num)

		print u'Now in: %s' % url

		# get page_content
		content_lst = get_content_from_page(url)

		print u'Get <%3d> pices from this page.\n' % len(content_lst)

		for author, content in content_lst:
			content_obj = Hot(author=author, content=content)
			session.add(content_obj)
			count += 1

		if count >= 100:
			session.commit()
			count = 0

		# couldn't be too soon
		time.sleep(3)

	session.commit()
	return 
开发者ID:glrh111,项目名称:python-features,代码行数:34,代码来源:spider.py


示例15: get_page_links2

def get_page_links2():
    '''
        Description: get images' second layer links
    '''
    pageLink = page_link1_queue.get()
    print "page links2 process id:%s" %os.getpid()
    print "Starting to crawl : %s" %pageLink
    if pageLink:
        #picture_urls = []  
        response = requests.get(pageLink, headers=headers) 
        soup = BeautifulSoup(response.text, "html.parser")
        picture_divs = soup.find_all("div", {"class":"pic"})
        for picture_div in picture_divs:
            picture_url = picture_div.find("a").get("href")
            page_link2_queue.put(picture_url)
            #picture_urls.append(picture_url)

            query = session.query(SecondLevelLinks)
            query_result = query.filter(SecondLevelLinks.url==picture_url).first()
            if query_result:
                continue
            else:
                second_level_links = SecondLevelLinks(url=picture_url)
                session.add(second_level_links)
        session.flush()
        session.commit()

        return page_link2_queue
    else:
        return None
开发者ID:zhengze,项目名称:imagecrawler,代码行数:30,代码来源:crawler.py


示例16: load_playlists

def load_playlists(session):
    user = 1
    playlist_titles = ["Narrative Shorts", "Something Different", "Hellbent Sports", "Documentaries"]
    for title in playlist_titles:
        playlist = models.Playlists(title=title, user_id=user)
        session.add(playlist)
    session.commit()
开发者ID:bessiec,项目名称:PlayShortFlix-Hackbright-Project,代码行数:7,代码来源:seed.py


示例17: guildwars2_filter_cm

def guildwars2_filter_cm(comments, array_anet_names):
    for cm in comments:
        logging.info("comment")
        if cm.author.name in array_anet_names:
            logging.info("comment from anet: " + cm.name)
            row = bot_submissions()
            title = cm.link_title
            if (len(title) + len(cm.author.name) + 3) > 300:
                title = title[: 300 - len(cm.author.name) - 3 - 3]
                title += "..."
            row.title = title + " [" + cm.author.name + "]"
            row.type = "link"
            row.subreddit = "gw2devtrack"
            row.submitted = False
            row.content = cm.permalink.replace("//www.reddit.com", "//np.reddit.com") + "?context=1000"
            session.add(row)
        continue  # DISALLOWS COMMENTS TO BE PARSED FPR GW2 LINKS
        if re.search("http.*?:\/\/.*?guildwars2.com\/", cm.body) != None:
            logging.info("comment with gw2 link: " + cm.name)
            all_links = re.findall("http.*?:\/\/.*?guildwars2.com\/[^ \])\s]*", cm.body)
            for link in all_links:
                if link != "":
                    try:
                        prepare_comment(cm.name, False, guildwars2.locate_origin(link))
                    except Exception as e:
                        logging.error(e)
                        session.rollback()
                    else:
                        session.commit()
开发者ID:networkjanitor,项目名称:polarbytebot,代码行数:29,代码来源:polarbytebot_legacy.py


示例18: task_retailers

 def task_retailers(self, grab, task):
     lines = grab.xpath_list('//div[@class="merch-full"]/a')
     for line in lines:
         title = line[1].text_content()
         cost = line[2].text_content().strip()
         data = Data(site_name=task.site_name, title=title.encode('utf-8'), cost=cost.encode('utf-8'))
         session.add(data)
     session.commit()
开发者ID:EvilDmitri,项目名称:jasper_first-ever_grabber,代码行数:8,代码来源:grabber.py


示例19: saveOneRow

    def saveOneRow(self):
        data = Data(description=self.description.encode('utf-8'), link=self.link, stock=self.inStock.encode('utf-8'),
                    shipping=self.shipping.encode('utf-8'), price=self.price.encode('utf-8'),
                    mail_rebate=self.rebate.encode('utf-8'), instant_rebate=self.instantRebate.encode('utf-8'),
                    final_price=self.finalPrice.encode('utf-8'), item_number=self.itemNo.encode('utf-8'))

        session.add(data)
        session.commit()
开发者ID:EvilDmitri,项目名称:jasper_NeweggGrabber,代码行数:8,代码来源:newegg_scrape.py


示例20: task_shop

 def task_shop(self, grab, task):
     lines = grab.xpath_list('//div[@id="allStores"]/ul/li/a')
     for line in lines:
         title = line.text_content()
         cost = line.tail.strip()
         data = Data(site_name=task.site_name, title=title.encode('utf-8'), cost=cost.encode('utf-8'))
         session.add(data)
     session.commit()
开发者ID:EvilDmitri,项目名称:jasper_first-ever_grabber,代码行数:8,代码来源:grabber.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python session.commit函数代码示例发布时间:2022-05-27
下一篇:
Python services.getSearchEpg函数代码示例发布时间: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