initial commit

This commit is contained in:
Eri - 2020-03-12 00:22:40 +01:00
commit 04fc8e9ab4
8 changed files with 170 additions and 0 deletions

0
README.md Normal file
View File

22
gefavic/__init__.py Normal file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env python # 3
# -*- coding: utf-8 -*-
from gefavic.getfavicon import main as getfavicon
__title__ = "gefavic"
__version__ = "0.0.1"
__author__ = "eri!"
__author_email__ = "eri@c3d2.de"
__license__ = "LGPL3"
__copyright__ = "Copyright 2020 me"
__description__ = "favicon requester"
__url__ = "https://gitea.c3d2.de/eri/gefavic"
def run(options):
getfavicon(options)

10
gefavic/__main__.py Normal file
View File

@ -0,0 +1,10 @@
#!/usr/bin/env python # 3
# -*- coding: utf-8 -*-
import gefavic.cli
__name__ == "__main__" and gefavic.cli.main()

48
gefavic/cli.py Normal file
View File

@ -0,0 +1,48 @@
#!/usr/bin/env python # 3
# -*- coding: utf-8 -*-
import sys
from argparse import ArgumentParser
import gefavic
### Arguments
def add_global_arguments(parser):
parser.add_argument(
"--version",
action='version',
version=gefavic.__version__,
help="Show tool version."
)
parser.add_argument(
"url",
metavar="URL",
nargs="?",
help="URL from where the favicon will be requested."
)
return parser
### Main
def global_parser():
parser = add_global_arguments(ArgumentParser(
description="favicon requester",
add_help=True,
))
return parser
def main():
parser = global_parser()
(options, args) = parser.parse_known_args(sys.argv[1:])
#print(options, args)
kwargs = vars(options)
gefavic.run(options)
sys.exit(0)

22
gefavic/getfavicon.py Normal file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from html.parser import HTMLParser
class favfinder(HTMLParser):
attrs = []
def handle_starttag(self, tag, attrs):
if tag == 'link':
for attr in attrs:
if 'rel' in attr and attr[1].find('icon') > 0:
self.attrs = attrs
def gethtml(url):
return "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><link rel=\"stylesheet\" type=\"text/css\" href=\"../static/style.css\"><link rel=\"shortcut icon\" type=\"image/png\" href=\"../static/py.png\"></head><body></body></html>"
def main(options):
ff = favfinder()
response = gethtml(options.url)
ff.feed(response)
print(ff.attrs)

0
requirements.txt Normal file
View File

22
scripts/make_env.sh Executable file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env bash
# parameters
build_dir=build
python_exe=python3
# create
mkdir -p ${build_dir}
virtualenv -p ${python_exe} ${build_dir}
# activate
source ${build_dir}/bin/activate
# setup
pip install -r requirements.txt
pip install -e .
# cleanup
deactivate
echo "run '${build_dir}/bin/activate' to get into env and 'deactivate' to close it."

46
setup.py Normal file
View File

@ -0,0 +1,46 @@
#!/usr/bin/python # 3
# -*- coding: utf-8 -*-
from re import sub, finditer
from setuptools import setup
from setuptools import find_packages
def find_description():
with open("README.md") as file:
return file.read()
def find_requirements():
with open("requirements.txt") as file:
return [line.strip() for line in file.readlines()]
def find_meta_data():
with open("gefavic/__init__.py") as file:
return {
sub(r'^title$', "name", match.group(1)): match.group(2)
for match in finditer(r'__([^\n]+)__\s*=\s*"([^\n]+)"', file.read())
}
setup(
long_description=find_description(),
packages=find_packages(),
install_requires=find_requirements(),
entry_points={"console_scripts": ["gefavic = gefavic.cli:main"]},
classifiers=[
"Environment :: Console",
"Intended Audience :: System Administrators",
"License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)",
"Natural Language :: English",
"Operating System :: POSIX",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
],
**find_meta_data()
)