Allow POST requests

master
pictuga 2021-09-08 20:43:21 +02:00
parent 71d9c7a027
commit 06e0ada95b
4 changed files with 15 additions and 9 deletions

View File

@ -263,11 +263,11 @@ arguments to morss is explained in Run above.
The list of arguments can be obtained by running `morss --help` The list of arguments can be obtained by running `morss --help`
``` ```
usage: morss [-h] [--format {rss,json,html,csv}] [--search STRING] [--clip] usage: morss [-h] [--post STRING] [--format {rss,json,html,csv}]
[--indent] [--cache] [--force] [--proxy] [--newest] [--firstlink] [--search STRING] [--clip] [--indent] [--cache] [--force]
[--resolve] [--items XPATH] [--item_link XPATH] [--proxy] [--newest] [--firstlink] [--resolve] [--items XPATH]
[--item_title XPATH] [--item_content XPATH] [--item_time XPATH] [--item_link XPATH] [--item_title XPATH] [--item_content XPATH]
[--nolink] [--noref] [--silent] [--item_time XPATH] [--nolink] [--noref] [--silent]
url url
Get full-text RSS feeds Get full-text RSS feeds
@ -277,6 +277,7 @@ positional arguments:
optional arguments: optional arguments:
-h, --help show this help message and exit -h, --help show this help message and exit
--post STRING POST request
output: output:
--format {rss,json,html,csv} --format {rss,json,html,csv}

View File

@ -32,6 +32,8 @@ def cli_app():
parser.add_argument('url', help='feed url') parser.add_argument('url', help='feed url')
parser.add_argument('--post', action='store', type=str, metavar='STRING', help='POST request')
group = parser.add_argument_group('output') group = parser.add_argument_group('output')
group.add_argument('--format', default='rss', choices=('rss', 'json', 'html', 'csv'), help='output format') group.add_argument('--format', default='rss', choices=('rss', 'json', 'html', 'csv'), help='output format')
group.add_argument('--search', action='store', type=str, metavar='STRING', help='does a basic case-sensitive search in the feed') group.add_argument('--search', action='store', type=str, metavar='STRING', help='does a basic case-sensitive search in the feed')

View File

@ -81,14 +81,17 @@ def get(*args, **kwargs):
return adv_get(*args, **kwargs)['data'] return adv_get(*args, **kwargs)['data']
def adv_get(url, timeout=None, *args, **kwargs): def adv_get(url, post=None, timeout=None, *args, **kwargs):
url = sanitize_url(url) url = sanitize_url(url)
if post is not None:
post = post.encode('utf-8')
if timeout is None: if timeout is None:
con = custom_opener(*args, **kwargs).open(url) con = custom_opener(*args, **kwargs).open(url, data=post)
else: else:
con = custom_opener(*args, **kwargs).open(url, timeout=timeout) con = custom_opener(*args, **kwargs).open(url, data=post, timeout=timeout)
data = con.read() data = con.read()

View File

@ -276,7 +276,7 @@ def FeedFetch(url, options):
delay = 0 delay = 0
try: try:
req = crawler.adv_get(url=url, follow=('rss' if not options.items else None), delay=delay, timeout=TIMEOUT * 2) req = crawler.adv_get(url=url, post=options.post, follow=('rss' if not options.items else None), delay=delay, timeout=TIMEOUT * 2)
except (IOError, HTTPException): except (IOError, HTTPException):
raise MorssException('Error downloading feed') raise MorssException('Error downloading feed')