Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -11,10 +11,14 @@ from flask_jwt_extended import JWTManager, create_access_token
|
|
11 |
from middleware.authUser import auth_user
|
12 |
from datetime import timedelta
|
13 |
from controllers.demo import get_initial_data
|
14 |
-
from controllers.mindmap import saveMindmap, getMindmap, deleteMindmap, getMindmapByid
|
15 |
import json
|
|
|
16 |
from dotenv import load_dotenv
|
17 |
import os
|
|
|
|
|
|
|
18 |
|
19 |
load_dotenv()
|
20 |
|
@@ -33,11 +37,12 @@ restUri = os.getenv('REST_URI')
|
|
33 |
|
34 |
uri = f'mongodb+srv://{username}:{password}{restUri}'
|
35 |
|
36 |
-
client = MongoClient(uri
|
37 |
db = client.GenUpNexus
|
38 |
users_collection = db["users"]
|
39 |
interviews_collection = db["interviews"]
|
40 |
savedMindmap = db["savedMindmap"]
|
|
|
41 |
|
42 |
# Send a ping to confirm a successful connection
|
43 |
try:
|
@@ -64,6 +69,8 @@ def index():
|
|
64 |
def index2():
|
65 |
return "routes checking..."
|
66 |
|
|
|
|
|
67 |
@app.route('/tree', methods=["POST", "GET"])
|
68 |
def tree():
|
69 |
if request.method == 'POST':
|
@@ -157,7 +164,6 @@ def tree():
|
|
157 |
return jsonify({'success': True, 'data': response.text})
|
158 |
# return temp
|
159 |
|
160 |
-
|
161 |
@app.route('/tree/demo', methods=["POST"])
|
162 |
def treeDemo():
|
163 |
if request.method == 'POST':
|
@@ -166,54 +172,80 @@ def treeDemo():
|
|
166 |
print(query)
|
167 |
response = model.generate_content('''Generate a comprehensive knowledge map representing the user's query, suitable for ReactFlow visualization.
|
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 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
- to edit edges add style with stroke property and a hexcode value to it.
|
207 |
-
|
208 |
-
Topic is: ''' + query)
|
209 |
|
210 |
# response.text(8,)
|
211 |
print(response.text)
|
212 |
json_data = response.text
|
213 |
modified_json_data = json_data[8:-3]
|
214 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
# return temp
|
216 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
217 |
|
218 |
def res(user_id):
|
219 |
avg_text = 0
|
@@ -292,7 +324,7 @@ def interview():
|
|
292 |
"code_suggestions": "Any suggestions or optimizations to the code...in string format.",
|
293 |
}
|
294 |
|
295 |
-
At the end of the interview if no Questions are required then respond in the following
|
296 |
{
|
297 |
"text_correctness": "Test the correctness of text and return a range from 1 to 5 of correctness of text.",
|
298 |
"text_suggestions": "Some suggestions regarding the text_answer...."
|
@@ -487,7 +519,7 @@ def signup():
|
|
487 |
expires = timedelta(days=7)
|
488 |
access_token = create_access_token(identity={"email": email, "id": str(result.inserted_id)}, expires_delta=expires)
|
489 |
|
490 |
-
res = {"name": name, "email": email}
|
491 |
|
492 |
return jsonify({"result": res, "token": access_token}), 201
|
493 |
|
@@ -508,7 +540,7 @@ def signin():
|
|
508 |
expires = timedelta(days=7)
|
509 |
access_token = create_access_token(identity={"email": user['email'], "id": str(user['_id'])}, expires_delta=expires)
|
510 |
|
511 |
-
res = {"name": user['name'], "email": user['email'], "
|
512 |
|
513 |
return jsonify({"result": res, "token": access_token}), 200
|
514 |
|
@@ -536,6 +568,13 @@ def mindmapSave():
|
|
536 |
data = request.json
|
537 |
return saveMindmap(data, userId, savedMindmap)
|
538 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
539 |
@app.route('/mindmap/get', methods=['GET'])
|
540 |
@auth_user
|
541 |
def mindmapGet():
|
@@ -543,10 +582,8 @@ def mindmapGet():
|
|
543 |
return getMindmap(userId, savedMindmap)
|
544 |
|
545 |
@app.route('/mindmap/get/<id>', methods=['GET'])
|
546 |
-
@auth_user
|
547 |
def mindmapGetById(id):
|
548 |
-
|
549 |
-
return getMindmapByid(userId, id, savedMindmap)
|
550 |
|
551 |
@app.route('/mindmap/delete', methods=['POST'])
|
552 |
@auth_user
|
@@ -563,5 +600,267 @@ def mindmapDemo():
|
|
563 |
return get_initial_data(), 200
|
564 |
|
565 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
566 |
if __name__ == '__main__':
|
567 |
-
app.run(debug=True)
|
|
|
11 |
from middleware.authUser import auth_user
|
12 |
from datetime import timedelta
|
13 |
from controllers.demo import get_initial_data
|
14 |
+
from controllers.mindmap import saveMindmap, getMindmap, deleteMindmap, getMindmapByid, saveMindmapById
|
15 |
import json
|
16 |
+
from bson import ObjectId
|
17 |
from dotenv import load_dotenv
|
18 |
import os
|
19 |
+
import re
|
20 |
+
import requests
|
21 |
+
|
22 |
|
23 |
load_dotenv()
|
24 |
|
|
|
37 |
|
38 |
uri = f'mongodb+srv://{username}:{password}{restUri}'
|
39 |
|
40 |
+
client = MongoClient(uri)
|
41 |
db = client.GenUpNexus
|
42 |
users_collection = db["users"]
|
43 |
interviews_collection = db["interviews"]
|
44 |
savedMindmap = db["savedMindmap"]
|
45 |
+
roadmap_collection = db['roadmaps']
|
46 |
|
47 |
# Send a ping to confirm a successful connection
|
48 |
try:
|
|
|
69 |
def index2():
|
70 |
return "routes checking..."
|
71 |
|
72 |
+
|
73 |
+
#generative model routes
|
74 |
@app.route('/tree', methods=["POST", "GET"])
|
75 |
def tree():
|
76 |
if request.method == 'POST':
|
|
|
164 |
return jsonify({'success': True, 'data': response.text})
|
165 |
# return temp
|
166 |
|
|
|
167 |
@app.route('/tree/demo', methods=["POST"])
|
168 |
def treeDemo():
|
169 |
if request.method == 'POST':
|
|
|
172 |
print(query)
|
173 |
response = model.generate_content('''Generate a comprehensive knowledge map representing the user's query, suitable for ReactFlow visualization.
|
174 |
|
175 |
+
**Prompt:** {query}
|
176 |
+
|
177 |
+
**Structure:**
|
178 |
+
|
179 |
+
- Top-level node: Represent the user's query.
|
180 |
+
- Sub-nodes branching out based on the query's relevance:
|
181 |
+
- Leverage external knowledge sources (e.g., Wikipedia, knowledge graphs, domain-specific APIs) to identify relevant sub-concepts, related entities, and potential relationships.
|
182 |
+
- Consider including different categories of sub-nodes:
|
183 |
+
- **Concepts:** Core ideas or principles related to the query.
|
184 |
+
- **Subfields:** Specialized areas within the main topic.
|
185 |
+
- **Applications:** Practical uses of the concept or subfield.
|
186 |
+
- **Tools and Technologies:** Software or platforms used to implement the concepts.
|
187 |
+
- **Examples:** Illustrative instances or use cases.
|
188 |
+
- **Historical Context:** Milestones or key figures in the topic's development.
|
189 |
+
- **See Also:** Links to broader concepts or related areas for the further exploration.
|
190 |
+
|
191 |
+
|
192 |
+
**Content:**
|
193 |
+
|
194 |
+
- Each node should have a label describing the concept, entity, or tool.
|
195 |
+
- Include brief descriptions, definitions, or key points within the nodes or as tooltips.
|
196 |
+
- Consider using icons to visually represent different categories of nodes (e.g.💡 for concepts, ⚙️ for tools, 📅 for historical context, 🧩 for subfields).
|
197 |
+
- Also follow the n-ary tree structure for better visualization.
|
198 |
+
- There should be atmax 10 nodes.
|
199 |
+
- Ensure the knowledge map is visually appealing, well-organized, and easy to navigate.
|
200 |
+
|
201 |
+
**Desired Format:**
|
202 |
+
|
203 |
+
- JSON structure compatible with ReactFlow:
|
204 |
+
- nodes (list): id, position, type(custom), data(label, description, icon, category).
|
205 |
+
- edges (list): id, source, target, label(if required), animated (true or false), style(stroke).
|
206 |
+
- The nodes should not overlap and have enough spacing for readability, therefore adjust it position accordingly.
|
207 |
+
- keep atleast 2 edges "animated":true.
|
208 |
+
- Strictly keep the all the nodes with type property value as custom.
|
209 |
+
- to edit edges add style with stroke property and a hexcode value to it(Only use this color: #e92a67, #a853ba, #2a8af6, #e92a67).
|
210 |
+
|
211 |
+
Topic is: ''' + query)
|
|
|
|
|
|
|
212 |
|
213 |
# response.text(8,)
|
214 |
print(response.text)
|
215 |
json_data = response.text
|
216 |
modified_json_data = json_data[8:-3]
|
217 |
+
|
218 |
+
while True:
|
219 |
+
new_object_id = ObjectId()
|
220 |
+
if savedMindmap.find_one({'_id': new_object_id}) is None:
|
221 |
+
break
|
222 |
+
|
223 |
+
return jsonify({'success': True, 'data': modified_json_data, 'objectId': str(new_object_id)})
|
224 |
# return temp
|
225 |
|
226 |
+
@app.route('/mindmap/generate/data', methods=["POST"])
|
227 |
+
def generateData():
|
228 |
+
if request.method == 'POST':
|
229 |
+
data = request.get_json()
|
230 |
+
topic = data.get('topic')
|
231 |
+
description = data.get('description')
|
232 |
+
category = data.get('category')
|
233 |
+
print(topic)
|
234 |
+
print(description)
|
235 |
+
print(category)
|
236 |
+
response = model.generate_content('''I will provide you a topic. You need to generate its detailed explanation also provide its links to the related topics and subtopics and respond with html format with tailiwindcss styling, wrapped under a single<div></div>.
|
237 |
+
|
238 |
+
- keep the background tranparent.
|
239 |
+
- Title should be in text-2xl font-bold.
|
240 |
+
- Subtitle should be in text-lg font-semibold.
|
241 |
+
- make sure the content is well structured and easy to read.
|
242 |
+
- make sure the link text style is in text-aqua.
|
243 |
+
Topic: ''' + topic)
|
244 |
+
print(response.text)
|
245 |
+
json_data = response.text
|
246 |
+
modified_json_data = json_data[8:-3]
|
247 |
+
|
248 |
+
return jsonify({'success': True, 'data': modified_json_data})
|
249 |
|
250 |
def res(user_id):
|
251 |
avg_text = 0
|
|
|
324 |
"code_suggestions": "Any suggestions or optimizations to the code...in string format.",
|
325 |
}
|
326 |
|
327 |
+
At the end of the interview if no Questions are required then respond in the following format:
|
328 |
{
|
329 |
"text_correctness": "Test the correctness of text and return a range from 1 to 5 of correctness of text.",
|
330 |
"text_suggestions": "Some suggestions regarding the text_answer...."
|
|
|
519 |
expires = timedelta(days=7)
|
520 |
access_token = create_access_token(identity={"email": email, "id": str(result.inserted_id)}, expires_delta=expires)
|
521 |
|
522 |
+
res = {"name": name, "email": email, "userId": str(result.inserted_id)}
|
523 |
|
524 |
return jsonify({"result": res, "token": access_token}), 201
|
525 |
|
|
|
540 |
expires = timedelta(days=7)
|
541 |
access_token = create_access_token(identity={"email": user['email'], "id": str(user['_id'])}, expires_delta=expires)
|
542 |
|
543 |
+
res = {"name": user['name'], "email": user['email'], "userId": str(user['_id'])}
|
544 |
|
545 |
return jsonify({"result": res, "token": access_token}), 200
|
546 |
|
|
|
568 |
data = request.json
|
569 |
return saveMindmap(data, userId, savedMindmap)
|
570 |
|
571 |
+
@app.route('/mindmap/save/id', methods=['POST'])
|
572 |
+
@auth_user
|
573 |
+
def mindmapSaveId():
|
574 |
+
userId = request.userId
|
575 |
+
data = request.json
|
576 |
+
return saveMindmapById(data, userId, savedMindmap)
|
577 |
+
|
578 |
@app.route('/mindmap/get', methods=['GET'])
|
579 |
@auth_user
|
580 |
def mindmapGet():
|
|
|
582 |
return getMindmap(userId, savedMindmap)
|
583 |
|
584 |
@app.route('/mindmap/get/<id>', methods=['GET'])
|
|
|
585 |
def mindmapGetById(id):
|
586 |
+
return getMindmapByid(id, savedMindmap)
|
|
|
587 |
|
588 |
@app.route('/mindmap/delete', methods=['POST'])
|
589 |
@auth_user
|
|
|
600 |
return get_initial_data(), 200
|
601 |
|
602 |
|
603 |
+
|
604 |
+
@app.route('/roadmap', methods=['POST'])
|
605 |
+
def roadmap():
|
606 |
+
if request.method == 'POST':
|
607 |
+
data = request.get_json()
|
608 |
+
# user_id = data.get('user_id')
|
609 |
+
# day_data = data.get('todayData')
|
610 |
+
|
611 |
+
if data.get('type') == 1:
|
612 |
+
# Generate New Roadmap
|
613 |
+
response = model.generate_content('''Generate a roadmap for Web developement in 2 months in following JSON format:
|
614 |
+
[
|
615 |
+
{
|
616 |
+
"week1": {
|
617 |
+
"title": "...",
|
618 |
+
"description": "What will i learn in this week...",
|
619 |
+
"data": {
|
620 |
+
"day1": {
|
621 |
+
"heading": "....",
|
622 |
+
"description": "What will i learn on this day...",
|
623 |
+
"links": [
|
624 |
+
"link1",
|
625 |
+
"link2",
|
626 |
+
....
|
627 |
+
]
|
628 |
+
},
|
629 |
+
"day2": {
|
630 |
+
"description": "...",
|
631 |
+
"heading": "....",
|
632 |
+
"links": [
|
633 |
+
"link1",
|
634 |
+
"link2",
|
635 |
+
....
|
636 |
+
]
|
637 |
+
},
|
638 |
+
...
|
639 |
+
},
|
640 |
+
{
|
641 |
+
"week2": {
|
642 |
+
"title": "...",
|
643 |
+
"description": "What will i learn in this week...",
|
644 |
+
"data": {
|
645 |
+
"day1": {
|
646 |
+
"heading": "....",
|
647 |
+
"description": "What will i learn on this day...",
|
648 |
+
"links": [
|
649 |
+
"link1",
|
650 |
+
"link2",
|
651 |
+
....
|
652 |
+
]
|
653 |
+
},
|
654 |
+
"day2": {
|
655 |
+
"description": "...",
|
656 |
+
"heading": "....",
|
657 |
+
"links": [
|
658 |
+
"link1",
|
659 |
+
"link2",
|
660 |
+
....
|
661 |
+
]
|
662 |
+
},
|
663 |
+
...
|
664 |
+
continue for other weeks...
|
665 |
+
]
|
666 |
+
Generate topics for all 7 days in a week and reference links only links(no header) accordingly.
|
667 |
+
''') # Prompt
|
668 |
+
|
669 |
+
# Youtube Integration & links modification
|
670 |
+
print(response)
|
671 |
+
print(response.text)
|
672 |
+
roads_data = json.loads(response.text)
|
673 |
+
|
674 |
+
print(roads_data)
|
675 |
+
return jsonify({'success': True})
|
676 |
+
|
677 |
+
API_KEY = os.environ('YOUTUBE_API_KEY')
|
678 |
+
url = "https://youtube.googleapis.com/youtube/v3/search"
|
679 |
+
|
680 |
+
for index, ele in enumerate(roads_data):
|
681 |
+
for i in range(0,7):
|
682 |
+
params = {
|
683 |
+
"part": "snippet",
|
684 |
+
"q": ele[f"week{index + 1}"]['data'][f"day{i+1}"]['heading'],
|
685 |
+
"key": API_KEY
|
686 |
+
}
|
687 |
+
|
688 |
+
response = requests.get(url, params=params)
|
689 |
+
|
690 |
+
if response.status_code == 200:
|
691 |
+
print(response.json())
|
692 |
+
video_data = response.json()
|
693 |
+
|
694 |
+
temp1 = []
|
695 |
+
for vid in video_data['items']:
|
696 |
+
if vid['id']['kind']=='youtube#playlist':
|
697 |
+
temp1.append({'viewed': False, 'type': 'playlist', 'playlistId': vid['id']['playlistId'], 'videoTitle': vid['snippet']['title'], 'channelName': vid['snippet']['channelTitle'], 'thumbnail': vid['snippet']['thumbnails']['high']['url']})
|
698 |
+
elif vid['id']['kind']=='youtube#video':
|
699 |
+
temp1.append({'viewed': False, 'type': 'video', 'videoId': vid['id']['videoId'], 'videoTitle': vid['snippet']['title'], 'channelName': vid['snippet']['channelTitle'], 'thumbnail': vid['snippet']['thumbnails']['high']['url']})
|
700 |
+
|
701 |
+
ele[f"week{index + 1}"]['data'][f"day{i+1}"]['youtube'] = temp1
|
702 |
+
|
703 |
+
# Reference Links
|
704 |
+
temp2 = []
|
705 |
+
for link in ele[f"week{index + 1}"]['data'][f"day{i+1}"]['links']:
|
706 |
+
temp2.append({'link': link, 'visited': False})
|
707 |
+
|
708 |
+
ele[f"week{index + 1}"]['data'][f"day{i+1}"]['links'] = temp2
|
709 |
+
|
710 |
+
else:
|
711 |
+
print("Error:", response.json())
|
712 |
+
|
713 |
+
# Save to MongoDB
|
714 |
+
roadmap_collection.insert_one({'data': roads_data, 'activeDays': [day_data], 'user_id': user_id})
|
715 |
+
|
716 |
+
return jsonify({'success': True})
|
717 |
+
|
718 |
+
elif data.get('type') == 2:
|
719 |
+
# Get roadmap data
|
720 |
+
roadmap_data = roadmap_collection.find_one({"_id": ObjectId(data.get("_id")), "userId": user_id})
|
721 |
+
if roadmap_data:
|
722 |
+
return jsonify({'success': True, 'roadmapData': {'data': roadmap_data['data']}, 'activeDays': roadmap_data['activeDays']})
|
723 |
+
else:
|
724 |
+
return jsonify({'success': False})
|
725 |
+
# return jsonify({'success': True, 'roadmapData': roads_data_demo, 'activeDays': active_days})
|
726 |
+
|
727 |
+
|
728 |
+
|
729 |
+
@app.route('/roadmapmodder', methods=['POST'])
|
730 |
+
def roadmapmodder():
|
731 |
+
if request.method == 'POST':
|
732 |
+
data = request.get_json()
|
733 |
+
user_id = data.get('user_id')
|
734 |
+
obj_id = data.get('_id')
|
735 |
+
day_data = data.get('todayData')
|
736 |
+
week_num = data.get('weekNum')
|
737 |
+
day_num = data.get('dayNum')
|
738 |
+
week_field = f'week{week_num}'
|
739 |
+
day_field = f'day{day_num}'
|
740 |
+
|
741 |
+
if data.get('type') == 11: # Add Youtube Video
|
742 |
+
video_url = data.get('videoUrl')
|
743 |
+
|
744 |
+
video_id_match = re.search(r"(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})", video_url)
|
745 |
+
video_id = video_id_match.group(1)
|
746 |
+
api_key = os.getenv('YOUTUBE_API_KEY')
|
747 |
+
|
748 |
+
api_url = f"https://www.googleapis.com/youtube/v3/videos?id={video_id}&key={api_key}&part=snippet"
|
749 |
+
response = requests.get(api_url)
|
750 |
+
temp = {}
|
751 |
+
if response.status_code == 200:
|
752 |
+
data = response.json()
|
753 |
+
|
754 |
+
if 'items' in data and data['items']:
|
755 |
+
item = data['items'][0]
|
756 |
+
print(item)
|
757 |
+
|
758 |
+
if item['kind'] == 'youtube#video':
|
759 |
+
temp = {
|
760 |
+
"channelName": item['snippet']['channelTitle'],
|
761 |
+
"thumbnail": item['snippet']['thumbnails']['high']['url'],
|
762 |
+
"type": 'video',
|
763 |
+
"videoId": item['id'],
|
764 |
+
"videoTitle": item['snippet']['localized']['title'],
|
765 |
+
"viewed": True
|
766 |
+
}
|
767 |
+
elif item['kind'] == 'youtube#playlist':
|
768 |
+
temp = {
|
769 |
+
"channelName": item['snippet']['channelTitle'],
|
770 |
+
"thumbnail": item['snippet']['thumbnails']['high']['url'],
|
771 |
+
"type": 'playlist',
|
772 |
+
"playlistId": item['id'],
|
773 |
+
"videoTitle": item['snippet']['localized']['title'],
|
774 |
+
"viewed": True
|
775 |
+
}
|
776 |
+
|
777 |
+
else:
|
778 |
+
print("Error occurred:", response.status_code)
|
779 |
+
|
780 |
+
temp_data = roadmap_collection.find_one({"_id": ObjectId(obj_id)})
|
781 |
+
temp_data['data'][week_num-1][week_field]['data'][day_field]['youtube'].append(temp)
|
782 |
+
|
783 |
+
roadmap_collection.update_one(
|
784 |
+
{"_id": ObjectId(obj_id)},
|
785 |
+
{"$set": { "data": temp_data['data'] }}
|
786 |
+
)
|
787 |
+
|
788 |
+
if temp_data['activeDays'][len(temp_data['activeDays'])-1]['day'] != day_data['day'] or temp_data['activeDays'][len(temp_data['activeDays'])-1]['month'] != day_data['month'] or temp_data['activeDays'][len(temp_data['activeDays'])-1]['year'] != day_data['year']:
|
789 |
+
updateActiveStreak(obj_id, day_data)
|
790 |
+
|
791 |
+
return jsonify({'success': True, 'youtubeUpdate': temp})
|
792 |
+
|
793 |
+
elif data.get('type') == 12: # Update Youtube Video View
|
794 |
+
video_index = data.get('videoIndex')
|
795 |
+
|
796 |
+
temp_data = roadmap_collection.find_one({"_id": ObjectId(obj_id)})
|
797 |
+
temp_data['data'][week_num-1][week_field]['data'][day_field]['youtube'][video_index]['viewed'] = True
|
798 |
+
|
799 |
+
roadmap_collection.update_one(
|
800 |
+
{"_id": ObjectId(obj_id)},
|
801 |
+
{"$set": { "data": temp_data['data'] }}
|
802 |
+
)
|
803 |
+
|
804 |
+
if temp_data['activeDays'][len(temp_data['active_days'])-1]['day'] != day_data['day'] or temp_data['activeDays'][len(temp_data['active_days'])-1]['month'] != day_data['month'] or temp_data['activeDays'][len(temp_data['active_days'])-1]['year'] != day_data['year']:
|
805 |
+
updateActiveStreak(obj_id, day_data)
|
806 |
+
|
807 |
+
return jsonify({'success': True})
|
808 |
+
|
809 |
+
elif data.get('type') == 21: # Add Reference Link
|
810 |
+
ref_link = data.get('refLink')
|
811 |
+
|
812 |
+
temp_data = roadmap_collection.find_one({"_id": ObjectId(obj_id)})
|
813 |
+
temp_data['data'][week_num-1][week_field]['data'][day_field]['links'].append({"link": ref_link, "visited": True})
|
814 |
+
|
815 |
+
roadmap_collection.update_one(
|
816 |
+
{"_id": ObjectId(obj_id)},
|
817 |
+
{"$set": { "data": temp_data['data'] }}
|
818 |
+
)
|
819 |
+
|
820 |
+
if temp_data['activeDays'][len(temp_data['active_days'])-1]['day'] != day_data['day'] or temp_data['activeDays'][len(temp_data['active_days'])-1]['month'] != day_data['month'] or temp_data['activeDays'][len(temp_data['active_days'])-1]['year'] != day_data['year']:
|
821 |
+
updateActiveStreak(obj_id, day_data)
|
822 |
+
|
823 |
+
elif data.get('type') == 22: # Update Reference link Visit
|
824 |
+
ref_link_index = data.get('refLinkIndex')
|
825 |
+
|
826 |
+
temp_data = roadmap_collection.find_one({"_id": ObjectId(obj_id)})
|
827 |
+
temp_data['data'][week_num-1][week_field]['data'][day_field]['links'][ref_link_index]["visited"] = True
|
828 |
+
|
829 |
+
roadmap_collection.update_one(
|
830 |
+
{"_id": ObjectId(obj_id)},
|
831 |
+
{"$set": { "data": temp_data['data'] }}
|
832 |
+
)
|
833 |
+
|
834 |
+
if temp_data['activeDays'][len(temp_data['active_days'])-1]['day'] != day_data['day'] or temp_data['activeDays'][len(temp_data['active_days'])-1]['month'] != day_data['month'] or temp_data['activeDays'][len(temp_data['active_days'])-1]['year'] != day_data['year']:
|
835 |
+
updateActiveStreak(obj_id, day_data)
|
836 |
+
|
837 |
+
# Add Mindmaps change in mindap generation fucntion such that if roadmapId, WeekNum, DayNum is sent while generation of mindmap then associate it directly with the roadmap.
|
838 |
+
|
839 |
+
elif data.get('type') == 31: # Update isComplete
|
840 |
+
temp_data = roadmap_collection.find_one({"_id": ObjectId(obj_id)})
|
841 |
+
temp_data['data'][week_num-1][week_field]['data'][day_field]['isComplete'] = True
|
842 |
+
|
843 |
+
roadmap_collection.update_one(
|
844 |
+
{"_id": ObjectId(obj_id)},
|
845 |
+
{"$set": { "data": temp_data['data'] }}
|
846 |
+
)
|
847 |
+
|
848 |
+
if temp_data['activeDays'][len(temp_data['active_days'])-1]['day'] != day_data['day'] or temp_data['activeDays'][len(temp_data['active_days'])-1]['month'] != day_data['month'] or temp_data['activeDays'][len(temp_data['active_days'])-1]['year'] != day_data['year']:
|
849 |
+
updateActiveStreak(obj_id, day_data)
|
850 |
+
|
851 |
+
return jsonify({'success': True})
|
852 |
+
|
853 |
+
|
854 |
+
def updateActiveStreak(object_id, day_data): # Update Active Streak
|
855 |
+
temp_data = roadmap_collection.find_one({"_id": ObjectId(object_id)})
|
856 |
+
temp_data['activeDays'].append(day_data)
|
857 |
+
|
858 |
+
roadmap_collection.update_one(
|
859 |
+
{"_id": ObjectId(object_id)},
|
860 |
+
{"$set": { "activeDays": temp_data['activeDays'] }}
|
861 |
+
)
|
862 |
+
|
863 |
+
|
864 |
+
|
865 |
if __name__ == '__main__':
|
866 |
+
app.run(debug=True, host='0.0.0.0')
|