Skip to content

Commit

Permalink
Get initial CLI working; update README; update version
Browse files Browse the repository at this point in the history
  • Loading branch information
zachbateman committed Dec 7, 2020
1 parent 2dcd5d6 commit 70b4bc5
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 39 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
# PyLookup

PyLookup is a fuzzy-matching, auto-updating library and command-line tool inspired by the "VLOOKUP" function in Excel.
PyLookup is a fuzzy-matching, auto-table-updating library and command-line tool inspired by the "VLOOKUP" function in Excel.


# Installation

```
pip install pylookup
```

# Command Line Interface Usage

- To add and populate the "COLUMN" column in "excel_to_populate" from the data in "excel_with_column",
simple run the following command. This currently works for .xlsx (Excel) files and .csv files.

```
pylookup COLUMN excel_to_populate.xlsx excel_with_column.xlsx
```



License
Expand Down
4 changes: 3 additions & 1 deletion pylookup/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from .pylookup import pylookup
from .pylookup import pylookup, file_lookup
from . import __main__
# from .__main__ import file_lookup
35 changes: 1 addition & 34 deletions pylookup/__main__.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,7 @@
'''
Command Line Interface for PyLookup.
'''
from pylookup import pylookup
import pandas
import click


@click.command()
@click.argument('column_to_fill')
@click.argument('main_file')
@click.argument('reference_file')
def file_lookup(column_to_fill, main_file, reference_file):

if '.xl' in main_file:
main_df = pandas.read_excel(main_file)
elif '.csv' in main_file:
main_df = pandas.read_csv(main_file)
else:
print('Error! Main file must be .csv or .xlsx!')

if '.xl' in reference_file:
ref_df = pandas.read_excel(reference_file)
elif '.csv' in reference_file:
ref_df = pandas.read_csv(reference_file)
else:
print('Error! Reference file must be .csv or .xlsx!')


pylookup(column_to_fill, main_df, ref_df)

if '.xl' in main_file:
main_df.to_excel(main_file, index=False)
elif '.csv' in main_file:
main_df.to_csv(main_file, index=False)
print(f'Saved updated {main_file}.')

from .pylookup import file_lookup


if __name__ == '__main__':
Expand Down
31 changes: 31 additions & 0 deletions pylookup/pylookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from statistics import mean
from collections import defaultdict
import random
import click



Expand Down Expand Up @@ -122,3 +123,33 @@ def matchable_columns(main_table, reference_table) -> dict:
if not main_col_matches:
print('No reference columns were found suitable for matching!')
return main_col_matches


@click.command()
@click.argument('column_to_fill')
@click.argument('main_file')
@click.argument('reference_file')
def file_lookup(column_to_fill, main_file, reference_file):

if '.xl' in main_file:
main_df = pandas.read_excel(main_file)
elif '.csv' in main_file:
main_df = pandas.read_csv(main_file)
else:
print('Error! Main file must be .csv or .xlsx!')

if '.xl' in reference_file:
ref_df = pandas.read_excel(reference_file)
elif '.csv' in reference_file:
ref_df = pandas.read_csv(reference_file)
else:
print('Error! Reference file must be .csv or .xlsx!')


pylookup(column_to_fill, main_df, ref_df)

if '.xl' in main_file:
main_df.to_excel(main_file, index=False)
elif '.csv' in main_file:
main_df.to_csv(main_file, index=False)
print(f'Saved updated {main_file}.')
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[options.entry_points]
console_scripts =
pylookup = pylookup:file_lookup
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@

setuptools.setup(
name='PyLookup',
version='0.1.0',
version='0.1.1',
packages=['pylookup'],
license='MIT',
author='Zach Bateman',
description='PyLookup - Fuzzy-matching table autofill tool',
long_description=long_description,
long_description_content_type='text/markdown',
url='https://github.com/zachbateman/pylookup.git',
download_url='https://github.com/zachbateman/pylookup/archive/v_0.1.0.tar.gz',
download_url='https://github.com/zachbateman/pylookup/archive/v_0.1.1.tar.gz',
keywords=['LOOKUP', 'VLOOKUP', 'TABLE', 'MATCHING'],
install_requires=['rapidfuzz', 'pandas'],
install_requires=['rapidfuzz', 'pandas', 'click'],
classifiers=['Development Status :: 3 - Alpha',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3',
Expand Down

0 comments on commit 70b4bc5

Please sign in to comment.