Commit ec0bf12b authored by Łukasz Nowak's avatar Łukasz Nowak

cli: With click allow to fetch any URL

parent 15719a5f
......@@ -42,6 +42,7 @@ setup(
license='GPLv3+ with wide exception for FOSS',
install_requires=[
'requests', # for the great CaseInsensitiveDict
'click', # easy cli
],
zip_safe=True,
python_requires=">=3.5",
......@@ -49,7 +50,7 @@ setup(
package_dir={"": "src"},
entry_points={
'console_scripts': [
'recurl = recurlests.cli:recurl',
'recurl = recurlests.cli:runRecurl',
]
},
)
import click
from pprint import pprint
from . import recurlests
def recurl():
@click.command(short_help="Runs curl's wrapper recurl")
@click.option('--headers/--no-headers', help="Shows response headers", default=False, show_default=True)
@click.option('--output/--no-output', help="Shows the output", default=False, show_default=True)
@click.argument("url")
def runRecurl(headers, output, url):
mimikra = recurlests.Recurlests()
mimikra.get('https://www.nexedi.com/')
response = mimikra.get(url)
print('Effective HTTP version:', response.effective_http_version)
print('Response status code:', response.status_code)
print('Response status:', response.ok and "ok" or "error")
print('Response content type:', response.content_type)
print('Response elapsed:', response.elapsed)
print('Response effective url:', response.url_effective)
if headers:
print('Reponse headers:')
pprint(dict(response.headers))
if output:
print('Output:')
print(response.text)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment