當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。