Question 1: Look at the freezer. It is open right now. Why is it a bad idea to leave the freezer open for a long time? What happens to the ice cream? · Student Answer: _________________________________________________ · Logical Target: It melts. / The food gets warm. Question 2: You see a big bowl of mixture on the table. It tastes very sweet. Which ingredient is inside: salt or sugar? How do you know? · Student Answer: _________________________________________________ · Logical Target: Sugar, because salt makes things salty and sugar makes them sweet. Question 3: Your mom is holding a glass of milk and a carton of cream. She is walking to the table. What is she doing with them? · Student Answer: _________________________________________________ · Target: She is pouring the cream into the milk. Question 4: You are carrying heavy plastic bags from the supermarket. The door is closed. How do you open the door if your hands are full? · Student Answer: _________________________________________________ · Logical Target: I kick it, I use my elbow, I ask for help, etc. Question 5: You want to make a cake mixture, but you cannot use sugar. The cake will taste very bad. What else can you put in the mixture to make it sweet? · Student Answer: _________________________________________________ · Logical Target: Honey, fruit, chocolate, etc. --- 🔵 PART 2: CAUSE & EFFECT CHEF (Present Simple) In the story, Omar's mom heats water to make him warm. Let's look at more causes and effects in the kitchen! Question 6: Cause: You put too much salt into your soup. What is the effect? Will it taste good or bad? · Student Answer: _________________________________________________ Question 7: Cause: You pour water into a glass and put it in the freezer. What is the effect? What will you have later? · Student Answer: _________________________________________________ Question 8: Cause: You leave the plastic bags on the floor. What is the effect? Is it safe for your family? · Student Answer: _________________________________________________ Question 9: Cause: The kitchen window is closed, and your mom is cooking a hot mixture. What is the effect? How does the kitchen feel? · Student Answer: _________________________________________________ Question 10: Cause: You want to make a milkshake, but the lid is on very tight. What is the effect? What do you need to do first?, please create a colorful handbook pdf with answers and all these questions mentioned above with it's answers and Russian translation under every sentence.
ls -la /tmp/workspace/; fc-list | grep -i -E "dejavu|liberation|noto" | head -20; python3 -c "import reportlab;print(reportlab.__version__)"
Which part should I build first as the colorful PDF handbook (answers plus Russian under every sentence)?
fc-list : file | grep -v -i "noto" | head -30; ls /usr/share/fonts/; python3 -c "import matplotlib,os;print(os.path.join(os.path.dirname(matplotlib.__file__),'mpl-data/fonts/ttf'))"
mkdir -p /tmp/workspace/kitchen-handbook/output && cat > /tmp/workspace/kitchen-handbook/build.py <<'EOF' from reportlab.lib.pagesizes import A4 from reportlab.lib.units import cm from reportlab.lib import colors from reportlab.lib.styles import ParagraphStyle from reportlab.lib.enums import TA_CENTER, TA_LEFT from reportlab.pdfbase import pdfmetrics from reportlab.pdfbase.ttfonts import TTFont from reportlab.platypus import (BaseDocTemplate, PageTemplate, Frame, Paragraph, Spacer, Table, TableStyle, KeepTogether, PageBreak, NextPageTemplate) pdfmetrics.registerFont(TTFont("D", "/usr/share/fonts/google-droid-sans-fonts/DroidSans.ttf")) pdfmetrics.registerFont(TTFont("DB", "/usr/share/fonts/google-droid-sans-fonts/DroidSans-Bold.ttf")) pdfmetrics.registerFontFamily("D", normal="D", bold="DB", italic="D", boldItalic="DB") W, H = A4 C = colors.HexColor NAVY = C("#1F2A5A") def st(name, **kw): base = dict(fontName="D", fontSize=11, leading=15, textColor=NAVY) base.update(kw) return ParagraphStyle(name, **base) # ---------------- CONTENT ---------------- # each item: (EN, RU) Q = [ dict(n=1, part=1, topic="Freezer", color="#2E86DE", light="#E3F0FF", q=[("Look at the freezer.","Посмотри на морозильник."), ("It is open right now.","Он открыт прямо сейчас."), ("Why is it a bad idea to leave the freezer open for a long time?","Почему плохо оставлять морозильник открытым надолго?"), ("What happens to the ice cream?","Что происходит с мороженым?")], a=[("It melts.","Оно тает."), ("The food gets warm.","Еда становится тёплой."), ("So I always close the freezer door.","Поэтому я всегда закрываю дверцу морозильника.")]), dict(n=2, part=1, topic="Sweet or salty?", color="#F39C12", light="#FFF3DC", q=[("You see a big bowl of mixture on the table.","Ты видишь на столе большую миску со смесью."), ("It tastes very sweet.","Она очень сладкая на вкус."), ("Which ingredient is inside: salt or sugar?","Какой ингредиент внутри: соль или сахар?"), ("How do you know?","Откуда ты знаешь?")], a=[("It is sugar.","Это сахар."), ("Salt makes things salty and sugar makes them sweet.","Соль делает еду солёной, а сахар делает её сладкой.")]), dict(n=3, part=1, topic="Milk and cream", color="#E84393", light="#FFE6F2", q=[("Your mom is holding a glass of milk and a carton of cream.","Твоя мама держит стакан молока и пачку сливок."), ("She is walking to the table.","Она идёт к столу."), ("What is she doing with them?","Что она с ними делает?")], a=[("She is pouring the cream into the milk.","Она наливает сливки в молоко.")]), dict(n=4, part=1, topic="Heavy bags", color="#8E44AD", light="#F1E4F8", q=[("You are carrying heavy plastic bags from the supermarket.","Ты несёшь тяжёлые пластиковые пакеты из супермаркета."), ("The door is closed.","Дверь закрыта."), ("How do you open the door if your hands are full?","Как ты откроешь дверь, если твои руки заняты?")], a=[("I use my elbow.","Я использую локоть."), ("I kick it gently, or I ask for help.","Я легонько толкаю её ногой или прошу о помощи.")]), dict(n=5, part=1, topic="No sugar!", color="#16A085", light="#DDF5EF", q=[("You want to make a cake mixture, but you cannot use sugar.","Ты хочешь приготовить тесто для торта, но не можешь использовать сахар."), ("The cake will taste very bad.","Торт будет очень невкусным."), ("What else can you put in the mixture to make it sweet?","Что ещё можно добавить в смесь, чтобы она стала сладкой?")], a=[("I can put honey, fruit or chocolate in the mixture.","Я могу добавить в смесь мёд, фрукты или шоколад.")]), dict(n=6, part=2, topic="Too much salt", color="#E74C3C", light="#FDE5E2", q=[("Cause: You put too much salt into your soup.","Причина: Ты кладёшь слишком много соли в суп."), ("What is the effect?","Каков результат?"), ("Will it taste good or bad?","Он будет вкусным или невкусным?")], a=[("The soup is too salty.","Суп слишком солёный."), ("It tastes bad.","Он невкусный.")]), dict(n=7, part=2, topic="Ice time", color="#0ABDE3", light="#DDF6FC", q=[("Cause: You pour water into a glass and put it in the freezer.","Причина: Ты наливаешь воду в стакан и ставишь его в морозильник."), ("What is the effect?","Каков результат?"), ("What will you have later?","Что у тебя будет потом?")], a=[("The water freezes.","Вода замерзает."), ("Later I have ice.","Потом у меня есть лёд.")]), dict(n=8, part=2, topic="Safety first", color="#F39C12", light="#FFF3DC", q=[("Cause: You leave the plastic bags on the floor.","Причина: Ты оставляешь пластиковые пакеты на полу."), ("What is the effect?","Каков результат?"), ("Is it safe for your family?","Это безопасно для твоей семьи?")], a=[("Someone trips over the bags and falls.","Кто-то спотыкается о пакеты и падает."), ("No, it is not safe for my family.","Нет, это небезопасно для моей семьи.")]), dict(n=9, part=2, topic="Hot kitchen", color="#D35400", light="#FCE9DC", q=[("Cause: The kitchen window is closed, and your mom is cooking a hot mixture.","Причина: Окно на кухне закрыто, а твоя мама готовит горячую смесь."), ("What is the effect?","Каков результат?"), ("How does the kitchen feel?","Какой кажется кухня?")], a=[("The hot air stays inside.","Горячий воздух остаётся внутри."), ("The kitchen feels hot and stuffy.","На кухне жарко и душно.")]), dict(n=10, part=2, topic="Milkshake", color="#27AE60", light="#DFF5E6", q=[("Cause: You want to make a milkshake, but the lid is on very tight.","Причина: Ты хочешь сделать молочный коктейль, но крышка закрыта очень туго."), ("What is the effect?","Каков результат?"), ("What do you need to do first?","Что нужно сделать в первую очередь?")], a=[("I cannot open it, so I cannot put the milk inside.","Я не могу её открыть, поэтому не могу налить молоко."), ("First, I need to open the lid, or I ask an adult for help.","Сначала мне нужно открыть крышку или попросить взрослого о помощи.")]), ] # ---------------- STYLES ---------------- en_q = st("enq", fontName="DB", fontSize=12, leading=16) ru_q = st("ruq", fontSize=10, leading=13, textColor=C("#5B6578")) en_a = st("ena", fontName="DB", fontSize=12, leading=16, textColor=C("#14532D")) ru_a = st("rua", fontSize=10, leading=13, textColor=C("#3F7D58")) lab = st("lab", fontName="DB", fontSize=9.5, leading=12, textColor=colors.white) hdr = st("hdr", fontName="DB", fontSize=15, leading=18, textColor=colors.white) hdrR = st("hdrR", fontName="DB", fontSize=11, leading=14, textColor=colors.white, alignment=2) small = st("small", fontSize=9, leading=12, textColor=C("#5B6578")) CW = W - 3.6*cm def card(q): col, light = C(q["color"]), C(q["light"]) head = Table([[Paragraph(f"Question {q['n']}", hdr), Paragraph(f"{q['topic']}", hdrR)]], colWidths=[CW*0.5, CW*0.5]) head.setStyle(TableStyle([("BACKGROUND",(0,0),(-1,-1),col), ("LEFTPADDING",(0,0),(-1,-1),12),("RIGHTPADDING",(0,0),(-1,-1),12), ("TOPPADDING",(0,0),(-1,-1),6),("BOTTOMPADDING",(0,0),(-1,-1),7), ("VALIGN",(0,0),(-1,-1),"MIDDLE")])) qcells = [] for en, ru in q["q"]: qcells += [Paragraph(en, en_q), Paragraph(ru, ru_q), Spacer(1,5)] acells = [Paragraph("ANSWER / ОТВЕТ", st("al", fontName="DB", fontSize=9, leading=11, textColor=C("#1E8449"))), Spacer(1,3)] for en, ru in q["a"]: acells += [Paragraph(en, en_a), Paragraph(ru, ru_a), Spacer(1,4)] t = Table([[head],[qcells],[acells]], colWidths=[CW]) t.setStyle(TableStyle([ ("BACKGROUND",(0,0),(0,0),col), ("BACKGROUND",(0,1),(0,1),light), ("BACKGROUND",(0,2),(0,2),C("#F2FBF4")), ("LEFTPADDING",(0,1),(-1,-1),12),("RIGHTPADDING",(0,1),(-1,-1),12), ("LEFTPADDING",(0,0),(0,0),0),("RIGHTPADDING",(0,0),(0,0),0), ("TOPPADDING",(0,0),(0,0),0),("BOTTOMPADDING",(0,0),(0,0),0), ("TOPPADDING",(0,1),(-1,1),9),("BOTTOMPADDING",(0,1),(-1,1),2), ("TOPPADDING",(0,2),(-1,2),8),("BOTTOMPADDING",(0,2),(-1,2),4), ("LINEABOVE",(0,2),(-1,2),1.2,C("#7BC98F"),0,(4,3)), ("BOX",(0,0),(-1,-1),1.6,col), ("ROUNDEDCORNERS",[10,10,10,10]), ])) return KeepTogether([t, Spacer(1, 14)]) def banner(text_en, text_ru, color): t = Table([[Paragraph(text_en, st("b1", fontName="DB", fontSize=20, leading=24, textColor=colors.white)),], [Paragraph(text_ru, st("b2", fontSize=12, leading=15, textColor=colors.white))]], colWidths=[CW]) t.setStyle(TableStyle([("BACKGROUND",(0,0),(-1,-1),C(color)), ("LEFTPADDING",(0,0),(-1,-1),16),("TOPPADDING",(0,0),(0,0),10),("BOTTOMPADDING",(0,1),(0,1),10), ("TOPPADDING",(0,1),(0,1),0),("BOTTOMPADDING",(0,0),(0,0),0),("ROUNDEDCORNERS",[12,12,12,12])])) return t # ---------------- PAGE DECORATION ---------------- def dots(c, colors_list): import random random.seed(4) for i in range(26): c.setFillColor(C(random.choice(colors_list))) c.setFillAlpha(0.25) x = random.uniform(0, W); y = random.choice([random.uniform(H-1.4*cm, H), random.uniform(0, 1.3*cm)]) c.circle(x, y, random.uniform(3, 9), stroke=0, fill=1) c.setFillAlpha(1) PAL = ["#2E86DE","#F39C12","#E84393","#8E44AD","#16A085","#E74C3C","#0ABDE3","#27AE60"] def page_bg(c, doc): c.saveState() c.setFillColor(C("#FFFDF6")); c.rect(0,0,W,H,stroke=0,fill=1) dots(c, PAL) c.setFont("D", 8.5); c.setFillColor(C("#7A8499")) c.drawString(1.8*cm, 0.9*cm, "Kitchen Chef Handbook / Книга юного шеф-повара") c.drawRightString(W-1.8*cm, 0.9*cm, f"Page {doc.page}") c.restoreState() def cover_bg(c, doc): c.saveState() c.setFillColor(C("#FFF6D6")); c.rect(0,0,W,H,stroke=0,fill=1) # big colored circles import random random.seed(11) for i in range(40): c.setFillColor(C(random.choice(PAL))); c.setFillAlpha(0.22) c.circle(random.uniform(0,W), random.uniform(0,H), random.uniform(10,55), stroke=0, fill=1) c.setFillAlpha(1) # title card c.setFillColor(C("#2E86DE")); c.roundRect(2*cm, H-12.5*cm, W-4*cm, 8.5*cm, 25, stroke=0, fill=1) c.setFillColor(C("#F39C12")); c.roundRect(2*cm+6, H-12.5*cm-6, W-4*cm, 8.5*cm, 25, stroke=0, fill=0) c.setFillColor(colors.white) c.setFont("DB", 38); c.drawCentredString(W/2, H-6.8*cm, "KITCHEN CHEF") c.setFont("DB", 38); c.drawCentredString(W/2, H-8.6*cm, "HANDBOOK") c.setFont("D", 16); c.drawCentredString(W/2, H-10.2*cm, "Questions, Answers and Russian Translation") c.setFont("D", 14); c.drawCentredString(W/2, H-11.3*cm, "Вопросы, ответы и перевод на русский язык") # parts boxes c.setFillColor(C("#16A085")); c.roundRect(2*cm, H-17.5*cm, (W-5*cm)/2, 3.8*cm, 16, stroke=0, fill=1) c.setFillColor(C("#E84393")); c.roundRect(2*cm+(W-5*cm)/2+1*cm, H-17.5*cm, (W-5*cm)/2, 3.8*cm, 16, stroke=0, fill=1) c.setFillColor(colors.white) bw=(W-5*cm)/2 c.setFont("DB", 14); c.drawCentredString(2*cm+bw/2, H-15.4*cm, "PART 1") c.setFont("D", 11); c.drawCentredString(2*cm+bw/2, H-16.1*cm, "Logic in the Kitchen") c.setFont("D", 10); c.drawCentredString(2*cm+bw/2, H-16.7*cm, "Логика на кухне (Q1-5)") x2=2*cm+bw+1*cm+bw/2 c.setFont("DB", 14); c.drawCentredString(x2, H-15.4*cm, "PART 2") c.setFont("D", 11); c.drawCentredString(x2, H-16.1*cm, "Cause & Effect Chef") c.setFont("D", 10); c.drawCentredString(x2, H-16.7*cm, "Причина и следствие (Q6-10)") # tip c.setFillColor(C("#1F2A5A")); c.setFont("DB", 13) c.drawCentredString(W/2, H-19.7*cm, "How to use this book / Как пользоваться книгой") c.setFont("D", 11) lines = [("1. Read the question. Look at the Russian under each sentence.","1. Прочитай вопрос. Смотри перевод под каждым предложением."), ("2. Think and say your answer before you look.","2. Подумай и скажи ответ, прежде чем смотреть."), ("3. Check your answer in the green box.","3. Проверь свой ответ в зелёной рамке.")] y = H-20.6*cm for en, ru in lines: c.setFillColor(C("#1F2A5A")); c.setFont("D", 11); c.drawCentredString(W/2, y, en) c.setFillColor(C("#5B6578")); c.setFont("D", 9.5); c.drawCentredString(W/2, y-0.5*cm, ru) y -= 1.35*cm c.restoreState() doc = BaseDocTemplate("/tmp/workspace/kitchen-handbook/output/Kitchen_Chef_Handbook.pdf", pagesize=A4, title="Kitchen Chef Handbook", author="Orris", leftMargin=1.8*cm, rightMargin=1.8*cm, topMargin=1.6*cm, bottomMargin=1.6*cm) fr = Frame(1.8*cm, 1.6*cm, W-3.6*cm, H-3.2*cm, id="f", leftPadding=0, rightPadding=0, topPadding=0, bottomPadding=0) doc.addPageTemplates([PageTemplate(id="cover", frames=[fr], onPage=cover_bg), PageTemplate(id="body", frames=[fr], onPage=page_bg)]) S = [NextPageTemplate("body"), PageBreak()] for part in (1, 2): if part == 1: S += [banner("PART 1: Logic in the Kitchen", "ЧАСТЬ 1: Логика на кухне", "#16A085"), Spacer(1,12)] else: S += [PageBreak(), banner("PART 2: Cause & Effect Chef (Present Simple)", "ЧАСТЬ 2: Причина и следствие (Present Simple)", "#E84393"), Spacer(1,6), Paragraph("In the story, Omar's mom heats water to make him warm. Let's look at more causes and effects in the kitchen!", st("i1", fontSize=10.5, leading=14)), Paragraph("В истории мама Омара греет воду, чтобы ему стало тепло. Давай посмотрим на другие причины и следствия на кухне!", st("i2", fontSize=9.5, leading=13, textColor=C("#5B6578"))), Spacer(1,12)] for q in Q: if q["part"] == part: S.append(card(q)) # Answer key S += [PageBreak(), banner("Quick Answer Key", "Краткие ответы", "#2E86DE"), Spacer(1,12)] rows = [[Paragraph("No.", lab), Paragraph("Answer", lab), Paragraph("Ответ", lab)]] for q in Q: rows.append([Paragraph(str(q["n"]), st("k0", fontName="DB", fontSize=11, textColor=C(q["color"]))), Paragraph(" ".join(e for e,_ in q["a"][:2]) if q["n"]!=3 else q["a"][0][0], st("k1", fontSize=10, leading=13)), Paragraph(" ".join(r for _,r in q["a"][:2]) if q["n"]!=3 else q["a"][0][1], st("k2", fontSize=9.5, leading=12, textColor=C("#5B6578")))]) kt = Table(rows, colWidths=[1.3*cm, CW*0.5-0.65*cm, CW*0.5-0.65*cm], repeatRows=1) ks = [("BACKGROUND",(0,0),(-1,0),NAVY),("VALIGN",(0,0),(-1,-1),"MIDDLE"), ("TOPPADDING",(0,0),(-1,-1),6),("BOTTOMPADDING",(0,0),(-1,-1),6), ("LEFTPADDING",(0,0),(-1,-1),8),("GRID",(0,0),(-1,-1),0.6,C("#D5DAE5")), ("ROUNDEDCORNERS",[8,8,8,8])] for i,q in enumerate(Q, start=1): ks.append(("BACKGROUND",(0,i),(-1,i),C(q["light"]))) kt.setStyle(TableStyle(ks)) S.append(kt) doc.build(S) print("ok") EOF cd /tmp/workspace/kitchen-handbook && python3 build.py && python3 -c " import pdfplumber p=pdfplumber.open('output/Kitchen_Chef_Handbook.pdf');print(len(p.pages)) for i,pg in enumerate(p.pages): print(i+1, (pg.extract_text() or '')[:150].replace('\n',' | ')) "
cd /tmp/workspace/kitchen-handbook && python3 -c " import pdfplumber p=pdfplumber.open('output/Kitchen_Chef_Handbook.pdf') for i,pg in enumerate(p.pages): pg.to_image(resolution=60).save(f'p{i+1}.png') print('done')"; ls
Kitchen Chef Handbook
PDF Document · PDF