Mobil ilovalarni ishlab chiqish
Telegram API dan foydalanib bot orqali telegram guruhiga yoki kanalga post
Download 53.06 Kb. Pdf ko'rish
|
Mobil ilovalarni ishlab chiqish
Telegram API dan foydalanib bot orqali telegram guruhiga yoki kanalga post
qilish, xabarlarni tahrirlash. package main import ( "log" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api" ) var numericKeyboard = tgbotapi.NewReplyKeyboard( tgbotapi.NewKeyboardButtonRow( tgbotapi.NewKeyboardButton("Biz_haqimizda"), tgbotapi.NewKeyboardButton("Rasimlar"), tgbotapi.NewKeyboardButton("Reklama"), ), tgbotapi.NewKeyboardButtonRow( tgbotapi.NewKeyboardButton("Pasportlarimiz"), tgbotapi.NewKeyboardButton("Dilomlarimiz"), tgbotapi.NewKeyboardButton("Ruyxat"), ), ) func main() { bot, err := tgbotapi.NewBotAPI("2024735399:AAGJwIKt181lUx3Tq5h10- kwdfK4qJEVkLc") if err != nil { log.Panic(err) } bot.Debug = true log.Printf("Authorized on account %s", bot.Self.UserName) u := tgbotapi.NewUpdate(0) u.Timeout = 60 updates, err := bot.GetUpdatesChan(u) for update := range updates { msg := tgbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text) switch update.Message.Text { case "/start": msg.ReplyMarkup = numericKeyboard case "/close": msg.ReplyMarkup = tgbotapi.NewRemoveKeyboard(true) } if update.Message == nil { // ignore non-Message updates continue } switch update.Message.Text { case "Biz_haqimizda": msgg := tgbotapi.NewMessage(update.Message.Chat.ID, "Biz 219 18 guruppamiz ") bot.Send(msgg) case "Rasimlar": file := "./guruppa.jpg" imsg := tgbotapi.NewPhotoUpload(update.Message.Chat.ID, file) bot.Send(imsg) case "Reklama": tel := tgbotapi.NewMessage(update.Message.Chat.ID, "Bizda reklama pullik") bot.Send(tel) case "Pasportlarimiz": tel := tgbotapi.NewMessage(update.Message.Chat.ID, "Hali passport haqida malumot bera olmaymiz") bot.Send(tel) case "Dilomlarimiz": tel := tgbotapi.NewMessage(update.Message.Chat.ID, "Hali olmadik olsak sizga nusxasini beramiz") bot.Send(tel) case "Ruyxat": file2 := "./jurnal.jpg" imsg2 := tgbotapi.NewPhotoUpload(update.Message.Chat.ID, file2) bot.Send(imsg2) } } } Yandex Translate API, ko'p tillarda matn tarjima qilishga yordam beruvchi o'tish mumkin bo'lgan yuqori sifatli bir API hisoblanadi. Siz birinchi qadam sifatida, Yandex Translate API-ni ishlatib, tilni aniqlashingiz va so'ng uni o'girish dasturlarini yaratishingiz kerak. Quyidagi kodlarni Python dasturi sifatida yozish mumkin: import requests import json def translate_text(text, target_language): url = 'https://translate.yandex.net/api/v1.5/tr.json/translate' api_key = 'API_KEY' # API kaliti yoki kaliti va API-ni olish usullari o'zgaruvchisi params = {'key': api_key, 'text': text, 'lang': target_language} response = requests.get(url, params=params) return json.loads(response.text)['text'][0] text = 'Assalomu alaykum, dunyo!' target_languages = ['en', 'ru', 'fr', 'de', 'es', 'it', 'tr', 'uz', 'ja', 'ko'] for lang in target_languages: translated_text = translate_text(text, lang) print(f'{lang.upper()}: {translated_text}') Musobek Jgar, [18.04.2023 11:07] Bu dasturda, translate_text() funksiyasi Yandex Translate API-ni ishlatadi va tarjima maqsadida matnni qabul qiladi. Keyingi qadamda, o'giruvchi dasturimizning tilini aniqlash uchun til kodi listasini aniqlashimiz kerak. Misol uchun, yuqorida ko'rsatilgan kod tili sifatida ingliz, rus, fransuz, nemis, ispan, italyan, turk, o'zbek, yapon va koreyacha tilini aniqlash uchun ishlatiladi. Yuqoridagi dasturni o'zgartirib, o'z maqsadingiz uchun kerakli tilni aniqlashingiz va matnni tarjima qilishingiz mumkin. Download 53.06 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling