def forbidden(err): return resp_err(str(err), 1, 403)
def internal_server_error(err): return resp_err("Internal server error", 4, 500)
def method_not_allowed(err): return resp_err("No Access Allowed", 3, 405)
def page_not_found(err): return resp_err("Not Found", 2, 404)
def wrapper(*args, **kwargs): if not check_connection(): return resp_err("No internet connection", 0, 444) return f(*args, **kwargs)
def app_info(): # Initial var password = "******" num_auth = 0 iteration = 0 sleep = 0 auth = dict() # Validation request post_data = request.get_json() if not post_data: return resp_err("Input not valid", 1) # Validation empty word_req = post_data.get("word") if not word_req: return resp_err("Input not valid", 2) # word_req.strip() word_req = re.sub('[^A-Za-z0-9-]+', '', word_req) # Start auto login s = requests.session() resp_login = s.get('https://kbbi.kemdikbud.go.id/Account/Login') sou = BeautifulSoup(resp_login.content, "html.parser") csrf = sou.find('input', {"name": "__RequestVerificationToken"}) token = csrf.attrs['value'] while True: iteration += 1 email = auth_email()[num_auth] if len(auth_email()) - 1 == num_auth: print('=' * 50) print('All account limit') print('=' * 50) sys.stdout.flush() return resp_err("All account limit", 3, 500) auth.update({"Posel": email}) auth.update({"KataSandi": password}) auth.update({"__RequestVerificationToken": token}) try: # End auto login s.post('https://kbbi.kemdikbud.go.id/Account/Login', data=auth) url_req = "https://kbbi.kemdikbud.go.id/entri/%s" % (word_req) resp = s.get(url_req, timeout=50) time.sleep(sleep) soup = BeautifulSoup(resp.content, "html.parser") except Exception as e: print("err: %s | %s | %s" % (e, iteration, word_req)) sys.stdout.flush() return resp_err("Website KBBI not response", 4, 500) limit_request = soup.find(text=" Batas Sehari") if limit_request: print('Limit account - %s' % email) sys.stdout.flush() num_auth += 1 continue error_request = soup.find(text="Terjadi Kesalahan") if error_request: print("Error request word: %s | %s" % (word_req, iteration)) sys.stdout.flush() num_auth += 1 continue data_text = soup.find(text=" Entri tidak ditemukan.") render_finish = soup.findAll("span", {"class": "glyphicon-info-sign"}) if data_text and render_finish: result = { "sts_word": False, "word": word_req } print("Berhasil - %s" % get_now()) sys.stdout.flush() return resp_success(result, "Word is not found") if not data_text and render_finish: break sleep += 0.25 all_resp = soup.find_all('ul', class_="adjusted-par") all_meaning_word = [] for item in all_resp: meaning = item.find("li").getText() all_meaning_word.append(meaning) result = { "sts_word": True, "word": word_req, "meaning": all_meaning_word } print("Berhasil - %s" % get_now()) sys.stdout.flush() return resp_success(result, "Word found in the KBBI")