def run(self, place_id): place = Place.objects.get(id=place_id) if not place.uplaces.first(): return False uplace = place.uplaces.first() post = place.placePost place.placeName = place.placeName or post.name place.lonLat = place.lonLat or post.lonLat if not place.placeName or not place.lonLat: return False place.save() name = place.placeName.content lon = place.lonLat.x lat = place.lonLat.y # 일단 LegacyPlace 에 의한 장소화가 되지 않은 경우만 구글 호출 # TODO : 구글 장소화는 무조건 시도하고... 구글에 없는 경우 구글 DB 에 추가 if not place.lps.first(): if place.placeName and place.lonLat: google_place_id = LegacyPlace.find_google_place_id_by_lonLatName( name, lon, lat) if google_place_id: lp, is_created = LegacyPlace.get_or_create_smart( '%s.google' % google_place_id) if not lp.place: lp.place = place lp.save() pb = PostBase() pb.lps.append(lp) PostPiece.create_smart_4place(place, uplace.vd, pb.pb_MAMMA) return True return False
def test_place_property(self): place = Place() place.save() self.assertEqual(LegacyPlace.objects.count(), 0) lp, is_created = LegacyPlace.get_or_create_smart('14720610.kakao') self.assertEqual(LegacyPlace.objects.count(), 1) self.assertEqual(lp.place, None) self.assertEqual(lp.lp_type, LP_TYPE['kakao']) lp2, is_created = LegacyPlace.get_or_create_smart('14720610.kakao') self.assertEqual(LegacyPlace.objects.count(), 1) self.assertEqual(lp2.place, None) self.assertEqual(lp2.lp_type, LP_TYPE['kakao']) self.assertEqual(lp2, lp) lp3, is_created = LegacyPlace.get_or_create_smart('15738374.kakao') self.assertEqual(LegacyPlace.objects.count(), 2) self.assertEqual(lp3.place, None) self.assertEqual(lp3.lp_type, LP_TYPE['kakao']) self.assertNotEqual(lp3, lp) lp.place = place lp.save() self.assertEqual(place.lps.first(), lp) lp3.place = place with self.assertRaises(IntegrityError): lp3.save()
def test_save_and_retreive_4square(self): if WORK_ENVIRONMENT: return test_data = '4ccffc63f6378cfaace1b1d6.4square' lp, is_created = LegacyPlace.get_or_create_smart(test_data) self.assertEqual(lp.uuid.split('.')[1], '4square') saved = LegacyPlace.objects.first() self.assertEqual(saved, lp) self.assertEqual(saved.id, lp.id) saved2 = LegacyPlace.get_from_json('{"uuid": "%s", "content": null}' % lp.uuid) self.assertEqual(saved2.content, lp.content) saved3 = LegacyPlace.get_from_json('{"uuid": null, "content": "%s"}' % lp.content) self.assertEqual(saved3, lp)
def test_access_methods(self): test_data = '4ccffc63f6378cfaace1b1d6.4square' lp, is_created = LegacyPlace.get_or_create_smart(test_data) lp.access() self.assertValidLocalFile(lp.path_accessed) self.assertValidInternetUrl(lp.url_accessed)
def paste(request, uplace_id): vd = vd_login_for_browser(request) uplace = UserPlace.objects.get(vd_id__in=vd.realOwner_vd_ids, id=uplace_id) if request.method == 'POST': pb = PostBase() pb.uuid = uplace.uuid if 'note' in request.POST and request.POST['note']: note, is_created = PlaceNote.get_or_create_smart( request.POST['note']) pb.notes.append(note) if request.FILES: for file in request.FILES.itervalues(): rf = RawFile.objects.create(vd=vd, file=file) rf.start() img, is_created = Image.get_or_create_smart(rf.url) pb.images.append(img) if 'lp' in request.POST and request.POST['lp']: lp, is_created = LegacyPlace.get_or_create_smart( request.POST['lp']) pb.lps.append(lp) pb_MAMMA = pb.pb_MAMMA if pb_MAMMA: place, is_created = Place.get_or_create_smart(pb_MAMMA, vd) uplace.placed(place) if pb.ujson: pp = PostPiece.create_smart(uplace, pb) if uplace.is_empty: uplace.is_empty = False uplace.save() uplace._clearCache() return render(request, 'ui/paste.html', context=dict(uplace=uplace))
def test_summarize_methods(self): test_data = '14720610.kakao' lp, is_created = LegacyPlace.get_or_create_smart(test_data) lp.summarize() self.assertValidLocalFile(lp.path_summarized) self.assertValidInternetUrl(lp.url_summarized)
def test_get_from_url(self): # naver disabled ''' url, is_created = Url.get_or_create_smart('http://map.naver.com/local/siteview.nhn?code=21149144') self.assertEqual(LegacyPlace.get_from_url(url).content, '21149144.naver') url, is_created = Url.get_or_create_smart('http://map.naver.com/?app=Y&version=10&appMenu=location&pinId=31130096&pinType=site&lat=37.3916387&lng=127.0584149&title=능이향기&dlevel=11') self.assertEqual(LegacyPlace.get_from_url(url).content, '31130096.naver') url, is_created = Url.get_or_create_smart('http://m.store.naver.com/restaurants/detail?id=37333252') self.assertEqual(LegacyPlace.get_from_url(url).content, '37333252.naver') url, is_created = Url.get_or_create_smart('http://m.map.naver.com/siteview.nhn?code=31176899') self.assertEqual(LegacyPlace.get_from_url(url).content, '31176899.naver') url, is_created = Url.get_or_create_smart('https://m.map.naver.com/viewer/map.nhn?pinType=site&pinId=21652462') self.assertEqual(LegacyPlace.get_from_url(url).content, '21652462.naver') url, is_created = Url.get_or_create_smart('https://m.map.naver.com/siteview.nhn?code=11523188&ret_url=https%3A%2F%2Fm.search.naver.com%2Fsearch.naver%3Fwhere%3Dm%26query%3D%25EC%259C%2584%25EB%258B%25B4%25ED%2595%259C%25EB%25B0%25A9%25EB%25B3%2591%25EC%259B%2590%26sm%3Dmsv_nex%23m_local') self.assertEqual(LegacyPlace.get_from_url(url).content, '11523188.naver') ''' url, is_created = Url.get_or_create_smart('http://place.kakao.com/places/14720610') self.assertEqual(LegacyPlace.get_from_url(url).content, '14720610.kakao') url, is_created = Url.get_or_create_smart('http://m.map.daum.net/actions/detailInfoView?id=15493954') self.assertEqual(LegacyPlace.get_from_url(url).content, '15493954.kakao') url, is_created = Url.get_or_create_smart('http://m.map.daum.net/actions/detailInfoView?id=15493954') self.assertEqual(LegacyPlace.get_from_url(url).content, '15493954.kakao') url, is_created = Url.get_or_create_smart('http://place.map.daum.net/26799590') self.assertEqual(LegacyPlace.get_from_url(url).content, '26799590.kakao') url, is_created = Url.get_or_create_smart('http://foursquare.com/v/4ccffc63f6378cfaace1b1d6') self.assertEqual(LegacyPlace.get_from_url(url).content, '4ccffc63f6378cfaace1b1d6.4square') url, is_created = Url.get_or_create_smart('https://ko.foursquare.com/v/방아깐/4ccffc63f6378cfaace1b1d6') self.assertEqual(LegacyPlace.get_from_url(url).content, '4ccffc63f6378cfaace1b1d6.4square') url, is_created = Url.get_or_create_smart('http://ko.foursquare.com/v/4ccffc63f6378cfaace1b1d6') self.assertEqual(LegacyPlace.get_from_url(url).content, '4ccffc63f6378cfaace1b1d6.4square') url, is_created = Url.get_or_create_smart('https://www.mangoplate.com/restaurants/f-YvkBx8IemC') self.assertEqual(LegacyPlace.get_from_url(url).content, 'f-YvkBx8IemC.mango') if not WORK_ENVIRONMENT: url, is_created = Url.get_or_create_smart('https://www.google.com/maps/place/Han+Ha+Rum+Korean+Restaurant/@22.3636765,113.4067433,9z/data=!4m8!1m2!2m1!1z7Iud64u5!3m4!1s0x34040056de2d51b3:0xae100fb893526bdf!8m2!3d22.2801408!4d114.182783') self.assertEqual(LegacyPlace.get_from_url(url).content, 'ChIJs1Et3lYABDQR32tSk7gPEK4.google')
def _skip_test_access_by_naver(self): test_data = '21149144.naver' lp, is_created = LegacyPlace.get_or_create_smart(test_data) path = Path(lp.path_accessed) if path.exists(): path.unlink() self.assertEqual(path.exists(), False) lp.access() self.assertEqual(path.exists(), True)
def test_access_by_kakao(self): test_data = '14720610.kakao' lp, is_created = LegacyPlace.get_or_create_smart(test_data) path = Path(lp.path_accessed) if path.exists(): path.unlink() self.assertEqual(path.exists(), False) lp.access() self.assertEqual(path.exists(), True)
def test_access_by_mango(self): test_data = 'f-YvkBx8IemC.mango' lp, is_created = LegacyPlace.get_or_create_smart(test_data) path = Path(lp.path_accessed) if path.exists(): path.unlink() self.assertEqual(path.exists(), False) lp.access() self.assertEqual(path.exists(), True)
def test_access_by_4square(self): if WORK_ENVIRONMENT: return test_data = '4ccffc63f6378cfaace1b1d6.4square' lp, is_created = LegacyPlace.get_or_create_smart(test_data) path = Path(lp.path_accessed) if path.exists(): path.unlink() self.assertEqual(path.exists(), False) lp.access_force() self.assertEqual(path.exists(), True)
def test_get_or_create_smart(self): vd = VD.objects.create() test_data = 'http://place.kakao.com/places/15738374' lp, is_created = LegacyPlace.get_or_create_smart(test_data) pb = PostBase() pb.lps.append(lp) place, is_created = Place.get_or_create_smart(pb.pb_MAMMA, vd) placePost = place.placePost self.assertDictEqual(pb.pb_MAMMA.json, placePost.json) self.assertEqual(unicode(place), '방아깐')
def test_access_by_google(self): if WORK_ENVIRONMENT: return test_data = 'ChIJs1Et3lYABDQR32tSk7gPEK4.google' lp, is_created = LegacyPlace.get_or_create_smart(test_data) path = Path(lp.path_accessed) if path.exists(): path.unlink() self.assertEqual(path.exists(), False) lp.access() self.assertEqual(path.exists(), True)
def test_content_property_google_case3(self): if WORK_ENVIRONMENT: return test_data = 'https://www.google.com/maps/place/Han+Ha+Rum+Korean+Restaurant/@22.3636765,113.4067433,9z/data=!4m8!1m2!2m1!1z7Iud64u5!3m4!1s0x34040056de2d51b3:0xae100fb893526bdf!8m2!3d22.2801408!4d114.182783' lp, is_created = LegacyPlace.get_or_create_smart(test_data) self.assertEqual(lp.uuid.split('.')[1], 'google') saved = LegacyPlace.objects.first() self.assertEqual(lp.content, 'ChIJs1Et3lYABDQR32tSk7gPEK4.google') self.assertEqual(saved, lp) self.assertEqual(saved.id, lp.id) self.assertEqual(saved.content, lp.content) self.assertEqual(saved.id, UUID('ba698d72-72bb-1a1e-97bb-3c44f54b973f'))
def test_content_property_google_case2(self): if WORK_ENVIRONMENT: return test_data = 'ChIJrTLr-GyuEmsRBfy61i59si0.google' lp, is_created = LegacyPlace.get_or_create_smart(test_data) self.assertEqual(lp.uuid.split('.')[1], 'google') saved = LegacyPlace.objects.first() self.assertEqual(lp.content, test_data) self.assertEqual(saved, lp) self.assertEqual(saved.id, lp.id) self.assertEqual(saved.content, lp.content) self.assertEqual(saved.id, UUID('fdc64a309ca7409a8a143be959307efe'))
def test_content_property_kakao_case1(self): test_data = '14720610.kakao' lp, is_created = LegacyPlace.get_or_create_smart(test_data) self.assertEqual(lp.uuid.split('.')[1], 'kakao') saved = LegacyPlace.objects.first() self.assertEqual(lp.content, test_data) self.assertEqual(lp.lp_type, 4) self.assertEqual(saved, lp) self.assertEqual(saved.id, lp.id) self.assertEqual(saved.content, lp.content) self.assertEqual(saved.id, UUID('00000004-0000-0000-0000-000014720610')) self.assertEqual(saved.lp_type, 4)
def test_content_property_kakao_case3(self): test_data = 'http://place.kakao.com/places/14720610' normalized_test_data = '14720610.kakao' lp, is_created = LegacyPlace.get_or_create_smart(test_data) self.assertEqual(lp.uuid.split('.')[1], 'kakao') saved = LegacyPlace.objects.first() self.assertNotEqual(lp.content, test_data) self.assertEqual(lp.content, normalized_test_data) self.assertEqual(saved, lp) self.assertEqual(saved.id, lp.id) self.assertEqual(saved.content, lp.content) self.assertEqual(saved.id, UUID('00000004-0000-0000-0000-000014720610'))
def _skip_test_content_property_naver_case3(self): test_data = 'http://map.naver.com/?app=Y&version=10&appMenu=location&pinId=36229742&pinType=site&lat=37.4893023&lng=127.1350392&title=%EB%B0%94%EC%9D%B4%ED%82%A4%20%EB%AC%B8%EC%A0%95%EC%A0%90&dlevel=11' normalized_test_data = '36229742.naver' lp, is_created = LegacyPlace.get_or_create_smart(test_data) self.assertEqual(lp.uuid.split('.')[1], 'naver') saved = LegacyPlace.objects.first() self.assertNotEqual(lp.content, test_data) self.assertEqual(lp.content, normalized_test_data) self.assertEqual(saved, lp) self.assertEqual(saved.id, lp.id) self.assertEqual(saved.content, lp.content) self.assertEqual(saved.id, UUID('00000002-0000-0000-0000-000036229742'))
def test_content_property_mango_case1(self): test_data = 'https://www.mangoplate.com/restaurants/f-YvkBx8IemC' normalized_test_data = 'f-YvkBx8IemC.mango' lp, is_created = LegacyPlace.get_or_create_smart(test_data) self.assertEqual(lp.uuid.split('.')[1], 'mango') saved = LegacyPlace.objects.first() self.assertNotEqual(lp.content, test_data) self.assertEqual(lp.content, normalized_test_data) self.assertEqual(saved, lp) self.assertEqual(saved.id, lp.id) self.assertEqual(saved.content, lp.content) self.assertEqual(saved.id, UUID('00000005-662d-5976-6b42-783849656d43'))
def _skip_test_content_property_naver_case2(self): test_data = 'http://map.naver.com/local/siteview.nhn?code=21149144' normalized_test_data = '21149144.naver' lp, is_created = LegacyPlace.get_or_create_smart(test_data) self.assertEqual(lp.uuid.split('.')[1], 'naver') saved = LegacyPlace.objects.first() self.assertNotEqual(lp.content, test_data) self.assertEqual(lp.content, normalized_test_data) self.assertEqual(saved, lp) self.assertEqual(saved.id, lp.id) self.assertEqual(saved.content, lp.content) self.assertEqual(saved.id, UUID('00000002-0000-0000-0000-000021149144'))
def test_content_property_kakao_case4(self): test_data = 'http://m.map.daum.net/actions/detailInfoView?id=15493954' normalized_test_data = '15493954.kakao' lp, is_created = LegacyPlace.get_or_create_smart(test_data) self.assertEqual(lp.uuid.split('.')[1], 'kakao') saved = LegacyPlace.objects.first() self.assertNotEqual(lp.content, test_data) self.assertEqual(lp.content, normalized_test_data) self.assertEqual(saved, lp) self.assertEqual(saved.id, lp.id) self.assertEqual(saved.content, lp.content) self.assertEqual(saved.id, UUID('00000004-0000-0000-0000-000015493954'))
def _skip_test_content_property_naver_case1(self): test_data = '21149144.naver' lp, is_created = LegacyPlace.get_or_create_smart(test_data) self.assertEqual(lp.uuid.split('.')[1], 'naver') saved = LegacyPlace.objects.first() self.assertEqual(lp.content, test_data) self.assertEqual(lp.lp_type, 2) self.assertEqual(saved, lp) self.assertEqual(saved.id, lp.id) self.assertEqual(saved.content, lp.content) self.assertEqual(saved.id, UUID('00000002-0000-0000-0000-000021149144')) self.assertEqual(saved.lp_type, 2)
def _skip_test_content_summarized_by_naver(self): test_data = '21149144.naver' lp, is_created = LegacyPlace.get_or_create_smart(test_data) lp.summarize() pb = lp.content_summarized self.assertEqual(pb.is_valid(), True) self.assertEqual(pb.name.content, '방아깐') self.assertIn(pb.images[0].content, [ unquote_plus('https://ssl.map.naver.com/staticmap/image?version=1.1&crs=EPSG%3A4326&caller=og_map¢er=127.092557%2C37.390271&level=11&scale=2&w=500&h=500&markers=type%2Cdefault2%2C127.092557%2C37.390271&baselayer=default'), 'http://ldb.phinf.naver.net/20150901_174/1441078320814Nj4Fe_JPEG/146466556151173_0.jpeg', ]) self.assertValidLocalFile(pb.images[0].path_summarized) self.assertValidInternetUrl(pb.images[0].url_summarized)
def test_content_property_4square_case2(self): if WORK_ENVIRONMENT: return test_data = 'http://foursquare.com/v/4ccffc63f6378cfaace1b1d6' normalized_test_data = '4ccffc63f6378cfaace1b1d6.4square' lp, is_created = LegacyPlace.get_or_create_smart(test_data) self.assertEqual(lp.uuid.split('.')[1], '4square') saved = LegacyPlace.objects.first() self.assertNotEqual(lp.content, test_data) self.assertEqual(lp.content, normalized_test_data) self.assertEqual(saved, lp) self.assertEqual(saved.id, lp.id) self.assertEqual(saved.content, lp.content) self.assertEqual(saved.id, UUID('00000001-4ccf-fc63-f637-8cfaace1b1d6'))
def test_content_summarized_by_google(self): if WORK_ENVIRONMENT: return test_data = 'ChIJs1Et3lYABDQR32tSk7gPEK4.google' lp, is_created = LegacyPlace.get_or_create_smart(test_data) lp.summarize() pb = lp.content_summarized self.printJson(pb) self.assertEqual(pb.is_valid(), True) self.assertEqual(pb.name.content, 'Han Ha Rum Korean Restaurant') self.assertEqual(pb.phone.content, '+85228666927') self.assertEqual(pb.addr.content, 'Causeway Bay Plaza 1, 489 Hennessy Rd, Causeway Bay, Hong Kong') self.assertValidLocalFile(pb.images[0].path_summarized) self.assertValidInternetUrl(pb.images[0].url_summarized)
def test_content_summarized_by_mango(self): test_data = 'f-YvkBx8IemC.mango' lp, is_created = LegacyPlace.get_or_create_smart(test_data) lp.summarize() pb = lp.content_summarized self.printJson(pb) self.assertEqual(pb.is_valid(), True) self.assertEqual(pb.name.content, '제로투나인') self.assertEqual(pb.images[0].content, unquote_plus( 'https://mp-seoul-image-production-s3.mangoplate.com/259736/xverhn9edfxp5w.jpg' )) self.assertValidLocalFile(pb.images[0].path_summarized) self.assertValidInternetUrl(pb.images[0].url_summarized)
def test_content_summarized_by_kakao(self): test_data = '14720610.kakao' lp, is_created = LegacyPlace.get_or_create_smart(test_data) lp.summarize() pb = lp.content_summarized self.printJson(pb) self.assertEqual(pb.is_valid(), True) self.assertEqual(pb.name.content, '홍콩') self.assertEqual(pb.images[0].content, unquote_plus( 'http://img1.daumcdn.net/thumb/C300x300/?fname=http%3A%2F%2Fdn-rp-place.kakao.co.kr%2Fplace%2FoWaiTZmpy7%2FviOeK5KRQK7mEsAHlckFgK%2FapreqCwxgnM_l.jpg' )) self.assertValidLocalFile(pb.images[0].path_summarized) self.assertValidInternetUrl(pb.images[0].url_summarized)
def url_placed(request): url = None places = None vd_id = request.session[VD_SESSION_KEY] vd = VD.objects.get(id=vd_id) if not vd: raise ValueError('Admin Login Required') if request.method == 'POST': raw_url = request.POST['url'] url, is_created = Url.get_or_create_smart(raw_url) if not url: raise ValueError('Invalid URL') raw_places = request.POST['places'] for raw_place in raw_places.split('\n'): raw_place = raw_place.strip() is_remove = False if raw_place.startswith('-'): is_remove = True raw_place = raw_place[1:] if not raw_place: continue lp_content = LegacyPlace.normalize_content(raw_place) if lp_content: lp, is_created = LegacyPlace.get_or_create_smart(lp_content) pb = PostBase() pb.lps.append(lp) place, is_created = Place.get_or_create_smart(pb.pb_MAMMA, vd) if is_remove: url.remove_place(place) else: url.add_place(place) else: raise NotImplementedError places = [place for place in url.places.all()] return render(request, 'admin2/url_placed.html', dict(url=url, places=places))
def test_content_property_google_case1(self): if WORK_ENVIRONMENT: return test_data = 'ChIJN1t_tDeuEmsRUsoyG83frY4.google' lp, is_created = LegacyPlace.get_or_create_smart(test_data) self.assertEqual(lp.uuid.split('.')[1], 'google') saved = LegacyPlace.objects.first() self.assertEqual(lp.content, test_data) self.assertEqual(lp.lp_type, 3) self.assertEqual(saved, lp) self.assertEqual(saved.id, lp.id) self.assertEqual(saved.content, lp.content) self.assertEqual(saved.id, UUID('DB8EC763BF050034C79174B5DA189FC8')) self.assertEqual(saved.lp_type, 3)
def test_content_summarized_by_4square2(self): if WORK_ENVIRONMENT: return test_data = '40a55d80f964a52020f31ee3.4square' lp, is_created = LegacyPlace.get_or_create_smart(test_data) lp.summarize() pb = lp.content_summarized self.printJson(pb) self.assertEqual(pb.is_valid(), True) self.assertEqual(pb.name.content, 'Clinton St. Baking Co. & Restaurant') self.assertEqual(pb.images[0].content, unquote_plus( 'https://irs2.4sqi.net/img/general/612x612/690170_HnduV5yM9RLNUHQseOOvDi3OCm4AoYmMld79iVTxrPg.jpg' )) self.assertValidLocalFile(pb.images[0].path_summarized) self.assertValidInternetUrl(pb.images[0].url_summarized)