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.94]) by gnuweeb.org (Postfix) with ESMTPSA id 47A14806C7; Fri, 29 Jul 2022 00:41:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1659055294; bh=ub48VuSs2Rj7o8al1VbWi3w4kfXAL9I9ASlPeU14Ysw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xf6N5VNJe5r0+95ls7Z1ZCDpCCT8FRx+qyIRzTIAL0JpADkvwFDoip+zoySijjpwZ KIw4BGcTf+cftRS6S20dU4oJaRDD5gSmTzFSvyuStKHo4k+2V9vGi35IQfTmw/VNxS +BzskE/OZSrCwICbMcubEaLFZUijyZHj1azgUqj5QCJMMHy4DUc81JQQp5iqo20e1t /CKC6BlI5btjQZwXOT4xdO4/6vtF+szFerxrXhQzA3fvDDPYeYRRTkg/A+Yoy8G93i 3VvmgsltCxfnULUWL7W6tf6J7TAW6GXf6Bv3++AP6+xTInHCt6rFavIzVeO36YMzHe u96zjioJpKjFg== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , GNU/Weeb Mailing List Subject: [PATCH v1 05/18] Add utility functions for /add_atom Date: Fri, 29 Jul 2022 07:40:14 +0700 Message-Id: <20220729004046.1890-6-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220729004046.1890-1-kiizuha@gnuweeb.org> References: <20220729004046.1890-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