Created
September 9, 2015 22:59
-
-
Save timothycrosley/6b27bbad75c4b5f11c81 to your computer and use it in GitHub Desktop.
Simple todo for puppy meetup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''Quite possibly the most simplistic remotely available todo list ever created''' | |
import hot_redis as redis | |
import hug | |
import requests | |
todos = redis.List(key='my_todos') | |
authentication = hug.authentication.basic(hug.authentication.verify(*AUTH)) | |
@hug.get('/todos') | |
def get_todos(): | |
'''Returns a list of all my todo items''' | |
return list(todos) | |
@hug.post('/todos', requires=authentication) | |
def add_todo(todo): | |
'''Adds a new todo item''' | |
todos.append(todo) | |
@hug.delete('/todos', requires=authentication) | |
def remove_todo(todo): | |
'''Removes a todo from the list''' | |
todos.pop(todos.index(todo)) | |
@hug.cli() | |
def todo_list(add=None, remove=None, endpoint=’localhost:8000/ci’, user=’username’, password=’password’): | |
'''A super simple remotely available todo list''' | |
if add: | |
return requests.post(endpoint, data={'todo': add}, auth=(user, password)) and 'Successfully added todo' | |
if remove: | |
return requests.delete(endpoint, data={'todo': remove}, auth=(user, password)) and 'Successfully removed/completed todo' | |
return "\t### Your Todos ###\n" + "\n".join(requests.get(endpoint, auth=auth).json()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment