-
Notifications
You must be signed in to change notification settings - Fork 2
/
QuestionMakermk2.py
77 lines (49 loc) · 1.99 KB
/
QuestionMakermk2.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
66
67
68
69
70
71
72
73
74
import requests
import json
import random
from itertools import izip
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")
def RandomNOGen():
global RandInt1
global RandInt2
RandInt1 = random.randint(0,len(SearchResults)-1)
RandInt2 = random.randint(0,len(SearchResults)-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
if len(ListForTerms) < 21:
for Current in range(0,len(ListForTerms)-1):
RandomNOGen()
ListToExport.append(ListForTerms[Current])
ListToExport.append(ListForDefinitions[Current])
else:
while LessThanNumberOfQuestions < NumberOfQuestions:
RandomNO = random.randint(1,(len(ListForTerms)))-1
ListToExport.append(ListForTerms[RandomNO])
ListToExport.append(ListForDefinitions[RandomNO])
LessThanNumberOfQuestions = LessThanNumberOfQuestions + 1
i = iter(ListToExport)
b = dict(izip(i, i))
print json.dumps(b)