diff --git a/go.mod b/go.mod index f50d0b9..6dd610c 100644 --- a/go.mod +++ b/go.mod @@ -10,9 +10,11 @@ require ( ) require ( + github.com/SebastiaanKlippert/go-wkhtmltopdf v1.9.0 // indirect github.com/andybalholm/cascadia v1.3.1 // indirect github.com/deckarep/golang-set/v2 v2.3.0 // indirect github.com/icza/gox v0.0.0-20230117093757-93f961aa2755 // indirect + github.com/pdfcpu/pdfcpu v0.4.0 // indirect golang.org/x/net v0.7.0 // indirect ) diff --git a/go.sum b/go.sum index 524262b..00da0ad 100644 --- a/go.sum +++ b/go.sum @@ -7,6 +7,8 @@ github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= github.com/PuerkitoBio/goquery v1.8.1 h1:uQxhNlArOIdbrH1tr0UXwdVFgDcZDrZVdcpygAcwmWM= github.com/PuerkitoBio/goquery v1.8.1/go.mod h1:Q8ICL1kNUJ2sXGoAhPGUdYDJvgQgHzJsnnd3H7Ho5jQ= +github.com/SebastiaanKlippert/go-wkhtmltopdf v1.9.0 h1:DNrExYwvyyI404SxdUCCANAj9TwnGjRfa3cYFMNY1AU= +github.com/SebastiaanKlippert/go-wkhtmltopdf v1.9.0/go.mod h1:SQq4xfIdvf6WYKSDxAJc+xOJdolt+/bc1jnQKMtPMvQ= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g= @@ -278,6 +280,8 @@ github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnh github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= +github.com/pdfcpu/pdfcpu v0.4.0 h1:381iGNvMeLP+GFqIAqgd0LSj36AsK3JH4UTaF6D5jRc= +github.com/pdfcpu/pdfcpu v0.4.0/go.mod h1:9NDeS6hrCheauxw6YUlzgL/q6At2+PMzUKyFcfUzLLY= github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac= github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= diff --git a/modules/tg/week_shedule.go b/modules/tg/week_shedule.go index 6d071cd..32db813 100644 --- a/modules/tg/week_shedule.go +++ b/modules/tg/week_shedule.go @@ -2,11 +2,16 @@ package tg import ( "fmt" + "io/ioutil" + "log" "math" + "os" + "strings" "time" "git.l9labs.ru/anufriev.g.a/l9_stud_bot/modules/database" "git.l9labs.ru/anufriev.g.a/l9_stud_bot/modules/ssau_parser" + wkhtml "github.com/SebastiaanKlippert/go-wkhtmltopdf" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" "github.com/icza/gox/timex" ) @@ -88,23 +93,84 @@ func (bot *Bot) GetWeekSummary(shedules []database.ShedulesInUser, dw int, isPer shedule[p[0].NumInShedule][day] = p } - bot.CreateHTMLShedule(week, shedule, dates, times) + html := bot.CreateHTMLShedule(week, shedule, dates, times) + + f, _ := os.Create("sh.html") + defer f.Close() + f.WriteString(html) + + wkhtml.SetPath("C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe") + pdfg, err := wkhtml.NewPDFGenerator() + if err != nil { + log.Fatal(err) + } + pdfg.Dpi.Set(300) + pdfg.MarginBottom.Set(0) + pdfg.MarginTop.Set(0) + pdfg.MarginLeft.Set(0) + pdfg.MarginRight.Set(0) + pdfg.Orientation.Set(wkhtml.OrientationLandscape) + pdfg.PageSize.Set(wkhtml.PageSizeA4) + pdfg.AddPage(wkhtml.NewPageReader(strings.NewReader(html))) + + err = pdfg.Create() + if err != nil { + log.Fatal(err) + } + + err = pdfg.WriteFile("./sh.pdf") + if err != nil { + log.Fatal(err) + } + + photoBytes, err := ioutil.ReadFile("./sh.pdf") + if err != nil { + panic(err) + } + fname := fmt.Sprintf("Расписание %d неделя.pdf", week-bot.Week) + photoFileBytes := tgbotapi.FileBytes{ + Name: fname, + Bytes: photoBytes, + } + + msg := tgbotapi.NewDocument(bot.TG_user.TgId, photoFileBytes) + _, err = bot.TG.Send(msg) + if err != nil { + log.Println(err) + } + var shId int64 + if isPersonal { + shId = 0 + } else { + shId = shedules[0].SheduleId + } + markup := SummaryKeyboard( + "week", + shId, + shedules[0].IsTeacher, + dw, + ) + str := fmt.Sprintf("Расписание на %d неделю сообщением ниже 👇", week-bot.Week) + bot.EditOrSend(str, markup, editMsg...) } const head = `
Время | \n" for i, d := range dates { day := d.Format("02") - html += fmt.Sprintf("%s %s | ", weekdays[i], day)
}
+ html += "
---|---|
%s %s | ", begin, end)
+ for i, l := range tline {
+
if len(l) > 0 {
html += fmt.Sprintf(lessonHead, l[0].Type, l[0].Name)
- html += "\n"
+ if l[0].TeacherId != 0 {
+ var t database.Teacher
+ bot.DB.ID(l[0].TeacherId).Get(&t)
+ name := GenerateName(t)
+ html += fmt.Sprintf("\n" + } + if i%7 == 6 { + html += " |