Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local acc, scr_name = ...
- local host = "https://www.duolingo.com"
- local from_lang, learning_lang = nil, nil
- do
- from_lang, learning_lang = scr_name:match("^[^,]+,([^,]+),([^,]+)%.lua$")
- if not from_lang then
- acc.output().print("Failed to get params from the script name")
- acc.output().print("For example: ctm,en,de.lua")
- return {}
- end
- end
- local user = acc.user()
- local output = acc.output()
- local utils = acc.bot().utils()
- local loc_table = {
- ["Vocab per Skill Unit for the %s / %s Course"] = {
- ["ru"] = "Список навыков со списком изучаемых слов %s / %s курса",
- ["de"] = "Vokabeln per Fähigkeit für den %s / %s Kurs"
- },
- ["Tips and notes"] = {
- ["ru"] = "Подсказки и заметки",
- ["de"] = "Tipps und Anmerkungen"
- },
- ["Number of lessons"] = {
- ["ru"] = "Количество уроков",
- ["de"] = "Anzahl Lektionen"
- },
- ["Words"] = {
- ["ru"] = "Слова",
- ["de"] = "Wörter"
- },
- ["Skills"] = {
- ["ru"] = "Навыки",
- ["de"] = "Fähigkeiten"
- },
- ["Lessons"] = {
- ["ru"] = "Уроки",
- ["de"] = "Lektionen"
- },
- ["no"] = {
- ["ru"] = "нет",
- ["de"] = "Nein"
- },
- ["yes"] = {
- ["ru"] = "да",
- ["de"] = "Ja"
- },
- ["test"] = {
- ["ru"] = "тест",
- ["de"] = "testen"
- },
- ["Total: %d skills, %s lessons, %d/%d words"] = {
- ["ru"] = "Всего: %d навыков, %s уроков, %d/%d слов",
- ["de"] = "Insgesamt: %d Fähigkeiten, %s Lektionen, %d/%d Wörter"
- },
- ["Total"] = {
- ["ru"] = "Всего",
- ["de"] = "Insgesamt"
- },
- ["Another lists:"] = {
- ["ru"] = "Другие списки:",
- ["de"] = "Andere Listen:"
- },
- ["Last update: %s"] = {
- ["ru"] = "Последнее обновление: %s",
- ["de"] = "Letzte Aktualisierung: %s"
- }
- }
- local tr = function(str, lang)
- return str and lang and loc_table[str] and loc_table[str][lang] or str
- end
- local display_error_status = function(err)
- if err then output.print(err.tostring()) end
- output.set_stream()
- output.printf("********** %s ERROR **********", scr_name:upper())
- end
- if not acc.course().switch(from_lang, learning_lang) then
- display_error_status(acc.error)
- return {}
- end
- local scnt = user.course_info().skills_count()
- local idx = 0
- local skt = {}
- local frm = nil
- do
- local sz = math.floor(math.log10(scnt) + 1)
- frm = string.format("[%%%dd/%%%dd]", sz, sz)
- end
- for s, d in user.course_info().each_skill() do
- if idx > 0 then
- acc.bot().utils().pause(2, 5)
- end
- idx = idx + 1
- local t = {}
- t.title = s.name
- t.url = s.urlName
- output.printf(frm .. " Getting skill \"%s\"", idx, scnt, t.title)
- local sd = acc.course().get_skill_data(t.url)
- if not sd then
- display_error_status(acc.error)
- return {}
- end
- t.id = s.id
- t.short = s.shortName
- t.nless = s.lessons
- if d.sectionName then -- It is the new style of Tips&Notes
- t.expl = (type(s.explanation) == "table") and (type(s.explanation.url) == "string") and (s.explanation.url ~= "")
- t.sname = d.sectionName
- else
- t.expl = (type(s.tipsAndNotes) == "string") and (s.tipsAndNotes ~= "")
- end
- t.chkp = d.checkpoint
- t.levels = s.levels
- t.flevels = s.finishedLevels
- t.words = {}
- for j = 1, #sd.lessonWords do
- local w = sd.lessonWords[j]
- if type(w) == "table" then
- for k = 1, #w do table.insert(t.words, w[k]) end
- end
- end
- table.insert(skt, t)
- end
- output.set_stream(string.format("tree_markdown_%s_%s.md", from_lang, learning_lang), "w")
- local function get_original_lessons_count(lessons, ftable)
- local res = nil
- for i = 1, #lessons do
- if lessons[i] ~= -1 and ftable[i] then
- res = lessons[i] / ftable[i]
- break
- end
- end
- if not res then
- local l = lessons.total
- if l then
- local f = 0
- for i = 1, #ftable do f = f + ftable[i] end
- res = l / f
- end
- end
- if res and res > 0 and math.floor(res) == res then
- return res
- end
- return nil
- end
- local function ensure_lessons_count(lessons)
- local f = { 1, 1, 2, 3, 5 }
- local b = get_original_lessons_count(lessons, f)
- if b then
- for i = 1, #lessons do
- if lessons[i] == -1 then
- lessons[i] = b * f[i]
- end
- end
- end
- end
- local function lessons_to_string(lessons)
- local t = {}
- local a = 0
- for i = 1, #lessons do
- local l = lessons[i]
- if l == -1 then
- table.insert(t, "?")
- a = 0
- else
- table.insert(t, l)
- if a then a = a + l end
- end
- end
- return table.concat(t, " | ") .. " || " .. (a and tostring(a) or "?")
- end
- local lcnt, wcnt = {}, 0
- local tips = 0
- local course_id = string.format("%s/%s", from_lang, learning_lang)
- local course_str = acc.user().get("currentCourse.title")
- local section_name = nil
- output.printf("TITLE: " .. string.format(tr("Vocab per Skill Unit for the %s / %s Course", from_lang), course_str, string.upper(from_lang)))
- output.print("")
- output.print("")
- for i = 1, #skt do
- local t = skt[i]
- if t.chkp then
- output.print("----------")
- end
- if i > 1 then
- output.print("")
- end
- if t.sname and t.sname ~= section_name then
- section_name = t.sname
- output.printf("## **%s**", section_name)
- output.print("")
- end
- local s = string.format("[%s](%s/skill/%s/%s/practice)", t.short, host, learning_lang, t.url)
- if t.short ~= t.title then s = s .. " - " .. t.title end
- s = s .. string.format(" \\[[%s](%s/skill/%s/%s/test)\\]", tr("test", from_lang), host, learning_lang, t.url)
- output.print("## " .. s)
- output.print("")
- local expl = nil
- if t.expl then
- tips = tips + 1
- expl = string.format("[%s](%s/skill/%s/%s/tips-and-notes)", tr("yes", from_lang), host, learning_lang, t.url)
- else
- expl = tr("no", from_lang)
- end
- output.printf("* %s: %s", tr("Tips and notes", from_lang), expl)
- local nl = {}
- do
- local nl_map = {}
- nl_map[1] = t.nless
- for k = 0, t.levels - 1 do
- local n = nl_map[k] or -1
- table.insert(nl, n)
- end
- if nl_map[t.levels] then nl.total = nl_map[t.levels] end
- end
- ensure_lessons_count(nl)
- output.printf("* %s: %s", tr("Number of lessons", from_lang), lessons_to_string(nl))
- output.printf("* %s: %s", tr("Words", from_lang), table.concat(t.words, ", "))
- output.print("")
- for k = 1, #nl do
- if nl[k] == -1 then
- lcnt[k] = -1
- elseif not lcnt[k] then
- lcnt[k] = nl[k]
- elseif lcnt[k] ~= -1 then
- lcnt[k] = lcnt[k] + nl[k]
- end
- end
- wcnt = wcnt + #t.words
- end
- local vcnt = user.course_info().vocabulary_size() or -1
- output.print("")
- output.print("----------")
- output.print("")
- output.printf("## **%s**", tr("Total", from_lang))
- output.print("")
- output.printf("- %s: %d", tr("Skills", from_lang), #skt)
- output.printf("- %s: %d/%d", tr("Words", from_lang), vcnt, wcnt)
- output.printf("- %s: %s", tr("Lessons", from_lang), lessons_to_string(lcnt))
- output.printf("- %s: %d (%.1f%%)", tr("Tips and Notes", from_lang), tips, tips / #skt * 100)
- output.print("")
- output.print("----------")
- output.print("")
- output.print(tr("Other links:", from_lang))
- output.print("")
- output.print("- [List of Vocabularies for Language Courses of Duolingo](https://forum.duolingo.com/comment/31074292)")
- output.print("")
- output.print("----------")
- output.print("")
- output.printf(tr("Last update: %s", from_lang), os.date("%Y-%m-%d"))
- output.set_stream()
- return {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement