diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000..03bf045 --- /dev/null +++ b/Pipfile @@ -0,0 +1,15 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] +utah = {editable = true,path = "."} +meetup-api = "*" +pytest = "*" + +[dev-packages] +pytest = "*" + +[requires] +python_version = "3.7" diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 0000000..bc3f078 --- /dev/null +++ b/Pipfile.lock @@ -0,0 +1,171 @@ +{ + "_meta": { + "hash": { + "sha256": "963f9dc471bba3d662fd62bef2c730154f6e27d506acb0da074e574a4315558a" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.6" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": { + "atomicwrites": { + "hashes": [ + "sha256:03472c30eb2c5d1ba9227e4c2ca66ab8287fbfbbda3888aa93dc2e28fc6811b4", + "sha256:75a9445bac02d8d058d5e1fe689654ba5a6556a1dfd8ce6ec55a0ed79866cfa6" + ], + "version": "==1.3.0" + }, + "attrs": { + "hashes": [ + "sha256:69c0dbf2ed392de1cb5ec704444b08a5ef81680a61cb899dc08127123af36a79", + "sha256:f0b870f674851ecbfbbbd364d6b5cbdff9dcedbc7f3f5e18a6891057f21fe399" + ], + "version": "==19.1.0" + }, + "certifi": { + "hashes": [ + "sha256:47f9c83ef4c0c621eaef743f133f09fa8a74a9b75f037e8624f83bd1b6626cb7", + "sha256:993f830721089fef441cdfeb4b2c8c9df86f0c63239f06bd025a76a7daddb033" + ], + "version": "==2018.11.29" + }, + "chardet": { + "hashes": [ + "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae", + "sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691" + ], + "version": "==3.0.4" + }, + "idna": { + "hashes": [ + "sha256:c357b3f628cf53ae2c4c05627ecc484553142ca23264e593d327bcde5e9c3407", + "sha256:ea8b7f6188e6fa117537c3df7da9fc686d485087abf6ac197f9c46432f7e4a3c" + ], + "version": "==2.8" + }, + "meetup-api": { + "hashes": [ + "sha256:83721e37f066c3faf9494592f9ba7ed4b931e9a1a46768ba2e4b55fb249a69ad", + "sha256:8c6e0a2e6b46e3379a8318857084dd93e95bdc156a04b71b41ef7b63f4e91887" + ], + "index": "pypi", + "version": "==0.1.1" + }, + "more-itertools": { + "hashes": [ + "sha256:0125e8f60e9e031347105eb1682cef932f5e97d7b9a1a28d9bf00c22a5daef40", + "sha256:590044e3942351a1bdb1de960b739ff4ce277960f2425ad4509446dbace8d9d1" + ], + "markers": "python_version > '2.7'", + "version": "==6.0.0" + }, + "pluggy": { + "hashes": [ + "sha256:19ecf9ce9db2fce065a7a0586e07cfb4ac8614fe96edf628a264b1c70116cf8f", + "sha256:84d306a647cc805219916e62aab89caa97a33a1dd8c342e87a37f91073cd4746" + ], + "version": "==0.9.0" + }, + "py": { + "hashes": [ + "sha256:64f65755aee5b381cea27766a3a147c3f15b9b6b9ac88676de66ba2ae36793fa", + "sha256:dc639b046a6e2cff5bbe40194ad65936d6ba360b52b3c3fe1d08a82dd50b5e53" + ], + "version": "==1.8.0" + }, + "pytest": { + "hashes": [ + "sha256:067a1d4bf827ffdd56ad21bd46674703fce77c5957f6c1eef731f6146bfcef1c", + "sha256:9687049d53695ad45cf5fdc7bbd51f0c49f1ea3ecfc4b7f3fde7501b541f17f4" + ], + "index": "pypi", + "version": "==4.3.0" + }, + "requests": { + "hashes": [ + "sha256:502a824f31acdacb3a35b6690b5fbf0bc41d63a24a45c4004352b0242707598e", + "sha256:7bf2a778576d825600030a110f3c0e3e8edc51dfaafe1c146e39a2027784957b" + ], + "version": "==2.21.0" + }, + "six": { + "hashes": [ + "sha256:3350809f0555b11f552448330d0b52d5f24c91a322ea4a15ef22629740f3761c", + "sha256:d16a0141ec1a18405cd4ce8b4613101da75da0e9a7aec5bdd4fa804d0e0eba73" + ], + "version": "==1.12.0" + }, + "urllib3": { + "hashes": [ + "sha256:61bf29cada3fc2fbefad4fdf059ea4bd1b4a86d2b6d15e1c7c0b582b9752fe39", + "sha256:de9529817c93f27c8ccbfead6985011db27bd0ddfcdb2d86f3f663385c6a9c22" + ], + "version": "==1.24.1" + }, + "utah": { + "editable": true, + "path": "." + } + }, + "develop": { + "atomicwrites": { + "hashes": [ + "sha256:03472c30eb2c5d1ba9227e4c2ca66ab8287fbfbbda3888aa93dc2e28fc6811b4", + "sha256:75a9445bac02d8d058d5e1fe689654ba5a6556a1dfd8ce6ec55a0ed79866cfa6" + ], + "version": "==1.3.0" + }, + "attrs": { + "hashes": [ + "sha256:69c0dbf2ed392de1cb5ec704444b08a5ef81680a61cb899dc08127123af36a79", + "sha256:f0b870f674851ecbfbbbd364d6b5cbdff9dcedbc7f3f5e18a6891057f21fe399" + ], + "version": "==19.1.0" + }, + "more-itertools": { + "hashes": [ + "sha256:0125e8f60e9e031347105eb1682cef932f5e97d7b9a1a28d9bf00c22a5daef40", + "sha256:590044e3942351a1bdb1de960b739ff4ce277960f2425ad4509446dbace8d9d1" + ], + "markers": "python_version > '2.7'", + "version": "==6.0.0" + }, + "pluggy": { + "hashes": [ + "sha256:19ecf9ce9db2fce065a7a0586e07cfb4ac8614fe96edf628a264b1c70116cf8f", + "sha256:84d306a647cc805219916e62aab89caa97a33a1dd8c342e87a37f91073cd4746" + ], + "version": "==0.9.0" + }, + "py": { + "hashes": [ + "sha256:64f65755aee5b381cea27766a3a147c3f15b9b6b9ac88676de66ba2ae36793fa", + "sha256:dc639b046a6e2cff5bbe40194ad65936d6ba360b52b3c3fe1d08a82dd50b5e53" + ], + "version": "==1.8.0" + }, + "pytest": { + "hashes": [ + "sha256:067a1d4bf827ffdd56ad21bd46674703fce77c5957f6c1eef731f6146bfcef1c", + "sha256:9687049d53695ad45cf5fdc7bbd51f0c49f1ea3ecfc4b7f3fde7501b541f17f4" + ], + "index": "pypi", + "version": "==4.3.0" + }, + "six": { + "hashes": [ + "sha256:3350809f0555b11f552448330d0b52d5f24c91a322ea4a15ef22629740f3761c", + "sha256:d16a0141ec1a18405cd4ce8b4613101da75da0e9a7aec5bdd4fa804d0e0eba73" + ], + "version": "==1.12.0" + } + } +} diff --git a/README.md b/README.md index 0292400..159d702 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,24 @@ This module is used as an example package for the Sept 2018 meetup, and also used as an example on slcpy.com. +# Standard Installation + +- `pip install utah` +- Set your `MEETUP_API_KEY` value: `$export MEETUP_API_KEY=api_key_value`, located at [meetup.com](https://secure.meetup.com/meetup_api/key/). +- Test with `from utah import slcpython; slcpython.howdy()` in a python interpreter. You should see details of the next meetup. + +# Dev Installation + +- Install `pipenv`: `python3 -m pip install pipenv`. +- Install the pipenv requirements: `pipenv sync --dev' +- After hacking, use `pipenv install -e .` +- For testing use: `python -m pytest` + + ## TODO - [x] Add tests -- [ ] Integrate meetup api to find latest meetups. +- [x] Integrate `meetup api` to find latest meetups. - [ ] Research if public api exists. - [ ] Figure out friendly auth flow for API key. +- [ ] Use rst for README diff --git a/setup.py b/setup.py index 8e0ec93..8f974fb 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ def readme(): setup( name='utah', - version='0.2', + version='0.9', description='The official module for Utah Python / SLCPython', long_description=readme(), classifiers=[ @@ -21,7 +21,10 @@ def readme(): author_email='faris@theluckybead.com', license='MIT', packages=['utah'], + install_requires=[ + 'meetup-api' + ], zip_safe=False, test_suite='nose.collector', - test_require=['nose'] + test_require=['pytest', 'pipenv'] ) diff --git a/utah/slc/__init__.py b/utah/slc/__init__.py new file mode 100644 index 0000000..6e1cfcb --- /dev/null +++ b/utah/slc/__init__.py @@ -0,0 +1 @@ +from utah.slcpython import * \ No newline at end of file diff --git a/utah/slcpython/__init__.py b/utah/slcpython/__init__.py index 97dc81e..dcb40d4 100644 --- a/utah/slcpython/__init__.py +++ b/utah/slcpython/__init__.py @@ -1,9 +1,44 @@ -def howdy(): - msg = """ - Howdy, Salt Lake City! - "Our next meetup is on:" - "Wednesday, September 5th, at 6:30 p.m." - "and is about:" - "A trio of python talks: Beginning / Intermediate / Advanced" +import os +from datetime import datetime +import webbrowser + +import meetup.api +from meetup.exceptions import ApiKeyError + + +def get_group_next_event(urlname='slcpython', key=''): + # TODO: convert to async def + client = meetup.api.Client(key) + group_info = client.GetGroup({'urlname': urlname}) + return group_info.next_event + + +def howdy(key=''): + try: + api_key = os.environ.get('MEETUP_API_KEY', key) + next_event_info = get_group_next_event(key=api_key) + next_datetime = datetime.fromtimestamp( + next_event_info['time'] / 1000.0) + datefmt = r'%A, %B %-d' + timefmt = r'%-I:%M%p' + time_msg = f"{next_datetime.strftime(datefmt)}, at {next_datetime.strftime(timefmt).lower()}" + + msg = f""" + Howdy, Salt Lake City! 🤠 + "Our next meetup is on:" + "{time_msg}" + "and is about:" + "{next_event_info['name']}" + """ + except (ApiKeyError, KeyError): + msg = """ + Sorry, we couldn't find a MEETUP_API_KEY. + Please set one up by visiting + https://secure.meetup.com/meetup_api/key/ + Then, `export MEETUP_API_KEY=` before + running this command. + Alternatively, you may add a `key` argument + to `howdy`. Eg, `slcpython.howdy(key='')` """ + print(msg) diff --git a/utah/slcpython/tests/test_howdy.py b/utah/slcpython/tests/test_howdy.py index 4df9f90..100b1a5 100644 --- a/utah/slcpython/tests/test_howdy.py +++ b/utah/slcpython/tests/test_howdy.py @@ -1,8 +1,9 @@ -import sys from contextlib import contextmanager -from unittest import TestCase - from io import StringIO +import sys + +from unittest import TestCase +from unittest.mock import patch from utah.slcpython import howdy @@ -19,7 +20,8 @@ def captured_output(): class TestHowdy(TestCase): - def test_howdy_prints_info(self): + @patch('utah.slcpython.meetup.api') + def test_howdy_prints_info(self, client): with captured_output() as (out, err): howdy() output = out.getvalue()