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


Python Session.close方法代码示例

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


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

示例1: insert_test_values

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import close [as 别名]
def insert_test_values():
    from database import Session
    from database.objects import User, Address, BlogPost, Keyword
    from random import randint

    letters = "abcdefghijklmnopqrstuvwxyz"

    s = Session()

    keyword = Keyword("firstpost")

    for n in range(100):
        name = ""
        for l in range(randint(4, 10)):
            letter = letters[randint(0, len(letters) - 1)]
            name += letter
        user = User(name=name, fullname=name, password="test")
        user.addresses = [
            Address(email_address=("%[email protected]" % name)),
            Address(email_address=("%[email protected]" % name)),
        ]
        post = BlogPost(("%ss Blog Post" % name), "This is a test", user)
        post.keywords.append(Keyword(name))
        post.keywords.append(keyword)
        s.add(post)

    s.commit()
    s.close()
开发者ID:Inktvisje,项目名称:alchtest,代码行数:30,代码来源:setup.py

示例2: delete_user

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import close [as 别名]
 def delete_user(self, user_id):
     s = Session()
     del_user = s.query(User).filter(User.id == user_id).one()
     s.delete(del_user)
     s.commit()
     self.signal_delete_user.emit(user_id)
     s.close()
开发者ID:Inktvisje,项目名称:alchtest,代码行数:9,代码来源:UserModel.py

示例3: get_announcements

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import close [as 别名]
def get_announcements(course, url):
    '''Gets all new announcements

    Returns a list of all new announcements.
    '''
    session = Session()
    try:
        r = s.get('https://edux.pjwstk.edu.pl/Announcements.aspx', stream=True)
        r.raise_for_status()
        new_announcements = extract_announcements(r.content)
        # All pairs of (timestamp, message) are saved to db
        # if they arent there already
        for (timestamp, message) in new_announcements:
            announcement = session.query(Announcement). \
                filter_by(course=course,
                          created_at=timestamp,
                          message=message). \
                first()
            if announcement is None:
                # This is what we care about
                announcement = Announcement(
                    course=course,
                    created_at=timestamp,
                    message=message)
                session.add(announcement)
                print u'New announcement at {0}'.format(timestamp)
                yield (timestamp, message)
        session.commit()
    except Exception:
        session.rollback()
        raise
    finally:
        session.close()
开发者ID:mpapierski,项目名称:edux,代码行数:35,代码来源:edux.py

示例4: add_user

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import close [as 别名]
 def add_user(self, name, address):
     if not (name == '' or address == ''):
         s = Session()
         u = User(name=name, fullname='%s test' % name, password='pwtest')
         u.addresses = [Address(email_address=address), ]
         s.add(u)
         s.commit()
         self.send_user(u)
         s.close()
开发者ID:Inktvisje,项目名称:alchtest,代码行数:11,代码来源:UserModel.py

示例5: index

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import close [as 别名]
    def index(self, fullname=None, username=None, password=None):
        if cherrypy.request.method == "POST":
            session = Session()
            new_user = User(username, fullname, password)
            session.add(new_user)
            session.commit()
            session.close()

        raise cherrypy.HTTPRedirect("/")
开发者ID:FissionCat,项目名称:cherrypy-practice,代码行数:11,代码来源:hello.py

示例6: check_db

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import close [as 别名]
def check_db(loud=False, delete_orphans=False, fix=False):
    session = Session()

    check_orphans(session, loud, delete_orphans)
    check_readings(session, loud, fix)
    check_masses(session, loud)
    check_events(session, loud)

    #session.commit()
    session.rollback()
    session.close()
开发者ID:giomasce,项目名称:liturgy,代码行数:13,代码来源:check_db.py

