import pandas as pd from API_call_method import callAPI import traceback df = pd.read_csv('mongo_data.csv') df1 = pd.DataFrame( columns=['ObjectId', 'Display_learnpath_name', 'Learnpath_name', 'Do_learnpaths_match', 'Question_code']) i = 0 for ind in df.index: object_id = df['_id'][ind] #print(object_id) url = f"/learning_objects/{object_id}?embed=true&next_status=true" response = callAPI('GET', 'https://knowledge-blue.embibe.com', url, 'a3e65d48-1c51-4191-96fb-1ee2d07d47da:7e02ba0f3c16a3f5231c51a42ffa76b84cf18480f74a02ca4c43ceb85b6ea8ba1f27564951cc70d49033d96334cdde23674939f05175339680ce3baabcb51ffd', '{}') # print(response.json()) try: content = response.json()['content'] try: question_code = response.json()['question_code'] except: question_code = 'question code key not available' for item in content: try: for item in content['question_meta_tags']: try: for item in item['learning_maps_data']: try: display_learnpath_name = item['display_learnpath_name'] except: display_learnpath_name = 'display_learnpath_name key not present'
def main(self, child_id, board, grade, exam, goal, embibe_token): payload = { "board": goal, "child_id": child_id, "exam": exam, "exam_name": exam, "goal": goal, "grade": grade, "fetch_all_content": True } response1 = callAPI('POST', 'https://preprodms.embibe.com', '/fiber_ms/v1/home/practise', embibe_token, json.dumps(payload)) # response1 = self.callAPI( # f"/fiber_ms/v1/home", # json.dumps(payload), # 'POST', embibe_token) # df_positive_results_all_subjects = pd.read_csv("positive_learn_results_all_subjects.csv") # df_negative_results_all_subjects = pd.read_csv("negative_learn_results_all_subjects.csv") df_positive_results = pd.read_csv("positive_learn_results.csv") df_negative_results = pd.read_csv("negative_learn_results.csv") try: for item in response1.json(): home_data = [child_id, exam, goal, grade] if item["content_section_type"] == "SUBJECTS": for data in item["content"]: if data["subject"] == "All Subjects": continue else: try: subject_data_extractor( child_id, board, grade, exam, goal, embibe_token, data["subject"], home_data, df_negative_results, df_positive_results) except Exception as e: print(e) if (item["contentType"] == "chapter"): try: section_name = item["section_name"] except: section_name = None for data in item["content"]: try: title = data["title"] except: title = None try: description = data["description"] except: description = None try: format_refrence = data["learnmap_id"] except: format_refrence = None a_string = format_refrence split_string = a_string.split("/", 1) format_refrence = split_string[0] try: Type = data["type"] except: Type = None try: subject_tagged = data["subject"] except: subject_tagged = None try: learnpath_name = data["learnpath_name"] except: learnpath_name = None LIST = [] LIST = learnpath_name.split('--') chapter = (LIST[len(LIST) - 1]) learnmap_id = data["learnmap_id"] df_positive_results.loc[len( df_positive_results)] = home_data + [ title, Type, format_refrence, section_name, "All Subjects", subject_tagged, learnpath_name, learnmap_id, chapter ] df_positive_results.to_csv( "positive_learn_results.csv", index=False) except: df_positive_results.loc[len(df_positive_results)] = home_data + [ response1.json(), '', '', '', "All Subjects", '', '', '', '' ] df_positive_results.to_csv("positive_learn_results.csv", index=False)
grade = df['Grade'][ind] print(goal, "--", exam) payload = { "board": goal, "child_id": dictionary['user_id'], "exam": exam, "exam_name": exam, "goal": goal, "grade": grade, "fetch_all_content": True } # embibe_token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJjb3VudHJ5IjoxLCJ1c2VyX3R5cGUiOjEsInBhcmVudF91c2VyX2lkIjoxNTAwMDA2MzQ0LCJjcmVhdGVkIjoxNjEyMjcwNTI0LCJvcmdhbml6YXRpb25faWQiOiIxIiwiaWQiOjE1MDAwMDYzNDUsImV4cCI6MTYxMzQ4MDEyNCwiZGV2aWNlSWQiOiIxNjExODU2NDMwMDY4IiwibW9iaWxlX3ZlcmlmaWNhdGlvbl9zdGF0dXMiOmZhbHNlLCJlbWFpbF92ZXJpZmljYXRpb25fc3RhdHVzIjpmYWxzZSwiZW1haWwiOiIxNTAwMDA2MzQ0XzE1Mjg5OTE3OTAwMzcxNDA0QGVtYmliZS11c2VyLmNvbSJ9.zaIn_Q18tJVGpoOxjPYQs1td1HRq_wamuhLOaZ0LxbwS5gSQGqkcKPaWCmZ-Drsm4a_p_-BpVH6_Vt_JSJe-eA' embibe_token = dictionary['embibe-token'] try: response = callAPI('POST', host, '/fiber_ms/v1/home/', embibe_token, json.dumps(payload)) for item in response.json(): if item['contentType'] == 'Video': section_name = item['section_name'] for item in item['content']: try: title = item['title'] except: title = None try: description = item['description'] except: description = None try: duration = item['length'] except:
def subject_data(child_id, board, grade, exam, goal, embibe_token, subject, df, host): payload = { "board": goal, "child_id": child_id, "exam": exam, "exam_name": exam, "goal": goal, "grade": grade, "onlyPractise": False, "fetch_all_content": True } response1 = callAPI('POST', host, f"/fiber_ms/v1/home/{subject}", embibe_token, json.dumps(payload)) # url = f"/fiber_ms/v2/home/learn/{subject}?exam={exam}&goal={goal}&fetch_all_content=true" # response1 = callAPI('GET', host, url, embibe_token, '{}') try: for item in response1.json(): if item["contentType"] == "Book": section = item['section_name'] for item in item['content']: try: teaser_url = item['teaser_url'] except: teaser_url = "KEY NOT AVAILABLE" try: title = item['title'] except: title = 'KEY NOT FOUND' if teaser_url == '' or teaser_url == 'KEY NOT AVAILABLE': teaser_url_working = 'teaser url not present' else: url = teaser_url response33 = callAPI2(url, '{}', 'GET', '') try: if response33.status_code == 200: teaser_url_working = 'Yes' else: teaser_url_working = 'No' except: teaser_url_working = response33.text df.loc[len(df)] = [ f'Learn/home{subject}', goal, exam, title, section, teaser_url, teaser_url_working ] for item in response1.json(): if item["contentType"] == "Video": section = item['section_name'] for item in item['content']: try: preview_url = item['preview_url'] except: preview_url = "KEY NOT AVAILABLE" try: title = item['title'] except: title = 'KEY NOT FOUND' if preview_url == '' or preview_url == 'KEY NOT AVAILABLE': preview_url_working = 'preview url not present' else: url = preview_url response33 = callAPI2(url, '{}', 'GET', '') try: if response33.status_code == 200: preview_url_working = 'Yes' else: preview_url_working = 'No' except: preview_url_working = response33.text df.loc[len(df)] = [ f'Learn/home{subject}', goal, exam, title, section, preview_url, preview_url_working ] except Exception as e: print(e) df.loc[len(df)] = [f'Learn/home/{subject}', goal, exam, '', '', '', ''] df.to_csv('teaser_urls_working_learn.csv', index=False)
def main(self, child_id, board, grade, exam, goal, embibe_token, subject, home_data, df_negative_results, df_positive_results): payload = { "board": goal, "child_id": child_id, "exam": exam, "exam_name": exam, "goal": goal, "grade": grade, "onlyPractise": "true", "fetch_all_content": "true" } response1 = callAPI('POST', 'https://preprodms.embibe.com', f"/fiber_ms/v1/home/{subject}", embibe_token, json.dumps(payload)) # response1 = self.callAPI( # f"/fiber_ms/v1/home/{subject}", # json.dumps(payload), # 'POST', embibe_token) try: for item in response1.json(): if item["contentType"] == "chapter": try: section_name = item["section_name"] except: section_name = None for data in item["content"]: try: title = data["title"] except: title = None try: description = data["description"] except: description = None try: format_refrence = data["learnmap_id"] except: format_refrence = None a_string = format_refrence split_string = a_string.split("/", 1) format_refrence = split_string[0] try: Type = data["type"] except: Type = None try: subject_tagged = data["subject"] except: subject_tagged = None try: learnpath_name = data["learnpath_name"] except: learnpath_name = None LIST = [] LIST = learnpath_name.split('--') chapter = (LIST[len(LIST) - 1]) learnmap_id = data["learnmap_id"] df_positive_results.loc[len( df_positive_results)] = home_data + [ title, Type, format_refrence, section_name, subject, subject_tagged, learnpath_name, learnmap_id, chapter ] df_positive_results.to_csv( "positive_learn_results.csv", index=False) except: df_positive_results.loc[len(df_positive_results)] = home_data + [ response1.json(), '', '', '', subject, '', '', '', '' ] df_positive_results.to_csv("positive_learn_results.csv", index=False)
def home_data(child_id, board, grade, exam, goal, embibe_token, host): df = pd.read_csv('complete_video_details.csv') payload = { "board": goal, "child_id": child_id, "exam": exam, "exam_name": exam, "goal": goal, "grade": grade, "fetch_all_content": True } response1 = callAPI('POST', host, '/fiber_ms/v1/home', embibe_token, json.dumps(payload)) # print(response1.json()) # url = f"/fiber_ms/v2/home/learn/?exam={exam}&goal={goal}&fetch_all_content=true" # response1 = callAPI('GET', host, url, embibe_token, '{}') try: for item in response1.json(): if item["contentType"] == "Video": section = item['section_name'] for item in item['content']: try: title = item['title'] except: title = 'KEY NOT AVAILABLE' try: description = item['description'] except: description = 'KEY NOT AVAILABLE' try: tags = item['learning_map']['tags'] except: tags = 'KEY NOT AVAILABLE' try: subject_tagged = item['subject'] except: subject_tagged = 'KEY NOT AVAILABLE' try: duration = item['length'] except: duration = 'KEY NOT AVAILABLE' try: preview_url = item['preview_url'] except: preview_url = "KEY NOT AVAILABLE" try: thumb = item['thumb'] except: thumb = 'KEY NOT AVAILABLE' try: embium = item['currency'] except: embium = 'KEY NOT AVAILABLE' try: topic_learnpath_name = item['learning_map'][ 'topic_learnpath_name'] except: topic_learnpath_name = 'KEY NOT AVAILABLE' try: id = item['id'] except: id = 'KEY NOT AVAILABLE' try: format_id = item['learning_map']['format_id'] except: format_id = 'KEY NOT AVAILABLE' # CHECKS#_________________ if title == '' or title == 'KEY NOT AVAILABLE': title_present = 'No' else: title_present = 'Yes' if description == '' or description == 'KEY NOT AVAILABLE': description_present = 'No' else: description_present = 'Yes' if tags == [] or tags == 'KEY NOT AVAILABLE': tags_present = 'No' else: tags_present = 'Yes' if subject_tagged == '' or subject_tagged == 'KEY NOT AVAILABLE': subject_tag_present = 'No' else: subject_tag_present = 'Yes' if duration == '' or duration == 'KEY NOT AVAILABLE' or duration == 0: duration_present = 'No' else: duration_present = 'Yes' if thumb == '' or thumb == 'KEY NOT AVAILABLE': thumb_present = 'No' else: thumb_present = 'Yes' if embium == '' or embium == 'KEY NOT AVAILABLE': embium_present = 'No' else: embium_present = 'Yes' if preview_url == '' or preview_url == 'KEY NOT AVAILABLE': preview_url_working = 'No' else: url = preview_url if '.webm' in url or '.webp' in url: response33 = callAPI2(url, '{}', 'GET', '', '') try: if response33.status_code == 200: preview_url_working = 'Yes' else: preview_url_working = 'No' except: preview_url_working = response33.text else: preview_url_working = 'No' if topic_learnpath_name == '' or topic_learnpath_name == 'KEY NOT AVAILABLE': More_on_this_topic_api = 'Topic learnpath not present in api response' Related_videos_api = 'topic learnpath not present in api response' elif id == '' or id == 'KEY NOT AVAILABLE': More_on_this_topic_api = 'id not present in api response' Related_videos_api = 'id not present in api response' else: url11 = "/fiber_ms/v1/topics/related/" + str( topic_learnpath_name ) + "?&content_id=" + str(id) + "&goal=" + str( goal) + "&exam_name=" + str(exam) + "&locale=en" response11 = callAPI2(url11, '{}', 'GET', host, embibe_token) if response11.status_code == 200: Related_videos_api = 'Yes' else: Related_videos_api = 'No' if format_id == '' or format_id == 'KEY NOT AVAILABLE': More_on_this_topic_api = 'format id is not present in api response' else: url22 = "/fiber_ms/topics/more/" + str( topic_learnpath_name) + "?content_id=" + str( id) + "&format_id=" + str( format_id) + "&locale=en" response22 = callAPI2(url22, '{}', 'GET', host, embibe_token) if response22.status_code == 200: More_on_this_topic_api = 'Yes' else: More_on_this_topic_api = 'No' df.loc[len(df)] = [ goal, exam, section, title_present, description_present, tags_present, subject_tag_present, duration_present, preview_url_working, embium_present, thumb_present, More_on_this_topic_api, Related_videos_api ] print(df) df.to_csv('complete_video_details.csv', index=False) except Exception as e: print(e) df.loc[len(df)] = [ goal, exam, response1.status_code, response1.text, '', '', '', '', '', '', '', '', '' ] df.to_csv('complete_video_details.csv', index=False)