本文整理汇总了Python中db.Db.update_course方法的典型用法代码示例。如果您正苦于以下问题:Python Db.update_course方法的具体用法?Python Db.update_course怎么用?Python Db.update_course使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类db.Db
的用法示例。
在下文中一共展示了Db.update_course方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Chami
# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import update_course [as 别名]
class Chami(object):
def __init__(self, username=None, password=None, site_url=None):
self.username = username
self.password = password
self.site_url = 'https://elearning.esi.heb.be'
self.db = Db()
self.session = requests.Session()
def connect(self, username=None, password=None, ssl_verify=False):
payload = {'login': username, 'password': password}
return not 'user_password_incorrect' in self.session.post(self.index_url, data=payload, verify=ssl_verify).url
def disconnect(self):
self.session.get('{}/index.php?logout=logout'.format(self.site_url))
@property
def index_url(self):
return '%s/%s' % (self.site_url, 'index.php')
@property
def courses_url(self):
return '%s/%s' % (self.site_url, 'main/auth/courses.php?action=display_courses&category_code=ALL&hidden_links=0')
@property
def my_courses_url(self):
return '%s/%s' % (self.site_url, 'user_portal.php')
def get_courses(self):
html = self.session.get(self.courses_url, verify=False).content
soup = bs(html).find('body', {'class': 'section-mycourses '})
for course in soup.findAll('div', {'class': 'span4'}):
# if course in span and has link to access it
if course.find('div', {'class': 'categories-course-description'}) \
and course.find('a', {'class': 'btn btn-primary'}):
name = course.find('h3').text
url = course.find('a', {'class': 'btn btn-primary'})['href']
print(name, url)
self.db.insert_course(Course(name, url))
return self.db.select_courses()
def get_my_courses(self):
def extract_course_id(url):
return url.split('/')[4]
html = self.session.get(self.my_courses_url, verify=False).content
soup = bs(html).find('section', {'id': 'main_content'})
for course in soup.findAll('div', {'class': 'well course-box'}):
self.db.insert_my_course(extract_course_id(course.find('a')['href']))
return self.db.select_my_courses()
def download(self):
course = self.courses[2]
print("course url " + course.url)
def update_db(self, courses):
for course in courses:
# # Initialize a pool, 5 threads in this case
# pool = workerpool.WorkerPool(size=5)
# # Loop over urls.txt and create a job to download the URL on each line
# for url in open("urls.txt"):
# job = DownloadJob(url.strip())
# pool.put(job)
# # Send shutdown jobs to all threads, and wait until all the jobs have been completed
# pool.shutdown()
# # pool.wait()
print('update_db_course', course, time.strftime('%Y-%m-%d %H:%M:%S'))
self.course_folders(course_id=course)
self.db.update_course(course, date=time.strftime('%Y-%m-%d %H:%M:%S'))
def courses_to_be_updated(self):
courses_to_update = []
for course in self.db.select_courses():
print(course)
date_updated_course = course[2]
course_url = '%s/main/document/document.php?cidReq=%s' % (self.site_url, course[0])
soup = bs(self.session.get(course_url).content)
if soup.find('table', {'class': 'data_table'}):
folders = soup.find('table', {'class': 'data_table'}).findAll('tr')[1:] # don't take first line
for folder in folders:
date_updated_folder = folder.find('small').text
if date_updated_folder > date_updated_course:
#.........这里部分代码省略.........