def get_all_lectures(): response = requests.get('http://curric.rithmschool.com/r13/lectures/') soup = BeautifulSoup(response.text) links = [] # Drop current lecture table engine = create_engine(ProductionConfig.SQLALCHEMY_DATABASE_URI) Lecture.__table__.drop(engine) db.create_all() for link in soup.find_all('a'): links.append(link.get('href')) for link in links: if 'zip' in link: continue response = requests.get('http://curric.rithmschool.com/r13/lectures/' + link) soup = BeautifulSoup(response.text) if (soup.title is None): continue if (soup.title.string == 'Rithm Curriculum'): continue else: new_lecture = Lecture( title=link, url='http://curric.rithmschool.com/r13/lectures/' + link) db.session.add(new_lecture) db.session.commit()
async def api_create_lecture(request, *, title, tim, place, url, content): check_admin(request) if not title or not title.strip(): raise APIValueError('title', 'title cannot be empty.') if not tim or not tim.strip(): raise APIValueError('tim', 'tim cannot be empty.') if not place or not place.strip(): raise APIValueError('place', 'place cannot be empty.') if not url or not url.strip(): raise APIValueError('url', 'url cannot be empty.') if not content or not content.strip(): raise APIValueError('content', 'content cannot be empty.') lecture = Lecture(title=title.strip(), tim=tim.strip(), place=place.strip(), url=url.strip(), content=content.strip()) await lecture.save() return lecture