ParthCodes commited on
Commit
97e1e6d
·
verified ·
1 Parent(s): 22b6105

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +34 -43
main.py CHANGED
@@ -88,7 +88,7 @@ safety_settings = [
88
  },
89
  ]
90
 
91
- model = genai.GenerativeModel('gemini-1.0-pro', generation_config=generation_config, safety_settings=safety_settings)
92
 
93
  # Caches to reduce no of queries to MongoDB...
94
  user_id_ping = {'current': 0}
@@ -770,36 +770,33 @@ def roadmap():
770
 
771
  roads_data = roadmap_list
772
 
773
- print(roads_data)
774
-
775
- time.sleep(60)
776
-
777
  # Youtube Integration & links modification
778
- API_KEY = os.getenv('YOUTUBE_API_KEY')
779
- url = "https://youtube.googleapis.com/youtube/v3/search"
780
 
781
  for index, ele in enumerate(roads_data):
782
  for i in range(0,7):
783
- params = {
784
- "part": "snippet",
785
- "q": ele[f"week{index + 1}"]['data'][f"day{i+1}"]['heading'] + ele[f"week{index + 1}"]['title'],
786
- "key": API_KEY,
787
- "maxResults" : 3
788
- }
789
 
790
- response = requests.get(url, params=params)
791
 
792
- if response.status_code == 200:
793
- video_data = response.json()
794
 
795
- temp1 = []
796
- for vid in video_data['items']:
797
- if vid['id']['kind']=='youtube#playlist':
798
- temp1.append({'viewed': False, 'type': 'playlist', 'playlistId': vid['id']['playlistId'], 'videoTitle': vid['snippet']['title'], 'channelName': vid['snippet']['channelTitle'], 'thumbnail': vid['snippet']['thumbnails']['high']['url']})
799
- elif vid['id']['kind']=='youtube#video':
800
- temp1.append({'viewed': False, 'type': 'video', 'videoId': vid['id']['videoId'], 'videoTitle': vid['snippet']['title'], 'channelName': vid['snippet']['channelTitle'], 'thumbnail': vid['snippet']['thumbnails']['high']['url']})
801
 
802
- ele[f"week{index + 1}"]['data'][f"day{i+1}"]['youtube'] = temp1
 
803
 
804
  # Reference Links
805
  temp2 = []
@@ -808,8 +805,8 @@ def roadmap():
808
 
809
  ele[f"week{index + 1}"]['data'][f"day{i+1}"]['links'] = temp2
810
 
811
- else:
812
- print("Error:", response.json())
813
 
814
  # Save to MongoDB
815
  roadmap_collection.insert_one({'data': roads_data, 'title': position, 'activeDays': [day_data], 'userId': user_id})
@@ -832,23 +829,24 @@ def roadmap():
832
  # Get roadmap data
833
  roadmap_data = roadmap_collection.find_one({"_id": ObjectId(data.get("_id")), "userId": user_id})
834
 
835
- practice_temp = roadmap_data['practice'] # Modify to remove answer and explanation
836
- for key in practice_temp.values():
837
- for question in key:
838
- if not question.get('solved', False):
839
- question.pop('answer', None)
840
- question.pop('explaination', None)
841
-
842
- if roadmap_data:
843
  return jsonify({'success': True, 'roadmapData': {'data': roadmap_data['data']}, 'activeDays': roadmap_data['activeDays'], 'practice': practice_temp, 'title': roadmap_data['title']})
844
- else:
845
- return jsonify({'success': False})
846
 
847
 
848
  @app.route('/roadmap/history', methods=['GET'])
849
- @auth_user
850
  def roadmapGetHistory():
851
  userId = request.userId
 
852
  try:
853
  results = roadmap_collection.find({"userId": userId}, {"_id": 1, "title": 1, "activeDays": 1}).limit(5)
854
  roadmaps = [{"_id": str(result["_id"]), "title": result["title"], "activeDays": result["activeDays"]} for result in results]
@@ -936,24 +934,17 @@ def roadmapmodder():
936
  temp_data = roadmap_collection.find_one({"_id": ObjectId(obj_id)})
937
  temp_data['data'][week_num-1][week_field]['data'][day_field]['youtube'][video_index]['viewed'] = True
938
 
939
- print("Meow")
940
-
941
  roadmap_collection.update_one(
942
  {"_id": ObjectId(obj_id)},
943
  {"$set": { "data": temp_data['data'] }}
944
  )
945
 
946
- print("Meow")
947
-
948
  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['active_days'])-1]['year'] != day_data['year']:
949
  temp_data['activeDays'].append(day_data)
950
  roadmap_collection.update_one(
951
  {"_id": ObjectId(obj_id)},
952
  {"$set": { "activeDays": temp_data['activeDays'] }}
953
  )
