Skip to content

Commit

Permalink
Switch to using make / setuptools
Browse files Browse the repository at this point in the history
  • Loading branch information
kchristensen committed Apr 25, 2018
1 parent 3a933b6 commit eb5d6db
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 21 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,4 @@ docs/_build/
target/

.vscode/
slappd.cfg
slappd.cfg.bak
tags
3 changes: 0 additions & 3 deletions .pylintrc

This file was deleted.

1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include templates/*.j2
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# slappd

### About

Since Untappd does not currently support callbacks or webhooks, I wrote a basic
Slack integration that will relay check-ins and badges earned for specified users
on your feed to a Slack channel.
Expand All @@ -10,19 +11,23 @@ on your feed to a Slack channel.
This script is designed to be run from crontab, and issues one API call per run.

### Known Issues
* The first time you run the script, it may be a little chatty because it has not
previously seen your feed before.

* The first time you run the script, it may be a little chatty because it has
not previously seen your feed before.
* If you have a lot of Untappd friends, but are only watching a subset of them,
you may miss check-ins if you don't run Slappd regularly.
you may miss check-ins if you don't run Slappd regularly.

### Requirements

* Python 3.5+ (It may run on >= 3.0, but I have not tested.)
* Some Python modules (configparser, Jinja2, simplejson, requests)
* A way of periodically running this script (at, cron, etc)
* Untappd [API access](https://untappd.com/api/register?register=new)
* A Slack channel full of beer lovers

### Configuration
* Install the required Python modules via: `pip3 install -r requirements.txt`
* Copy [slappd.cfg.dist](slappd.cfg.dist) to 'slappd.cfg' and edit it to reflect your API information
* Run it from crontab: `*/5 * * * python3.5 /path/to/slappd.py > /dev/null 2>&1`
### Installation & Configuration

* Install Slappd to a virtualenv via `make install`.
* If this is your first time, create the default config file with `make config`
and then edit it `(~/.config/slappd/slappd.cfg)` to reflect your API information.
* Run it from crontab: `*/5 * * * ~/.virtualenv/slappd/bin/slappd > /dev/null 2>&1`
30 changes: 30 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
SHELL = /bin/bash
VIRTUALENV_DIR = ${HOME}/.virtualenv
CFG_DIR = ${HOME}/.config/slappd

.PHONY: config
config:
mkdir -p ${CFG_DIR}
test -f ${CFG_DIR}/slappd.cfg || cp -p slappd.cfg.dist ${CFG_DIR}/slappd.cfg

.PHONY: dev
dev: ${VIRTUALENV_DIR}/slappd
source ${VIRTUALENV_DIR}/slappd/bin/activate && \
pip install -U flake8 pip && \
pip install --editable .

.PHONY: install
install: ${VIRTUALENV_DIR}/slappd
source ${VIRTUALENV_DIR}/slappd/bin/activate && \
pip install -U pip && \
pip install --upgrade .

${VIRTUALENV_DIR}/slappd:
mkdir -p ${VIRTUALENV_DIR}
cd ${VIRTUALENV_DIR} && python3 -m venv slappd

.PHONY: lint
lint:
-flake8

.DEFAULT_GOAL := install
3 changes: 0 additions & 3 deletions requirements.txt

This file was deleted.

16 changes: 16 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[flake8]
exclude =
.git,
__pycache__,
build,
dist
max-line-length = 120

[isort]
import_heading_firstparty = First Party Imports
import_heading_future = Future Imports
import_heading_localfolder = Local Imports
import_heading_stdlib = Standard Library Imports
import_heading_thirdparty = Third Party Imports
line_length = 119
skip = setup.py
24 changes: 24 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env python3

""" Slappd setup.py. """

from setuptools import setup

setup(
entry_points='''
[console_scripts]
slappd=slappd.__main__:main
''',
include_package_data=True,
install_requires=[
'Jinja2',
'configparser',
'requests'
],
name='slappd',
packages=['slappd'],
package_data={
'': ['templates/*.j2']
},
version='1.0.0'
)
1 change: 1 addition & 0 deletions slappd/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
""" Slappd Package """
17 changes: 11 additions & 6 deletions slappd.py → slappd/__main__.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@
SOFTWARE.
"""

# Standard Library Imports
import os
import re
import sys

# First Party Imports
from configparser import SafeConfigParser
from operator import itemgetter

# Third Party Imports
import requests
from jinja2 import Environment, FileSystemLoader

Expand All @@ -49,7 +53,7 @@ def check_for_photos(checkins):

def config_load():
""" Load configuration options from file """
config_file = get_cwd() + '/slappd.cfg'
config_file = get_cfg_path()
if not os.path.exists(config_file):
sys.exit('Error: Configuration file {} does not exist'
.format(config_file))
Expand All @@ -59,7 +63,7 @@ def config_load():

def config_update():
""" Updates the config file with any changes that have been made """
config_file = get_cwd() + '/slappd.cfg'
config_file = get_cfg_path()
try:
with open(config_file, 'w') as cfg_handle:
CONFIG.write(cfg_handle)
Expand Down Expand Up @@ -93,9 +97,9 @@ def fetch_url(method):
CONFIG.get('untappd', 'lastseen'))


def get_cwd():
""" Return the current working directory """
return os.path.dirname(os.path.realpath(__file__))
def get_cfg_path():
""" Return the path to the config file """
return os.path.expanduser('~/.config/slappd/slappd.cfg')


def slack_message(images=None, msg_type=None, text=None):
Expand Down Expand Up @@ -133,8 +137,9 @@ def strip_html(text):
def main():
""" Where the magic happens """
config_load()
cwd = os.path.dirname(os.path.realpath(__file__))
data = fetch_untappd_activity()
env = Environment(loader=FileSystemLoader(get_cwd() + '/templates'))
env = Environment(loader=FileSystemLoader('{}/templates'.format(cwd)))

if data['meta']['code'] == 200:
checkins = data['response']['checkins']['items']
Expand Down
File renamed without changes.

0 comments on commit eb5d6db

Please sign in to comment.