當前位置: 首頁>>代碼示例>>Python>>正文


Python Session.expunge方法代碼示例

本文整理匯總了Python中database.Session.expunge方法的典型用法代碼示例。如果您正苦於以下問題:Python Session.expunge方法的具體用法?Python Session.expunge怎麽用?Python Session.expunge使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在database.Session的用法示例。


在下文中一共展示了Session.expunge方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_courses

# 需要導入模塊: from database import Session [as 別名]
# 或者: from database.Session import expunge [as 別名]
def get_courses():
    '''Navigates to Premain

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

    new_announcements = []

    for i, (course_id, name, url) in enumerate(extract_courses(r.content)):
        course = session.query(Course). \
            filter_by(course_id=course_id). \
            first()
        if course is None:
            print u'Add new course "{}"'.format(name)
            course = Course(
                course_id=course_id,
                title=name)
            session.add(course)
        print course.title
        # Get inside the course
        r = s.get(url)
        r.raise_for_status()
        session.expunge(course)
        course_content = r.content
        if 'Announcements.aspx' in course_content:
            print 'There are announcements'
            # Get announcement for this course
            for (timestamp, announcement) in get_announcements(course, url):
                new_announcements.append((course.title, timestamp, announcement))
        if 'Quiz.aspx' in course_content:
            print 'There are quizes'
            get_quiz(course)
        if 'Folder.aspx' in course_content:
            print 'There are folders'
            get_folders(course)

    # Prepare email stuff from gathered data

    subject = 'You have {0} new announcements on EDUX'.format(
        len(new_announcements))

    body = u''

    # Sort new announcements so highest date (newer) will be on top
    sorted_announcements = sorted(new_announcements,
                                  key=operator.itemgetter(1),
                                  reverse=True)
    # TODO: Use some templating here
    for i, (course, timestamp, announcement) in enumerate(sorted_announcements,
                                                          1):
        body += u'{0}. {1} at {2}\n{3}\n\n'.format(
            i,
            timestamp,
            course,
            announcement)

    # Cant send empty body because mailgun throws HTTP400s.
    send_notify(subject, body)

    session.commit()
開發者ID:mpapierski,項目名稱:edux,代碼行數:65,代碼來源:edux.py


注:本文中的database.Session.expunge方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。