954
-
955
-
956
- print("Meow")
957
 
958
  return jsonify({'success': True})
959
 
 
88
  },
89
  ]
90
 
91
+ model = genai.GenerativeModel('gemini-1.5-flash', generation_config=generation_config, safety_settings=safety_settings)
92
 
93
  # Caches to reduce no of queries to MongoDB...
94
  user_id_ping = {'current': 0}
 
770
 
771
  roads_data = roadmap_list
772
 
 
 
 
 
773
  # Youtube Integration & links modification
774
+ # API_KEY = os.getenv('YOUTUBE_API_KEY')
775
+ # url = "https://youtube.googleapis.com/youtube/v3/search"
776
 
777
  for index, ele in enumerate(roads_data):
778
  for i in range(0,7):
779
+ # params = {
780
+ # "part": "snippet",
781
+ # "q": ele[f"week{index + 1}"]['data'][f"day{i+1}"]['heading'] + ele[f"week{index + 1}"]['title'],
782
+ # "key": API_KEY,
783
+ # "maxResults" : 3
784
+ # }
785
 
786
+ # response = requests.get(url, params=params)
787
 
788
+ # if response.status_code == 200:
789
+ # video_data = response.json()
790
 
791
+ # temp1 = []
792
+ # for vid in video_data['items']:
793
+ # if vid['id']['kind']=='youtube#playlist':
794
+ # temp1.append({'viewed': False, 'type': 'playlist', 'playlistId': vid['id']['playlistId'], 'videoTitle': vid['snippet']['title'], 'channelName': vid['snippet']['channelTitle'], 'thumbnail': vid['snippet']['thumbnails']['high']['url']})
795
+ # elif vid['id']['kind']=='youtube#video':
796
+ # temp1.append({'viewed': False, 'type': 'video', 'videoId': vid['id']['videoId'], 'videoTitle': vid['snippet']['title'], 'channelName': vid['snippet']['channelTitle'], 'thumbnail': vid['snippet']['thumbnails']['high']['url']})
797
 
798
+ # ele[f"week{index + 1}"]['data'][f"day{i+1}"]['youtube'] = temp1
799
+ ele[f"week{index + 1}"]['data'][f"day{i+1}"]['youtube'] = []
800
 
801
  # Reference Links
802
  temp2 = []
 
805
 
806
  ele[f"week{index + 1}"]['data'][f"day{i+1}"]['links'] = temp2
807
 
808
+ # else:
809
+ # print("Error:", response.json())
810
 
811
  # Save to MongoDB
812
  roadmap_collection.insert_one({'data': roads_data, 'title': position, 'activeDays': [day_data], 'userId': user_id})
 
829
  # Get roadmap data
830
  roadmap_data = roadmap_collection.find_one({"_id": ObjectId(data.get("_id")), "userId": user_id})
831
 
832
+ if "practice" in roadmap_data:
833
+ practice_temp = roadmap_data['practice'] # Modify to remove answer and explanation
834
+ for key in practice_temp.values():
835
+ for question in key:
836
+ if not question.get('solved', False):
837
+ question.pop('answer', None)
838
+ question.pop('explaination', None)
839
+
840
  return jsonify({'success': True, 'roadmapData': {'data': roadmap_data['data']}, 'activeDays': roadmap_data['activeDays'], 'practice': practice_temp, 'title': roadmap_data['title']})
841
+
842
+ return jsonify({'success': True, 'roadmapData': {'data': roadmap_data['data']}, 'activeDays': roadmap_data['activeDays'], 'practice': [], 'title': roadmap_data['title']})
843
 
844
 
845
  @app.route('/roadmap/history', methods=['GET'])
846
+ # @auth_user
847
  def roadmapGetHistory():
848
  userId = request.userId
849
+ print(userId)
850
  try:
851
  results = roadmap_collection.find({"userId": userId}, {"_id": 1, "title": 1, "activeDays": 1}).limit(5)
852
  roadmaps = [{"_id": str(result["_id"]), "title": result["title"], "activeDays": result["activeDays"]} for result in results]
 
934
  temp_data = roadmap_collection.find_one({"_id": ObjectId(obj_id)})
935
  temp_data['data'][week_num-1][week_field]['data'][day_field]['youtube'][video_index]['viewed'] = True
936
 
 
 
937
  roadmap_collection.update_one(
938
  {"_id": ObjectId(obj_id)},
939
  {"$set": { "data": temp_data['data'] }}
940
  )
941
 
 
 
942
  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['active_days'])-1]['year'] != day_data['year']:
943
  temp_data['activeDays'].append(day_data)
944
  roadmap_collection.update_one(
945
  {"_id": ObjectId(obj_id)},
946
  {"$set": { "activeDays": temp_data['activeDays'] }}
947
  )
 
 
 
948
 
949
  return jsonify({'success': True})
950