From 62906c267c953d7ac3b8d343d753688d66e94808 Mon Sep 17 00:00:00 2001 From: Krishna Singhal Date: Wed, 17 Aug 2022 23:00:44 +0530 Subject: [PATCH] BitlyAPI 1.0.1 --- .gitignore | 129 ----------------------------------------- BitlyAPI/__init__.py | 17 ++++++ BitlyAPI/exceptions.py | 6 ++ README.md | 61 ++++++++++++++++++- pyproject.toml | 6 ++ setup.py | 30 ++++++++++ 6 files changed, 118 insertions(+), 131 deletions(-) delete mode 100644 .gitignore create mode 100644 BitlyAPI/__init__.py create mode 100644 BitlyAPI/exceptions.py create mode 100644 pyproject.toml create mode 100644 setup.py diff --git a/.gitignore b/.gitignore deleted file mode 100644 index b6e4761..0000000 --- a/.gitignore +++ /dev/null @@ -1,129 +0,0 @@ -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -pip-wheel-metadata/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -.python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ diff --git a/BitlyAPI/__init__.py b/BitlyAPI/__init__.py new file mode 100644 index 0000000..dcc367b --- /dev/null +++ b/BitlyAPI/__init__.py @@ -0,0 +1,17 @@ +import requests +from .exceptions import BitlyApiNotWorking, BitlyException + +__version__ = "1.0.1" +bitli_api = "https://api.ksprojects.me/bitly?url={}" + + +def shorten_url(url: str) -> str: + try: + response = requests.get(bitli_api.format(url)).json() + except Exception: + raise BitlyApiNotWorking + if response['success'] is True: + return response.get('link') + if response.get('message'): + raise BitlyException(response['message']) + raise BitlyApiNotWorking \ No newline at end of file diff --git a/BitlyAPI/exceptions.py b/BitlyAPI/exceptions.py new file mode 100644 index 0000000..bc92240 --- /dev/null +++ b/BitlyAPI/exceptions.py @@ -0,0 +1,6 @@ +class BitlyApiNotWorking(Exception): + pass + + +class BitlyException(Exception): + pass \ No newline at end of file diff --git a/README.md b/README.md index c7b5bfc..31911e3 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,59 @@ -# bitly-api-python -A Python wrapper for the bit.ly API +# BitlyAPI + +- [Installation](#installation) +- [Documentation](#documentation) +- [Examples](#examples) + - [Short Url](#short-url) + - [Version](#version) +- [Copyright](#copyright) + +
+ +# Installation + +```shell +pip install bitly-api-python +``` + +
+ +# Documentation + +You can read our Documention on https://api.ksprojects.me/docs + +
+ +# Examples + +## Short Url + +```python +from BitlyAPI import shorten_url + +url = "https://github.com/Krishna-Singhal" + +shortened_url = shorten_url(url) +print(shortened_url) +``` + +#### Parameters + +Parameter | description +--------- | ----------- +`url` | Long url + +
+ +## Version + +```python +from BitlyAPI import __version__ + +print(__version__) +``` + +# Copyright + +Copyright (C) 2022 by Krishna-Singhal, < https://github.com/Krishna-Singhal >. + +All rights reserved. diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..b5a3c46 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,6 @@ +[build-system] +requires = [ + "setuptools>=42", + "wheel" +] +build-backend = "setuptools.build_meta" \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..04fc78b --- /dev/null +++ b/setup.py @@ -0,0 +1,30 @@ +import re +import setuptools + +with open("BitlyAPI/__init__.py", encoding="utf-8") as f: + version = re.findall(r"__version__ = \"(.+)\"", f.read())[0] + +with open("README.md", "r") as fh: + long_description = fh.read() + +setuptools.setup( + name="bitly-api-python", + version=version, + author="Krishna-Singhal", + author_email="ylikehits3@gmail.com", + description="Wrapper for [Bitly API](https://api.ksprojects.me/bitly)", + long_description=long_description, + long_description_content_type="text/markdown", + url="https://github.com/Krishna-Singhal/bitly-api-python", + project_urls={ + "Bug Tracker": "https://github.com/Krishna-Singhal/bitly-api-python/issues", + }, + classifiers=[ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", + "Operating System :: OS Independent", + ], + install_requires=["requests"], + packages=['BitlyAPI'], + python_requires=">=3.6", +) \ No newline at end of file