def available_languages(): """ :return: jason with language codes for the supported languages. e.g. ["en", "fr", "de", "it", "no", "ro"] """ available_language_codes = list(map((lambda x: x.code), Language.available_languages())) return json.dumps(available_language_codes)
def recompute_for_topics_and_languages(): from zeeguu_core.model import Topic, Language for each in Topic.get_all_topics(): each.all_articles() for each in Language.available_languages(): each.get_articles()
def system_languages(): result = dict() result["learnable_languages"] = list( map((lambda x: dict(name=x.name, code=x.code)), Language.available_languages())) result["native_languages"] = list( map((lambda x: dict(name=x.name, code=x.code)), Language.native_languages())) return result
def available_languages(): """ :return: jason with language codes for the supported languages. e.g. ["en", "fr", "de", "it", "no", "ro"] """ available_language_codes = list( map((lambda x: x.code), Language.available_languages())) return json.dumps(available_language_codes)
def cache_articles(code): if code != zeeguu_core.app.config.get("PRIVATE_API_CODE"): return "Nope" from zeeguu_core.model import Topic, Language for each in Topic.get_all_topics(): each.all_articles() for each in Language.available_languages(): each.get_articles() return "OK"
def cache_articles(code): if code != zeeguu_core.app.config.get("PRIVATE_API_CODE"): return "Nope" from zeeguu_core.model import Topic, Language for each in Topic.get_all_topics(): each.all_articles() for each in Language.available_languages(): each.get_articles() print("done caching articles!") return "OK"
def create_own_cohort(): """ Creates a cohort in the database. Requires form input (inv_code, name, language_id, max_students, teacher_id) """ if not _is_teacher(flask.g.user.id): flask.abort(401) params = request.form inv_code = params.get("inv_code") name = params.get("name") # language_id is deprecated and kept here for backwards compatibility # use language_code instead language_code = params.get("language_code") or params.get("language_id") if name is None or inv_code is None or language_code is None: flask.abort(400) available_languages = Language.available_languages() code_allowed = False for code in available_languages: if language_code in str(code): code_allowed = True if not code_allowed: flask.abort(400) language = Language.find_or_create(language_code) teacher_id = flask.g.user.id max_students = params.get("max_students") if int(max_students) < 1: flask.abort(400) try: c = Cohort(inv_code, name, language, max_students) db.session.add(c) db.session.commit() _link_teacher_cohort(teacher_id, c.id) return "OK" except ValueError: flask.abort(400) return "ValueError" except sqlalchemy.exc.IntegrityError: flask.abort(400) return "IntegrityError"
def create_own_cohort(): ''' Creates a cohort in the database. Requires form input (inv_code, name, language_id, max_students, teacher_id) ''' if not _is_teacher(flask.g.user.id): flask.abort(401) inv_code = request.form.get("inv_code") name = request.form.get("name") language_id = request.form.get("language_id") if name is None or inv_code is None or language_id is None: flask.abort(400) available_languages = Language.available_languages() code_allowed = False for code in available_languages: if language_id in str(code): code_allowed = True if not code_allowed: flask.abort(400) language = Language.find_or_create(language_id) teacher_id = flask.g.user.id max_students = request.form.get("max_students") if int(max_students) < 1: flask.abort(400) try: c = Cohort(inv_code, name, language, max_students) db.session.add(c) db.session.commit() _link_teacher_cohort(teacher_id, c.id) return "OK" except ValueError: flask.abort(400) return "ValueError" except sqlalchemy.exc.IntegrityError: flask.abort(400) return "IntegrityError"
import zeeguu_core from zeeguu_core.model import Article, Language, LocalizedTopic session = zeeguu_core.db.session counter = 0 languages = Language.available_languages() languages = [Language.find('da')] for language in languages: articles = Article.query.filter(Article.language == language).order_by(Article.id.desc()).all() loc_topics = LocalizedTopic.all_for_language(language) total_articles = len(articles) for article in articles: counter += 1 print(f"{article.title}") print(f"{article.url.as_string()}") for loc_topic in loc_topics: if loc_topic.matches_article(article): article.add_topic(loc_topic.topic) print(f" #{loc_topic.topic_translated}") print("") session.add(article) if counter % 1000 == 0: percentage = (100 * counter / total_articles) / 100 print(f"{counter} dorticles done ({percentage}%). last article id: {article.id}. Comitting... ") session.commit()