forked from pinico42/revi.se
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Question.py
65 lines (42 loc) · 1.92 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import requests
import json
import random
ListForDefinitions = []
ListForTerms = []
LessThanNumberOfQuestions = 0
NumberOfQuestions = 20
ListToExport = []
QuestionNotRepeated = []
ListForEnerites = []
# This will find a specified set then set the varible search results to results
setid = '45301'
search = 'https://api.quizlet.com/2.0/sets/' + setid + '/terms?client_id=RFsBbdeZFt&whitespace=1'
TempStore = requests.get(search)
SearchResults = TempStore.text
#Will find key points in the data by finding repeating syntax
TermPosition = SearchResults.find("term")
#Once there are no more "terms" (at the end of the list) the .find will return -1
while TermPosition > 1:
SearchResults = SearchResults[TermPosition:len(SearchResults)]
ColonPosition = SearchResults.find(":")
ComaPosistion = SearchResults.find(",")
ListForTerms.append(str(SearchResults[ColonPosition+3:ComaPosistion-1]))
DefinitionPosition = SearchResults.find("definition")
SearchResults = SearchResults[DefinitionPosition:len(SearchResults)]
ColonPosition = SearchResults.find(":")
ComaPosistion = SearchResults.find(",")
ListForDefinitions.append(str(SearchResults[ColonPosition+3:ComaPosistion-1]))
TermPosition = SearchResults.find("term")
# compiles a list with the terms and definitions
#If its less that 20 all cards avalible is selected
if len(ListForTerms) < 21:
for Current in range(0,len(ListForTerms)-1):
ListToExport.append(ListForTerms[Current] + " = " + ListForDefinitions[Current])
#Otherwise 20 random questions are selected for the cards
else:
while LessThanNumberOfQuestions < NumberOfQuestions:
RandomNO = random.randint(1,(len(ListForTerms)))-1
ListToExport.append(ListForTerms[RandomNO] + " = " + ListForDefinitions[RandomNO])
LessThanNumberOfQuestions = LessThanNumberOfQuestions + 1
print (ListToExport)
print (ListForEnerites)