def dict_to_json_file(self, list_info_dict): crawl_data = [] for page_id in list_info_dict.keys(): restaurant_api_url = f'https://www.yogiyo.co.kr/api/v1/restaurants/{page_id}/?lat={lat}&lng={lng}' restaurant_info_api_url = f'https://www.yogiyo.co.kr/api/v1/restaurants/{page_id}/info/' review_api_url = f'https://www.yogiyo.co.kr/api/v1/reviews/{page_id}/?count=30&only_photo_review=false&page=1&sort=time' menu_api_url = f'https://www.yogiyo.co.kr/api/v1/restaurants/{page_id}/menu/?add_photo_menu=android&add_one_dish_menu=true&order_serving_type=delivery' avgrating_url = f'https://www.yogiyo.co.kr/review/restaurant/{page_id}/avgrating/' restaurant_data = { 'list_info': list_info_dict[page_id], 'restaurant_results': self.get_response_json_data(restaurant_api_url), 'restaurant_info_results': self.get_response_json_data(restaurant_info_api_url), 'review_results': self.get_response_json_data(review_api_url), 'menu_results': self.get_response_json_data(menu_api_url), 'avgrating_results': self.get_response_json_data(avgrating_url), } crawl_data.append(restaurant_data) with open('yogiyo_data_for_parsing.json', 'w', encoding='utf-8') as file: json.dump(crawl_data, file, ensure_ascii=False, indent='\t')
def prepare_method_specs_graph(id): SPEC_GROUP = 10 METHOD_GROUP = 15 print('Preparing Method-Spec Graph...') graph = {"nodes": [], "links": []} method = Method.objects.get(id=id) if method.specs: node = { "id": re.sub( '[^A-Za-z0-9]+', '', (method.method_name + method.class_name + method.method_id)), "cod": method.id, "name": method.method_name, "group": METHOD_GROUP, "executed": method.scenarios.count(), "size": 1 } graph['nodes'].append(node) for spec in method.specs.all(): node = { "id": re.sub('[^A-Za-z0-9]+', '', (spec.description + spec.file + str(spec.line))), "cod": spec.id, "name": spec.description, "group": SPEC_GROUP, "size": len(spec.executed_methods.all()) } if node not in graph['nodes']: graph['nodes'].append(node) link = { "source": re.sub('[^A-Za-z0-9]+', '', (method.method_name + method.class_name + method.method_id)), "target": re.sub('[^A-Za-z0-9]+', '', (spec.description + spec.file + str(spec.line))), "value": 2 } graph['links'].append(link) with open('app/static/method_graph.json', 'w') as outfile: json.dump(graph, outfile)
def prepare_method_graph(id): SCENARIO_GROUP = 10 METHOD_GROUP = 15 print('Preparing Method Graph...') graph = { "nodes": [], "links": [] } method = Method.objects.get(id=id) node = { "id": re.sub('[^A-Za-z0-9]+', '', (method.method_name + method.class_name + method.method_id)), "cod": method.id, "name": method.method_name, "group": METHOD_GROUP, "executed": method.scenarios.count(), "size": 1 } graph['nodes'].append(node) for scenario in method.scenarios.all(): feature = scenario.feature node = { "id": re.sub('[^A-Za-z0-9]+', '', (scenario.scenario_title + feature.path_name + str(scenario.line))), "cod": scenario.id, "name": scenario.scenario_title, "group": SCENARIO_GROUP, "size": len(scenario.executed_methods.all()) } if node not in graph['nodes']: graph['nodes'].append(node) link = { "source": re.sub('[^A-Za-z0-9]+', '', (method.method_name + method.class_name + method.method_id)), "target": re.sub('[^A-Za-z0-9]+', '', (scenario.scenario_title + feature.path_name + str(scenario.line))), "value": 2 } graph['links'].append(link) node = { "id": re.sub('[^A-Za-z0-9]+', '', feature.path_name), 'cod': feature.id, "name": feature.feature_name, "group": 5, "size": get_size(feature.simple_scenarios.all()) } if node not in graph['nodes']: graph['nodes'].append(node) link = { "source": re.sub('[^A-Za-z0-9]+', '', (scenario.scenario_title + feature.path_name + str(scenario.line))), "target": re.sub('[^A-Za-z0-9]+', '', feature.path_name), "value": 2 } graph['links'].append(link) with open('app/static/method_graph.json', 'w') as outfile: json.dump(graph, outfile)
def save(self, force_insert=False, force_update=False, using=None, update_fields=None, *args, **kwargs): super(Person, self).save(*args, **kwargs) str_fn = "file_data_{}.json".format(self.id) Person.objects.filter(pk=self.id).update(file_info=str_fn) dict_to_write = {'name': self.name, 'surn': self.surn} with open("person/user_data_files/{}".format(str_fn), 'w') as fw: fw.write('{\n') for key in dict_to_write: fw.write('\t') json.dump('{}'.format(key), fw) fw.write(': ') json.dump('{}'.format(dict_to_write.get(key)), fw) fw.write(',\n') fw.write('\t') json.dump('pasw', fw) fw.write(': ') json.dump('{}'.format(self.pasw1), fw) fw.write('\n}') fw.close()
def prepare_spec_graph(id): SPEC_GROUP = 20 METHOD_GROUP = 15 graph = { "nodes": [], "links": [] } specs = Spec.objects.filter(project=id) for spec in specs: node = { "id": re.sub('[^A-Za-z0-9]+', '', (spec.description + spec.file + str(spec.line))), 'cod': spec.id, "name": spec.description, "group": SPEC_GROUP, "size": len(spec.executed_methods.all()) } if node not in graph['nodes']: graph['nodes'].append(node) for method in spec.executed_methods.all(): node = { "id": re.sub('[^A-Za-z0-9]+', '', (method.method_id + method.class_path)), "cod": method.id, "name": method.method_name, "group": METHOD_GROUP, "executed": method.scenarios.count(), "size": 1 } if node not in graph['nodes']: graph['nodes'].append(node) # Create links between spec and method link = { "source": re.sub('[^A-Za-z0-9]+', '', (spec.description + spec.file + str(spec.line))), "target": re.sub('[^A-Za-z0-9]+', '', (method.method_id + method.class_path)), "value": 2 } graph['links'].append(link) print('Number of nodes: ', len(graph['nodes'])) print('Number of links: ', len(graph['links'])) with open('app/static/spec_graph.json', 'w') as outfile: json.dump(graph, outfile)
def prepare_graph(id): FEATURE_GROUP = 5 SCENARIO_GROUP = 10 METHOD_GROUP = 15 graph = {"nodes": [], "links": []} project = Project.objects.get(pk=id) features = Feature.objects.filter(project=project) for feature in features: scenarios = SimpleScenario.objects.filter(feature=feature) node = { "id": re.sub('[^A-Za-z0-9]+', '', feature.path_name), "cod": feature.id, "identifier": feature.path_name, "name": feature.feature_name, "group": FEATURE_GROUP, "size": get_size(scenarios) / 5 } if node not in graph['nodes']: graph['nodes'].append(node) for scenario in scenarios: if not scenario.scenario_title: scenario.scenario_title = "Background" methods = scenario.executed_methods.all() node = { "id": re.sub('[^A-Za-z0-9]+', '', (scenario.scenario_title + feature.path_name + str(scenario.line))), "cod": scenario.id, "identifier": scenario.scenario_title + "[" + scenario.feature.feature_name + "]", "name": scenario.scenario_title, "group": SCENARIO_GROUP, "size": len(methods) / 5 } if node not in graph['nodes']: graph['nodes'].append(node) # Create links between feature and scenarios link = { "source": re.sub('[^A-Za-z0-9]+', '', feature.path_name), "target": re.sub('[^A-Za-z0-9]+', '', (scenario.scenario_title + feature.path_name + str(scenario.line))), "value": 3 } graph['links'].append(link) for method in methods: node = { "id": re.sub('[^A-Za-z0-9]+', '', (method.method_name + method.class_name + method.method_id)), "cod": method.id, "identifier": method.method_name + "[" + method.class_path + "]", "name": method.method_name, "group": METHOD_GROUP, "size": 1 } if node not in graph['nodes']: graph['nodes'].append(node) link = { "source": re.sub('[^A-Za-z0-9]+', '', (scenario.scenario_title + feature.path_name + str(scenario.line))), "target": re.sub('[^A-Za-z0-9]+', '', (method.method_name + method.class_name + method.method_id)), "value": 3 } graph['links'].append(link) with open('app/static/data2.json', 'w') as outfile: json.dump(graph, outfile)
def prepare_feature_graph(id): SCENARIO_GROUP = 10 METHOD_GROUP = 15 graph = {"nodes": [], "links": []} feature = Feature.objects.filter(id=id)[0] scenarios = SimpleScenario.objects.filter(feature=feature) print('Scenarios: ', len(scenarios)) print('feature ', feature.path_name) node = { "id": re.sub('[^A-Za-z0-9]+', '', feature.path_name), 'cod': feature.id, "name": feature.feature_name, "group": 5, "size": get_size(scenarios) } graph['nodes'].append(node) print('Feature Defined') for scenario in scenarios: methods = scenario.executed_methods.all() print('Scenario ', scenario.scenario_title, ': ', len(methods), ' executed methods.') node = { "id": re.sub('[^A-Za-z0-9]+', '', (scenario.scenario_title + feature.path_name + str(scenario.line))), "cod": scenario.id, "name": scenario.scenario_title, "group": SCENARIO_GROUP, "size": len(methods) } if node not in graph['nodes']: graph['nodes'].append(node) # Create links between feature and scenarios link = { "source": re.sub('[^A-Za-z0-9]+', '', feature.path_name), "target": re.sub('[^A-Za-z0-9]+', '', (scenario.scenario_title + feature.path_name + str(scenario.line))), "value": 2 } graph['links'].append(link) for method in methods: node = { "id": re.sub('[^A-Za-z0-9]+', '', (method.method_name + method.class_name + method.method_id)), "cod": method.id, "name": method.method_name, "group": METHOD_GROUP, "executed": method.scenarios.count(), "size": 1 } if node not in graph['nodes']: graph['nodes'].append(node) link = { "source": re.sub('[^A-Za-z0-9]+', '', (scenario.scenario_title + feature.path_name + str(scenario.line))), "target": re.sub('[^A-Za-z0-9]+', '', (method.method_name + method.class_name + method.method_id)), "value": 3 } graph['links'].append(link) print('Number of nodes: ', len(graph['nodes'])) print('Number of links: ', len(graph['links'])) with open('app/static/feature_graph.json', 'w') as outfile: json.dump(graph, outfile)