From: Oleg Broytman Date: Wed, 28 Feb 2024 21:18:38 +0000 (+0300) Subject: Feat: Robot based on requests X-Git-Tag: 5.1.0^0 X-Git-Url: https://git.phdru.name/?p=bookmarks_db.git;a=commitdiff_plain;h=08ec9479b05db7a2d40cc58f3a39256dfaf9ff30 Feat: Robot based on requests --- diff --git a/Makefile b/Makefile index 63c8dfd..6dc83ed 100644 --- a/Makefile +++ b/Makefile @@ -2,11 +2,11 @@ # This file is a part of Bookmarks database and Internet robot. # # __author__ = "Oleg Broytman " -# __copyright__ = "Copyright (C) 2000-2023 PhiloSoft Design" +# __copyright__ = "Copyright (C) 2000-2024 PhiloSoft Design" # __license__ = "GNU GPL" # -VERSION=5.0.0 +VERSION=5.1.0 EXAMPLE_SHELL=\ bkmk-add bkmk-add.py bkmk-chk bkmk-publish bkmk-rsync bkmk-sort bkmk2db \ diff --git a/README b/README index f613289..c061e96 100644 --- a/README +++ b/README @@ -2,7 +2,7 @@ Bookmarks database and Internet robot. Author: Oleg Broytman -Copyright (C) 1997-2023 PhiloSoft Design. +Copyright (C) 1997-2024 PhiloSoft Design. License: GPL. For detailed terms see doc/COPYING. diff --git a/Robots/bkmk_rrequests.py b/Robots/bkmk_rrequests.py new file mode 100644 index 0000000..d1bf98b --- /dev/null +++ b/Robots/bkmk_rrequests.py @@ -0,0 +1,37 @@ +"""Robot based on requests + +This file is a part of Bookmarks database and Internet robot. + +""" + +__author__ = "Oleg Broytman " +__copyright__ = "Copyright (C) 2024 PhiloSoft Design" +__license__ = "GNU GPL" + +__all__ = ['robot_requests'] + + +import requests +import requests_ftp + +from Robots.bkmk_robot_base import robot_base + +requests_ftp.monkeypatch_session() + + +class robot_requests(robot_base): + def get(self, bookmark, url, accept_charset=False): + try: + r = requests.Session().get( + url, timeout=self.timeout, allow_redirects=False) + except requests.RequestException as e: + error = str(e) + self.log(' Error: %s' % error) + return error, None, None, None, None + else: + if r.is_redirect: + return None, r.status_code, r.next.url, None, None + return None, None, None, r.headers, r.content + + def get_ftp_welcome(self): + return '' # Alas, requests_ftp doesn't store welcome message diff --git a/bkmk-venv b/bkmk-venv index 751416f..ad9257b 100644 --- a/bkmk-venv +++ b/bkmk-venv @@ -3,8 +3,9 @@ if [ -z "$VIRTUAL_ENV" ]; then test -d .venv && . .venv/bin/activate || { - { python3 -m virtualenv .venv || python3 -m venv .venv; } && - . .venv/bin/activate && - pip install --compile --upgrade beautifulsoup4 lxml m_lib.full + { python3 -m virtualenv .venv || python3 -m venv .venv; } && + . .venv/bin/activate && + pip install --compile --upgrade beautifulsoup4 lxml m_lib.full \ + requests requests-ftp } || exit 1 fi diff --git a/doc/ANNOUNCE b/doc/ANNOUNCE index 5179695..b6775e9 100644 --- a/doc/ANNOUNCE +++ b/doc/ANNOUNCE @@ -6,6 +6,10 @@ WHAT IS IT bookmarks.html. WHAT'S NEW +Version 5.1.0 (2024-03-01) + + Robot based on requests. + Version 5.0.0 (2023-11-22) Python 3. @@ -22,14 +26,15 @@ WHERE TO GET git clone https://git.phdru.name/bookmarks_db.git git clone git://git.phdru.name/bookmarks_db.git - Requires: Python 2.7 or 3.4+, BeautifulSoup 4, lxml, m_lib 2.0+. + Requires: Python 2.7 or 3.4+, BeautifulSoup 4, lxml, m_lib 2.0+, + requests and requests-ftp. AUTHOR Oleg Broytman COPYRIGHT - Copyright (C) 1997-2023 PhiloSoft Design + Copyright (C) 1997-2024 PhiloSoft Design LICENSE GPL diff --git a/doc/ChangeLog b/doc/ChangeLog index 6b8d305..9267bae 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,7 @@ +Version 5.1.0 (2024-03-01) + + Robot based on requests. + Version 5.0.0 (2023-11-22) Python 3. diff --git a/doc/TODO b/doc/TODO index f2573b3..e294cbc 100644 --- a/doc/TODO +++ b/doc/TODO @@ -1,5 +1,3 @@ -Robot based on requests. - Robot based on PycURL. A program to publish bookmarks with icons. diff --git a/robots.py b/robots.py index 1571d58..70513f2 100644 --- a/robots.py +++ b/robots.py @@ -5,7 +5,7 @@ This file is a part of Bookmarks database and Internet robot. """ __author__ = "Oleg Broytman " -__copyright__ = "Copyright (C) 1997-2023 PhiloSoft Design" +__copyright__ = "Copyright (C) 1997-2024 PhiloSoft Design" __license__ = "GNU GPL" __all__ = ['import_robot', 'robot'] @@ -15,7 +15,7 @@ import sys from os import environ from bkmk_objects import parse_params, set_params -robot_name, robot_params = parse_params(environ.get("BKMK_ROBOT", "forking")) +robot_name, robot_params = parse_params(environ.get("BKMK_ROBOT", "requests")) def import_robot(robot_name):