From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from localhost.localdomain (unknown [101.128.125.157]) by gnuweeb.org (Postfix) with ESMTPSA id AA67E7E257; Sat, 30 Jul 2022 04:40:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1659156045; bh=ub48VuSs2Rj7o8al1VbWi3w4kfXAL9I9ASlPeU14Ysw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hAO4IbIubGcU/8HZutnZddCcTEPfFZajbC7Kr2pKccvWdtQFvKMK8OlzeEJYJnjsp wAjaGYBoWc/Wj+ZFivra0oUQTL5okeVMpyr4TgDx06y/pXRyokA81jbTj2mz3zP1yA F82ZpA1SJl1EA2p0lDOmeRd1AU2R/zjGKshqAIrvf4FuTl/XfjkKLskaN7hIs5QAVc cR4Ul18n0Fco+ka0hmiy0iDUoEIlWYRdpRNfCtW/DJVDKe/IwXFxFj21INAucX/hhK jB+4VoPHbYDn0dQNptF9njYEWUbIutx0AmnXZ6TCcwgKsl40z3EBK9RLepTmmIKW/B 5CkD7TTolefTA== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , GNU/Weeb Mailing List , Alviro Iskandar Setiawan Subject: [PATCH v4 05/18] Add utility functions for /add_atom Date: Sat, 30 Jul 2022 11:40:03 +0700 Message-Id: <20220730044016.988-6-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220730044016.988-1-kiizuha@gnuweeb.org> References: <20220730044016.988-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Add some utility functions for /add_atom command in the scraper/utils.py and call it in packages/plugins/add_atom.py Signed-off-by: Muhammad Rizki --- daemon/packages/plugins/manage_atom.py | 20 ++++++++++---------- daemon/scraper/utils.py | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/daemon/packages/plugins/manage_atom.py b/daemon/packages/plugins/manage_atom.py index eca3a60..a10318f 100644 --- a/daemon/packages/plugins/manage_atom.py +++ b/daemon/packages/plugins/manage_atom.py @@ -6,17 +6,17 @@ from pyrogram.types import Message from pyrogram import filters from packages import DaemonClient +from scraper import utils @DaemonClient.on_message( - filters.command("add_atom") & - filters.chat(["kiizuah", "nekoha", -1001673279485]) + filters.command("add_atom") & + filters.chat(["kiizuah", "nekoha", -1001673279485]) ) async def add_atom_url(c: DaemonClient, m: Message): - pass - # text = utils.remove_command(m.text) - # if not utils.is_atom_url(text): - # return - - # ### - # ### TODO: Muhammad Rizki: Add atom url into the database - # ### + text = utils.remove_command(m.text) + if not utils.is_atom_url(text): + return + + ### + ### TODO: Muhammad Rizki: Add atom url into the database + ### diff --git a/daemon/scraper/utils.py b/daemon/scraper/utils.py index 30efb7b..f7de5ba 100644 --- a/daemon/scraper/utils.py +++ b/daemon/scraper/utils.py @@ -12,6 +12,7 @@ import uuid import os import re import shutil +import httpx def get_email_msg_id(mail): @@ -231,3 +232,17 @@ def extract_email_msg_id(msg_id): return None return ret.group(1) + +async def is_atom_url(text: str): + try: + async with httpx.AsyncClient() as ses: + res = await ses.get(text) + mime = res.headers.get("Content-Type") + + return mime == "application/atom+xml" + except: return False + +def remove_command(text: str): + txt = text.split(" ") + txt = text.replace(txt[0] + " ","") + return txt -- Muhammad Rizki