This repository has been archived by the owner on Mar 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.py
79 lines (62 loc) · 2.44 KB
/
handler.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
75
76
77
78
import json
import os
from dotenv import load_dotenv
load_dotenv()
from src.decipherability import find_decipherable_words_above_threshold, compute_decipherability_for_text, \
find_words_with_non_mastered_LO
from src.load_dico import load_dico
dico = load_dico(
os.getenv("MANULEX_SPREADSHEET_ID"),
os.getenv("GOOGLE_REFRESH_TOKEN"),
os.getenv("GOOGLE_CLIENT_ID"),
os.getenv("GOOGLE_CLIENT_SECRET")
)
def find_mastered_words(event, context):
mastered_relations = list(
map(str.strip, (event["queryStringParameters"].get("masteredRelations") or '').split(','))
)
threshold = float(event["queryStringParameters"].get("threshold") or 1)
include_words_with_muted_letters = event["queryStringParameters"].get("includeWordsWithMutedLetters") == 'true'
decipherable_words = find_decipherable_words_above_threshold(dico,
mastered_relations,
threshold=threshold,
include_words_with_muted_letters=False)
response = {
"statusCode": 200,
"body": json.dumps(decipherable_words),
"headers": {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
}
}
return response
def decipherability_text(event, context):
mastered_relations = list(
map(str.strip, (event["queryStringParameters"]["masteredRelations"] or '').split(','))
)
text = event["queryStringParameters"]["text"]
decipherability = compute_decipherability_for_text(dico, mastered_relations, text)
response = {
"statusCode": 200,
"body": decipherability,
"headers": {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
}
}
return response
def find_mastered_words_with_LO(event, context):
mastered_relations = list(
map(str.strip, (event["queryStringParameters"]["masteredRelations"] or '').split(','))
)
LO = event["queryStringParameters"]["LO"]
decipherable_words = find_words_with_non_mastered_LO(dico, LO, mastered_relations)
response = {
"statusCode": 200,
"body": json.dumps(decipherable_words),
"headers": {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
}
}
return response