1 changed files with 37 additions and 0 deletions
@ -0,0 +1,37 @@ |
|||||
|
# python -m venv .venv |
||||
|
# .venv\Scripts\activate |
||||
|
# pip install wikipedia |
||||
|
|
||||
|
import wikipedia |
||||
|
|
||||
|
def najdi_na_wiki(tema,jazyk="cs"): |
||||
|
""" |
||||
|
Nastaví jazyk a zkusí najít shrnutí stránky na téma |
||||
|
""" |
||||
|
# en = angličtina, cs = čeština, sk = slovenština |
||||
|
wikipedia.set_lang(jazyk) |
||||
|
|
||||
|
try: |
||||
|
vysledek = wikipedia.summary(tema,sentences=5) |
||||
|
return vysledek |
||||
|
except wikipedia.exceptions.PageError: |
||||
|
return "Je mi líto, ale stránku se nepodařilo najít" |
||||
|
except wikipedia.exceptions.DisambiguationError: |
||||
|
return "Je to mocobecné, zkus být konkretnější" |
||||
|
|
||||
|
# --- hlavní část programu ---- |
||||
|
print("--- WIKIPEDIA BOT ---") |
||||
|
print("zadej téma, které tě zajíma(např. Praha, Python, Minecraft)") |
||||
|
|
||||
|
while True: |
||||
|
tema_input = input("\n Hledat (nebo 'konec' pro ukončení):") |
||||
|
if tema_input == "konec" or tema_input == "q": |
||||
|
break |
||||
|
if tema_input: |
||||
|
print("hledám...") |
||||
|
info = najdi_na_wiki(tema=tema_input) |
||||
|
print("-"*30) |
||||
|
print(info) |
||||
|
print("-"*30) |
||||
|
|
||||
|
|
||||
Loading…
Reference in new issue