def location_base_api(code_dict): call_api = callAPI() call_api.url = "http://api.visitkorea.or.kr/openapi/service/rest/KorService/locationBasedList?ServiceKey=0tGMz" \ "%2FY9NJAmuX2b5XBvz2jtdGMVxjmqpEk6dB%2FoX65tTQruqoO6A3Mpk5en%2BbqSaQCIBLWqiXU8vMVDNTdhiA%3D%3D& " call_api.params = { 'numOfRows': 10, 'pageNo': 1, 'arrange': 'B', 'MobileApp': 'romiBot', 'MobileOS': 'ETC', 'contentTypeId': code_dict['type'], 'mapX': code_dict['lng'] if 'lng' in code_dict else '', 'mapY': code_dict['lat'] if 'lat' in code_dict else '', 'radius': 2000, '_type': 'json' } result = call_api.get_send_api() if result: result.update(code_dict) slack_bot.message = parsing_api(result, "location") else: slack_bot.message = [{ 'title': slack_bot.location + ' 어디 ' + slack_bot.type_code + '를 원하시나요?', 'text': slack_bot.location + '의 자세한 장소를 알려주세요.' }] response = slack_bot.send_message() print("\n location base send message : ") print(slack_bot.message) return Response(), response
def type_info(type_str): call_api = callAPI() call_api.url = "http://api.visitkorea.or.kr/openapi/service/rest/KorService/searchKeyword?ServiceKey=0tGMz" \ "%2FY9NJAmuX2b5XBvz2jtdGMVxjmqpEk6dB%2FoX65tTQruqoO6A3Mpk5en%2BbqSaQCIBLWqiXU8vMVDNTdhiA%3D%3D& " call_api.params = { 'numOfRows': 1, 'MobileApp': 'romiBot', 'MobileOS': 'ETC', 'keyword': type_str, 'arrange': 'B', '_type': 'json' } result = call_api.get_send_api() type = {} if result: type_result = result['response']['body']['items']['item'] type['type'] = type_result[ 'contenttypeid'] if 'contenttypeid' in type_result else '' type['cat1'] = type_result['cat1'] if 'cat1' in type_result else '' type['cat2'] = type_result['cat2'] if 'cat2' in type_result else '' type['cat3'] = type_result['cat3'] if 'cat3' in type_result else '' return type
def detail_common(type_id, content_id): call_api = callAPI() call_api.url = "http://api.visitkorea.or.kr/openapi/service/rest/KorService/detailCommon?ServiceKey=0tGMz%2FY9N" \ "JAmuX2b5XBvz2jtdGMVxjmqpEk6dB%2FoX65tTQruqoO6A3Mpk5en%2BbqSaQCIBLWqiXU8vMVDNTdhiA%3D%3D" call_api.params = { 'numOfRows': 10, 'pageNo': 1, 'MobileApp': 'romiBot', 'MobileOS': 'ETC', 'contentId': content_id, 'contentTypeId': type_id, '_type': 'json', 'defaultYN': 'Y', 'firstImageYN': 'Y', 'areacodeYN': 'Y', 'catcodeYN': 'Y', 'addrinfoYN': 'Y', 'mapinfoYN': 'Y', 'overviewYN': 'Y', } result = call_api.get_send_api() if result['response']['body']['totalCount'] > 0: result = result['response']['body']['items']['item'] return result
def area_info(addr): call_api = callAPI() call_api.url = "http://api.visitkorea.or.kr/openapi/service/rest/KorService/areaCode?ServiceKey=0tGMz%2FY9N" \ "JAmuX2b5XBvz2jtdGMVxjmqpEk6dB%2FoX65tTQruqoO6A3Mpk5en%2BbqSaQCIBLWqiXU8vMVDNTdhiA%3D%3D" call_api.params = { 'numOfRows': 40, 'arrange': 'A', 'MobileApp': 'romiBot', 'MobileOS': 'ETC', '_type': 'json' } print("area info : ", addr) addr_result = call_api.get_send_api() code_arr = addr_result['response']['body']['items']['item'] area_code = {} for code in code_arr: if code['name'] in addr['upperAddrName']: area_code['area_code'] = code['code'] if slack_bot.location not in addr['upperAddrName']: call_api.url = 'http://api.visitkorea.or.kr/openapi/service/rest/KorService/areaCode?ServiceKey=0tGMz%2FY9NJAmuX2b5XBvz2jtdGMVxjmqpEk6dB%2FoX65tTQruqoO6A3Mpk5en%2BbqSaQCIBLWqiXU8vMVDNTdhiA%3D%3D' call_api.params = { 'MobileOS': 'ETC', 'MobileApp': 'romiBot', 'numOfRows': 100, '_type': 'json', 'areaCode': area_code['area_code'] } addr2_result = call_api.get_send_api() code2_arr = addr2_result['response']['body']['items']['item'] for code in code2_arr: if code['name'] in addr['middleAddrName']: area_code['sigungu_code'] = code['code'] return area_code
def detail_image(content_id): call_api = callAPI() call_api.url = "http://api.visitkorea.or.kr/openapi/service/rest/KorService/detailImage?ServiceKey=0tGMz%2FY9N" \ "JAmuX2b5XBvz2jtdGMVxjmqpEk6dB%2FoX65tTQruqoO6A3Mpk5en%2BbqSaQCIBLWqiXU8vMVDNTdhiA%3D%3D" call_api.params = { 'numOfRows': 10, 'pageNo': 1, 'MobileApp': 'romiBot', 'MobileOS': 'ETC', 'contentId': content_id, '_type': 'json', 'imageYN': 'Y', 'subImageYN': 'Y', } result = call_api.get_send_api() result = result['response']['body']['items']['item'] print("\n******") print(result) print("\n******") return result
def keyword_addr(): call_api = callAPI() call_api.url = 'http://apis.skplanetx.com/tmap/pois' call_api.params = { 'appKey': '6c8d5711-b0e5-30b1-8aa3-1cdfd328db49', 'version': '1', 'format': 'json', 'searchKeyword': slack_bot.location, 'page': '1', 'count': '5', 'resCoordType': 'WGS84GEO', } result = call_api.get_send_api() error_code = result['error']['id'] if 'error' in result else '' if error_code == '': total_count = int(result['searchPoiInfo']['totalCount']) # 주소 정보가 많을 경우 선택 if total_count > 1: btn_message = [{ "text": "검색하신 장소를 선택해주세요.", "fallback": "", "callback_id": "select addr info", "color": "#3AA3E3", "attachment_type": "default", 'actions': [] }] str_addr = "" for addr in result['searchPoiInfo']['pois']['poi']: if str_addr != addr['upperAddrName'] + " " + addr[ 'middleAddrName'] + " " + addr['lowerAddrName']: # search type - location info save if slack_bot.type == "location": value = addr['frontLon'] + "/" + addr['frontLat'] else: value = addr['upperAddrName'] + "/" + addr[ 'middleAddrName'] coordinate = { "name": addr['id'], "text": addr['upperAddrName'] + " " + addr['middleAddrName'] + " " + addr['lowerAddrName'], "type": "button", "value": value } str_addr = addr['upperAddrName'] + " " + addr[ 'middleAddrName'] + " " + addr['lowerAddrName'] btn_message[0]['actions'].append(coordinate) slack_bot.message = btn_message elif total_count == 1: extra_api(result['searchPoiInfo']['pois']['poi'][0]) else: slack_bot.message = [{ 'title': '찾으시는 장소가 ' + slack_bot.location + '이 맞나요?', 'text': '상세 장소 정보를 찾지 못했어요. 다시 자세하게 알려주시겠어요? ' }] else: slack_bot.message = [{ 'title': slack_bot.location + ' 어디 ' + slack_bot.type_code + '를 원하시나요?', 'text': slack_bot.location + '의 자세한 장소를 알려주세요.' }] response = slack_bot.send_message() print("\n keyword arr send message : ") print(slack_bot.message) return Response(), response