Skip to content

Instantly share code, notes, and snippets.

@timothycrosley
Created September 9, 2015 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timothycrosley/6b27bbad75c4b5f11c81 to your computer and use it in GitHub Desktop.
Save timothycrosley/6b27bbad75c4b5f11c81 to your computer and use it in GitHub Desktop.
Simple todo for puppy meetup
'''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