-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_question.py
40 lines (32 loc) · 1.05 KB
/
get_question.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import csv
import requests
from bs4 import BeautifulSoup, GuessedAtParserWarning
import wikipedia
def get_page(random):
result = wikipedia.summary(random, sentences=2)
return result.split(' — ')[1].lower().capitalize().split("\n")[0]
def random_calling():
quesion = wikipedia.random(1)
print(quesion, len(str(quesion).split()))
if len(str(quesion).split()) == 1:
return str(quesion)
else:
return random_calling()
def get_question():
wikipedia.set_lang('ru')
call = random_calling()
try:
if all(i.isalpha() for i in call) and ord(call[0]) > 1000:
return [call.lower().capitalize(), get_page(call)]
else:
return get_question()
except:
return get_question()
print(ord('а'))
with open('questions.csv', mode='w', encoding='utf-8') as csvfile:
writer = csv.writer(
csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
for _ in range(10):
question = get_question()
print([_] + question)
writer.writerow(question)