From 1d62e480de9a6810a0fa5b63ad98917c2e81ec21 Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Mon, 13 Jun 2022 09:26:47 +0300 Subject: [PATCH] Initial commit --- .gitignore | 143 ++++++++++++++++++ README.md | 17 +++ find_duplicate_contacts/__init__.py | 0 .../find_duplicate_contacts.py | 90 +++++++++++ find_duplicate_contacts/types.json | 1 + pyproject.toml | 3 + requirements.txt | 3 + setup.py | 12 ++ 8 files changed, 269 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 find_duplicate_contacts/__init__.py create mode 100755 find_duplicate_contacts/find_duplicate_contacts.py create mode 100644 find_duplicate_contacts/types.json create mode 100644 pyproject.toml create mode 100644 requirements.txt create mode 100644 setup.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae138df --- /dev/null +++ b/.gitignore @@ -0,0 +1,143 @@ + 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/ +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/ +cover/ + +# 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 +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .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/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# Configuration files +*.conf +*.cfg +*.ini \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..0b5eea8 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# find_duplicate_contacts + +## Requirements + +## Installation + +### Linux + + `sudo python3 setup.py install` + +### Windows (from PowerShell) + + `& $(where.exe python).split()[0] setup.py install` + +## Usage + + `find_duplicate_contacts.py [--debug-level|-d CRITICAL|ERROR|WARNING|INFO|DEBUG|NOTSET] # Other parameters` diff --git a/find_duplicate_contacts/__init__.py b/find_duplicate_contacts/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/find_duplicate_contacts/find_duplicate_contacts.py b/find_duplicate_contacts/find_duplicate_contacts.py new file mode 100755 index 0000000..9ccee2f --- /dev/null +++ b/find_duplicate_contacts/find_duplicate_contacts.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python3 +# -*- encoding: utf-8 -*- +# +# This script is licensed under GNU GPL version 2.0 or above +# (c) 2022 Antonio J. Delgado +# __description__ + +import sys +import os +import logging +import click +import click_config_file +from logging.handlers import SysLogHandler +import vobject + +class find_duplicate_contacts: + + def __init__(self, debug_level, log_file, directory): + ''' Initial function called when object is created ''' + self.config = dict() + self.config['debug_level'] = debug_level + if log_file is None: + log_file = os.path.join(os.environ.get('HOME', os.environ.get('USERPROFILE', os.getcwd())), 'log', 'find_duplicate_contacts.log') + self.config['log_file'] = log_file + self._init_log() + + self.directory = directory + self.entries = list() + for entry in os.scandir(directory): + self.entries.append(entry) + + self.process_entries() + + def process_entries(self): + for entry in self.entries: + with open(entry.path, 'r') as filep: + content=filep.read() + card = vobject.readOne(content) + print(entry.path) + print(card.contents.keys()) + sys.exit(0) + + + + def _init_log(self): + ''' Initialize log object ''' + self._log = logging.getLogger("find_duplicate_contacts") + self._log.setLevel(logging.DEBUG) + + sysloghandler = SysLogHandler() + sysloghandler.setLevel(logging.DEBUG) + self._log.addHandler(sysloghandler) + + streamhandler = logging.StreamHandler(sys.stdout) + streamhandler.setLevel(logging.getLevelName(self.config.get("debug_level", 'INFO'))) + self._log.addHandler(streamhandler) + + if 'log_file' in self.config: + log_file = self.config['log_file'] + else: + home_folder = os.environ.get('HOME', os.environ.get('USERPROFILE', '')) + log_folder = os.path.join(home_folder, "log") + log_file = os.path.join(log_folder, "find_duplicate_contacts.log") + + if not os.path.exists(os.path.dirname(log_file)): + os.mkdir(os.path.dirname(log_file)) + + filehandler = logging.handlers.RotatingFileHandler(log_file, maxBytes=102400000) + # create formatter + formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s') + filehandler.setFormatter(formatter) + filehandler.setLevel(logging.DEBUG) + self._log.addHandler(filehandler) + return True + +@click.command() +@click.option("--debug-level", "-d", default="INFO", + type=click.Choice( + ["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "NOTSET"], + case_sensitive=False, + ), help='Set the debug level for the standard output.') +@click.option('--log-file', '-l', help="File to store all debug messages.") +@click.option("--directory", "-d", help="Directory containing vCard files to check.") +@click_config_file.configuration_option() +def __main__(debug_level, log_file, directory): + return find_duplicate_contacts(debug_level, log_file, directory) + +if __name__ == "__main__": + __main__() + diff --git a/find_duplicate_contacts/types.json b/find_duplicate_contacts/types.json new file mode 100644 index 0000000..56c1371 --- /dev/null +++ b/find_duplicate_contacts/types.json @@ -0,0 +1 @@ +{"IMAGE": {"type": "image", "id": "Nan"}, "PDF": {"type": "application", "id": "octet-stream"}} \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..9787c3b --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools", "wheel"] +build-backend = "setuptools.build_meta" diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..3d62a26 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +click +click_config_file +vobject \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..341237f --- /dev/null +++ b/setup.py @@ -0,0 +1,12 @@ +import setuptools +setuptools.setup( + scripts=['find_duplicate_contacts/find_duplicate_contacts.py'], + author="Antonio J. Delgado", + version='0.0.1', + name='__project_codenane__', + author_email="", + url="", + description="__description__", + license="GPLv3", + #keywords=["my", "script", "does", "things"] +)