Wikipedia'dan nasıl bilgi çekilir?

doğru yazamadım büyük ihtimalle kontrol edebilir misiniz

import speech_recognition as sr
import wikipedia as wikipedia
from gtts import gTTS
from playsound import playsound
import random
from responsive_voice import ResponsiveVoice
from tkinter import *
def mainCommands(gender=ResponsiveVoice.MALE, rate=0.52, pitch=0.50, vol=1):
    engine = ResponsiveVoice()
    engine = ResponsiveVoice(lang=ResponsiveVoice.TURKISH)
    r = sr.Recognizer()

    def record(ask=False):
        with sr.Microphone() as source:
            if ask:
                print(ask)
            audio = r.listen(source)
            voice = ""
            try:
                voice = r.recognize_google(audio, language="tr-TR")
            except sr.UnknownValueError:
                engine.say("anlayamadım", gender=gender, rate=rate, pitch=pitch, vol=vol)
                engine.say("Lütfen arayüz de bulunan butona tekrar tıklayın ve yeniden konuşun", gender=gender, rate=rate, pitch=pitch, vol=vol)
                exit()

            except sr.UnknownValueError:
                engine.say("sistem çalışmadı", gender=gender, rate=rate, pitch=pitch, vol=vol)

            return voice


    def response(voice):
        global numb, month
        if "bilgi ver" in voice:
            engine.say("Aranıyor", gender=gender, rate=rate, pitch=pitch, vol=vol)
            voice = voice.replace("bilgi ver", "")
            results = record()
            results = wikipedia.summary(voice, sentences=3)
            engine.say("sonuçları okuyorum", gender=gender, rate=rate, pitch=pitch, vol=vol)
            time.sleep(1)
            engine.say(results, gender=gender, rate=rate, pitch=pitch, vol=vol)
            voice(results)

    def speak(string):
        tts = gTTS(string, lang="tr")
        rand = random.randint(1, 10000)
        file = "audio-" + str(rand) + ".mp3"
        tts.save(file)
        playsound(file)
        os.remove(file)
    time.sleep(1)
    while True:
        voice = record()
        voice = voice.lower()
        print(voice)
        response(voice)
        time.sleep(1)
pygame.mixer.init()
def gui(geometry, title):
    root = Tk()
    root.configure(background='white')
    root.geometry(f"{geometry}")
    root.title(f"{title}")
    b = Button(root, text="bana tıkla",bg="white", command=lambda: Thread(target=mainCommands).start())
    b.pack()
    root.resizable(0, 0)

if __name__ == "__main__":
    gui("300x200", "Jack Asistan")
    mainloop()

Öncelikle daha kısa yoldan yapılır mı, wikipedia modülü işe yararmı bilemem fakat ben şöyle bir çözüm ürettim.

    def response(voice):
        global numb, month
        if "bilgi ver" in voice:
            engine.say("hangi konuda bilgi vermemi istersin ?", gender=gender, rate=rate, pitch=pitch, vol=vol)
            results = record("hangi konuda bilgi vermemi istersin ?")
            engine.say(f"{results} için ufak bir bilgi veriyorum. ", gender=gender, rate=rate, pitch=pitch, vol=vol)

            wikipedia = f"https://tr.wikipedia.org/wiki/{results.capitalize().replace(' ','_')}"
            r = requests.get(url=wikipedia)
            soup = BeautifulSoup(r.content,"lxml")
            text = ""

            for i in soup.find_all("p"):
                text +=i.text
            with open("bilgi.txt","w",encoding="utf-8") as f:
                f.write(text)
            for j in range(8):
                with open("bilgi.txt","r",encoding="utf-8") as g:
                    okunacak_bilgi = g.readlines()
                engine.say(okunacak_bilgi[j], gender=gender, rate=rate, pitch=pitch, vol=vol)

            os.remove("bilgi.txt")

Tekrardan söylüyorum eğer wikipedia modülü bunları tek başına yapıyorsa ayrıyeten göründüğü üzere beautifulsoup veya requests modüllerine ihtiyaç olmayabilir.

1 Beğeni

kütüphane olarak beautifulsoup ve request mi import etmem gerekiyor

Ee tabi onları projeye eklemen gerekiyor

Exception in thread Thread-7 (mainCommands):
Traceback (most recent call last):
  File "C:\Users\Ali\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1009, in _bootstrap_inner
    self.run()
  File "C:\Users\Ali\AppData\Local\Programs\Python\Python310\lib\threading.py", line 946, in run
    self._target(*self._args, **self._kwargs)
  File "E:\Users\Ali Tabak\Desktop\Software\JackAsistan\main.py", line 623, in mainCommands
    response(voice)
  File "E:\Users\Ali Tabak\Desktop\Software\JackAsistan\main.py", line 587, in response
    soup = BeautifulSoup(r.content, "lxml")
  File "C:\Users\Ali\AppData\Local\Programs\Python\Python310\lib\site-packages\bs4\__init__.py", line 245, in __init__
    raise FeatureNotFound(
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?

https://www.google.com/search?q=bs4.FeatureNotFound%3A&sourceid=chrome&ie=UTF-8