示例7: get_folders

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import close [as 别名]
def get_folders(course):
    '''Gets all folders
    '''
    session = Session()
    try:
        r = s.get('https://edux.pjwstk.edu.pl/Folder.aspx')
        r.raise_for_status()
        new_folders = extract_folders(r.content)
        for (folder_id, title, start_at, finish_at) in new_folders:
            folder = session.query(Folder). \
                filter_by(folder_id=folder_id). \
                first()
            if folder is None:
                folder = Folder(
                    folder_id=folder_id,
                    course=course,
                    title=title,
                    start_at=start_at,
                    finish_at=finish_at)
                send_notify('New folder "{}" at {}'.format(title,
                                                           course.title),
                            '''Folder title: {0.title}
Start at: {0.start_at}
Finish at: {0.finish_at}'''.format(folder))

                session.add(folder)
            if (folder.title != title or
                    folder.start_at != start_at or
                    folder.finish_at != finish_at):
                new = {
                    'title': title,
                    'start_at': start_at,
                    'finish_at': finish_at
                }
                send_notify('Folder "{0}" updated'.format(title),
                            '''Folder title: {new[title]} (old: {0.title})
Start at: {new[start_at]} (old: {0.start_at})
Finish at: {new[finish_at]} (old: {0.finish_at})'''.format(folder,
                                                           new=new))

                folder.title = title
                folder.start_at = start_at
                folder.finish_at = finish_at
                session.add(folder)
        session.commit()
    finally:
        session.close()
开发者ID:mpapierski,项目名称:edux,代码行数:49,代码来源:edux.py

示例8: load_all_users

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import close [as 别名]
 def load_all_users(self):
     s = Session()
     for u in s.query(User).all():
         self.send_user(u)
     s.close()
开发者ID:Inktvisje,项目名称:alchtest,代码行数:7,代码来源:UserModel.py

示例9: print_date

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import close [as 别名]
def print_date(date):
    session = Session()
    ref_year = calc_ref_year(date)
    lit_year = build_dict_lit_year(ref_year, session)
    print_lit_date(lit_year[date])
    session.close()
开发者ID:giomasce,项目名称:liturgy,代码行数:8,代码来源:liturgy.py

示例10: print_year

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import close [as 别名]
def print_year(year):
    session = Session()
    lit_year = build_lit_year(year, session)
    for ld in lit_year:
        print_lit_date(ld)
    session.close()
开发者ID:giomasce,项目名称:liturgy,代码行数:8,代码来源:liturgy.py

示例11: get_quiz

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import close [as 别名]
def get_quiz(course):
    '''Navigates to quiz

    Gets all quiz
    '''
    session = Session()
    try:
        r = s.get('https://edux.pjwstk.edu.pl/Quiz.aspx')
        r.raise_for_status()

        # quiz = []

        for (quiz_id,
             title,
             start_at,
             finish_at,
             duration,
             score) in extract_quiz(r.content):
            quiz = session.query(Quiz). \
                filter_by(quiz_id=quiz_id). \
                first()
            if quiz is None:
                quiz = Quiz(
                    course=course,
                    quiz_id=quiz_id,
                    title=title,
                    start_at=start_at,
                    finish_at=finish_at,
                    duration=duration,
                    score=score
                )
                session.add(quiz)
                print u'New quiz "{0}" {1} - {2}'.format(
                    quiz.title,
                    quiz.start_at,
                    quiz.finish_at)
                send_notify(u'Quiz "{0.title}" at {1.title}'.format(quiz,
                                                                    course),
                            u'''Quiz title: {0.title}
Course: {1.title}
Start: {0.start_at}
Finish: {0.finish_at}
Duration: {0.duration}
Score: {0.score}
'''.format(quiz, course))

            if (quiz.title != title or
                    quiz.start_at != start_at or
                    quiz.finish_at != finish_at or
                    quiz.duration != duration or
                    quiz.score != score):
                send_notify(u'Quiz "{0.title}" changed'.format(quiz,
                                                               course),
                            u'''Quiz title: {new[title]} (old: {0.title})
Course: {1.title}
Start: {new[start_at]} (old: {0.start_at})
Finish: {new[finish_at]} (old: {0.finish_at})
Duration: {new[duration]} (old: {0.duration})
Score: {new[score]} (old: {0.score})
'''.format(quiz, course, new={'title': title,
                              'start_at': start_at,
                              'finish_at': finish_at,
                              'duration': duration,
                              'score': score}))
                quiz.title = title
                quiz.start_at = start_at
                quiz.finish_at = finish_at
                quiz.duration = duration
                quiz.score = score
                session.add(quiz)

        session.commit()
    except Exception:
        session.rollback()
        raise
    finally:
        session.close()
