-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
194 lines (159 loc) · 5.37 KB
/
app.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
from flask import Flask, request
app = Flask(__name__)
import dictionary as dictionary
import requests
import json
import sys
def getResults(tags):
# replace the spaces with underlines
tags = getUsableTags(tags)
# add a comma to the end of tags to prevent crashing and initialize individual tags
tags = tags + ","
tag1 = " "
tag2 = " "
tag3 = " "
tag4 = " "
tag5 = " "
# isolate each tag by commas
if (len(tags) > 0) & ("," in tags):
tag1 = tags[0:tags.index(",")]
tags = tags[tags.index(",") + 1:]
if (len(tags) > 0) & ("," in tags):
tag2 = tags[0:tags.index(",")]
tags = tags[tags.index(",") + 1:]
if (len(tags) > 0) & ("," in tags):
tag3 = tags[0:tags.index(",")]
tags = tags[tags.index(",") + 1:]
if (len(tags) > 0) & ("," in tags):
tag4 = tags[0:tags.index(",")]
tags = tags[tags.index(",") + 1:]
if (len(tags) > 0) & ("," in tags):
tag5 = tags[0:tags.index(",")]
tags = tags[tags.index(",") + 1:]
# create the url from the tags that the API will collect
tagSplit = "%3B%20"
buildURL = ("https://api.stackexchange.com/2.2/tags/" + tag1 + tagSplit + tag2 + tagSplit + tag3 + tagSplit +
tag4 + tagSplit + tag5 + "/faq?site=stackoverflow")
# url for testing, no longer needed
testURL = "https://api.stackexchange.com/2.2/tags/java%3B%20exception%3B%20FileNotFoundException/" \
"faq?site=stackoverflow"
# get the response from the API and save it as a JSON object
url = buildURL
response = requests.get(url)
responseJSON = response.json()
# For testing, print all of the results' title and link
"""
for i in range(len(responseJSON['items'])):
print((responseJSON['items'][i]['title']))
print((responseJSON['items'][i]['link']))
"""
return responseJSON
import json
with open('data.json', 'w', encoding='utf-8') as f:
json.dump(responseJSON, f, ensure_ascii=False, indent=4)
# replaces the spaces with underlines
def getUsableTags(tags):
workingTags = ""
originalTag = tags
for i in range(len(tags)):
if originalTag[i] == " ":
workingTags = workingTags + "_"
else:
workingTags = workingTags + originalTag[i]
return workingTags
#this should be templated
@app.route('/')
def hello_world():
return """<!DOCTYPE html>
<html lang="en">
<head>
<title>RubberDuck</title>
<script type="module" src="https://unpkg.com/@google/model-viewer/dist/model-viewer.min.js"></script>
<!--<link rel="stylesheet" href="rubber.css" id="change">-->
</head>
<body style="background-color: #073763ff;">
<!--<script src="duck.js"></script>-->
<p1 id="press">
</p1>
<model-viewer src="duck.glb" camera-controls auto-rotate auto-rotate-delay=10000 rotation-per-second="45deg" interaction-prompt=none camera-orbit="45deg 80deg" shadow-intensity="0" onclick="myFunction()" class="center" class="space"></model-viewer>
<h1 class="name" class="space">RubberDuck</h1>
<form action="/info" method="post" novalidate>
<input type="text" id="pEnter" class='input' name="tags" placeholder="What's your problem?">
<button>Send</button>
</form>
</body>
</html>"""
@app.route('/new')
def OUT2():
return """<!DOCTYPE html>
<html lang="en">
<head>
<style>
model-viewer {
float: initial;
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
margin-top: 200px;
width: 240px;
height: 240px;
}
h1 {
font-family: Montserrat;
font-size: 64px;
text-align: center;
color: white;
margin-top: 0px;
margin-bottom: 24px;
font-weight: bold;
}
input {
font-family: Montserrat;
border: none;
border-radius: 15px;
display: block;
width: 30%;
font-size: 16px;
float: center;
padding: 12px 20px;
margin: 0 auto;
margin-top: 2px;
margin-bottom: 0px;
background-image: url('searchIcon.png');
background-position: 97%;
background-size: 12px 12px;
background-repeat: no-repeat;
}
input:focus {
background-color: lightblue;
border: none;
outline: none;
border-radius: 15px;
}
@font-face {
font-family: Mont;
src: url(Montserrat-Bold.ttf);
font-weight: bold;
}
</style>
<title>RubberDuck</title>
<script type="module" src="https://unpkg.com/@google/model-viewer/dist/model-viewer.min.js"></script>
<!--<link rel="stylesheet" href="rubber.css" id="change">-->
</head>
<body style="background-color: #073763ff;">
<!--<script src="duck.js"></script>-->
<p1 id="press">
</p1>
<model-viewer src="duck.glb" camera-controls auto-rotate auto-rotate-delay=10000 rotation-per-second="45deg" interaction-prompt=none camera-orbit="45deg 80deg" shadow-intensity="0" onclick="myFunction()" class="center" class="space"></model-viewer>
<h1 class="name" class="space">RubberDuck</h1>
<h1>this is page 2</h1>
</body>
</html>"""
@app.route('/info', methods=['GET', 'POST'])
def info():
data = request.form["tags"]
print(data)
return getResults(data)
if __name__ == '__main__':
app.run(debug=True)