def get_search_list(self, keyword): kwd = keyword keyword = quote(keyword, encoding='cp949') r = self.get(self.search_url + keyword) soup = BeautifulSoup(r.content, 'html.parser') table_titles = [] product_tables = [] for subheader in soup('div', {'class': 'subheader'}): inuse = subheader.text.strip() if "유통" in inuse: if '유통중인' in inuse: inuse = "유통중" else: inuse = "미확인" table_titles.append(inuse) for table in soup('table'): for tr in table('tr'): if table('table'): continue header = tr.text.strip().split('\n') if header == [ '제품명', '임부', '보험코드', '판매사', '성분/함량', '구분', '보험', '약가', '조회수', '대체', '수정' ]: product_tables.append(table) if len(table_titles) != len(product_tables): print('유통 정보와 테이블이 맞지 않습니다') return Listorm() lst_result = Listorm() kwd = kwd[:15] + '...' if len(kwd) > 15 else kwd for inuse, table in zip(table_titles, product_tables): pw = ParseWebPage(str(table)) lst = Listorm(pw.ext_tables('제품명', '임부', '보험코드', only_data=False)) lst = lst.add_columns(유통정보=lambda row: inuse, 검색어=lambda row: kwd) lst_result += lst return lst_result
def get_context_data(self, **kwargs): context = super(StockInPLVano, self).get_context_data(**kwargs) queryset = self.get_queryset().order_by('drug') if queryset.exists(): ediset = Listorm(queryset.values( 'drug__edi').distinct()).column_values('drug__edi') Info = queryset.first().drug.__class__ drugset = {edi: Info.objects.get(edi=edi) for edi in ediset} else: ediset = [] drugset = {} aggset = queryset.values('buyitem__drug').annotate( total_amount=Sum('amount')) aggset = Listorm(aggset) aggset = aggset.add_columns( total_price=lambda row: drugset.get(row.buyitem__drug ).price * row.total_amount, drug=lambda row: drugset.get(row.buyitem__drug)) context['object_list'] = aggset context['total_price'] = aggset.apply_column('total_price', sum) return context
def get_drug_search_list(**kwargs): search_result_page = retrieve_search_drug.get_search(**kwargs) drug_countset = parse_search_drug.get_count(search_result_page) ret = Listorm() for pro, cnt in drug_countset.items(): if pro == 'proy': attr_id = 'result_recorded' pro_yn = 'Y' else: attr_id = 'result_unrecorded' pro_yn = 'N' records = Listorm( parse_search_drug.parse(search_result_page, 'article', id=attr_id)) retrieve_count = len(records) if cnt > retrieve_count: search_more_result_page = retrieve_search_drug.get_search_more( cnt, proYN=pro_yn, **kwargs) records = Listorm() for page in range(1, cnt // DRUG_SEARCH_MORE_FORM['rowLength'] + 2): search_more_result_page = retrieve_search_drug.get_search_more( cnt, proYN=pro_yn, pageNo=page, **kwargs) page_records = Listorm( parse_search_drug.parse(search_more_result_page, 'article', id='resultMoreTable')) records += page_records records = records.add_columns(pro_yn=lambda row: pro_yn) ret += records return ret.distinct('drug_cd')