开发者ID:mpapierski,项目名称:edux,代码行数:79,代码来源:edux.py

示例12: import_from_scrape

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import close [as 别名]

#.........这里部分代码省略.........
    lit_years = {}
    session = Session()

    for day in real_itermonthdays(year, month):
        date = datetime.date(year, month, day)
        print >> sys.stderr, "Importing %s..." % (date)
        lit_date = get_lit_date(date, lit_years, session)

        # Check if we already have a mass here
        try:
            lit_date.get_masses(strict=False)
        except SelectingMassException:
            pass
        else:
            print >> sys.stderr, "  * skipping because a valid mass already exists"
            continue

        winner = lit_date.get_winner(remove_ok=True)
        if winner is None:
            print >> sys.stderr, "  * skipping because there are no masses today"
            continue

        event = winner[1]
        with open(os.path.join('scrape', '%04d-%02d-%02d.html' % (year, month, day))) as fhtml:
            quotes = scrape_file(fhtml)

        if u'auto' not in event.status.split(u' '):
            event.status += u' auto'

        mass = Mass()
        mass.order = 0
        mass.event = event
        mass.digit = lit_date.digit
        mass.letter = lit_date.letter
        mass.title = None
        mass.status = u'auto'
        session.add(mass)

        order = 0
        if len(quotes) == 4:
            titles = [u'Prima lettura', u'Salmo responsoriale', u'Seconda lettura', u'Vangelo']
        elif len(quotes) == 3:
            titles = [u'Prima lettura', u'Salmo responsoriale', u'Vangelo']
        # Domenica delle Palme
        elif len(quotes) == 5:
            titles = [u'Vangelo delle Palme', u'Prima lettura', u'Salmo responsoriale', u'Seconda lettura', u'Vangelo']
        # Pasqua
        elif len(quotes) == 17:
            titles = [u'Prima lettura',
                      u'Salmo responsoriale',
                      u'Seconda lettura',
                      u'Salmo responsoriale',
                      u'Terza lettura',
                      u'Salmo responsoriale',
                      u'Quarta lettura',
                      u'Salmo responsoriale',
                      u'Quinta lettura',
                      u'Salmo responsoriale',
                      u'Sesta lettura',
                      u'Salmo responsoriale',
                      u'Settima lettura',
                      u'Salmo responsoriale',
                      u'Epistola',
                      u'Salmo responsoriale',
                      u'Vangelo']
        else:
            raise Exception('Strange number of readings (%d)' % (len(quotes)))

        for (quote, text), title in zip(quotes, titles):
            reading = Reading()
            reading.order = order
            order += 1
            reading.alt_num = 0
            reading.mass = mass
            reading.title = title
            reading.quote = canonicalise_quote(quote)
            reading.text = text
            try:
                decode_quote(quote, allow_only_chap=True, valid_abbr=ABBR_VATICAN)
            except:
                reading.quote_status = u'auto invalid'
            else:
                reading.quote_status = u'auto'
            if text is None:
                reading.text_status = u'missing'
            else:
                reading.text_status = u'auto'
            session.add(reading)

        session.flush()

        # Write some interesting things
        #print '#'
        #print_lit_date(lit_date, PrependStream(sys.stdout, '# '))
        #print
        #print json.dumps(event.as_dict(), encoding='utf-8', ensure_ascii=False, indent=2, sort_keys=True)
        #print

    session.commit()
    session.close()
开发者ID:giomasce,项目名称:liturgy,代码行数:104,代码来源:import_month.py


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