本文整理汇总了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()