def query_save_to(user_id, password, keywords, public_ip, headers, _file, start=True, oneByone=True, distinct=True, detail=True, append=None, to_html=None): if isinstance(keywords, str): keywords = [keywords] append_lst = open_record_file(append) excludes = append_lst.unique('id') if len(append_lst) > 0 else [] dg = DrugInfoAPI(user_id, password, public_ip, headers) results = [] if oneByone: results = dg.search_one_by_one(keywords, detail=detail, exclude_ids=excludes) else: length, step = len(keywords), 50 todo_range = list(range(0, length, 50)) iter_range = tqdm(todo_range, total=len(todo_range)) for page in iter_range: keyword = ' '.join(keywords[page:page + step]) results += dg.search(keyword, detail=detail) lst = Listorm(results) + append_lst if distinct: lst.distinct('id') if to_html: create_img_html(lst, _file=to_html, start=start) if _file or append: if start and platform.system() == 'Windows': try: lst.to_excel(append or _file) os.startfile(append or _file) return except: for row in lst: print('Exception Occuer') # print(row) return else: lst.to_excel(append or _file) return lst
def drug_picture_view(records, columns=5, env=JINJA_ENV, output_html=None): records = Listorm(records) records = records.distinct('drug_code') template = env.get_template('drug_pictures.html') object_lists = [] for i in range(0, len(records), columns): object_lists.append(records[i:i + columns]) html = template.render(object_lists=object_lists) if output_html: with open(output_html, 'wt', encoding='utf-8') as fp: fp.write(html) else: return html
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')