Skip to content

Instantly share code, notes, and snippets.

@AwwCookies
Created April 30, 2015 04:35
Show Gist options
  • Save AwwCookies/3a50c7e5d84940c027b7 to your computer and use it in GitHub Desktop.
Save AwwCookies/3a50c7e5d84940c027b7 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python2
import sqlite3
import sys
# Path to Tasker DB
DB_PATH = "/home/aww/tasker.db"
connection = sqlite3.connect(DB_PATH)
cursor = connection.cursor()
# Create a new table in the database if one does not exists with three cols
cursor.execute("CREATE TABLE IF NOT EXISTS tasker (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, description TEXT)")
# This saves the changes to the database
connection.commit()
# $ tasker
if len(sys.argv) > 1:
# $ tasker add Cookies go buy cookies
if sys.argv[1] in ["add", "a", "new", "create"]:
cursor.execute('INSERT INTO tasker (name, description) VALUES ("%s", "%s")'
% (sys.argv[2], ' '.join(sys.argv[3:])))
print("Task: %s added!" % sys.argv[2])
connection.commit()
# $ tasker remove 1
if sys.argv[1] in ["remove", "delete", "del", "rem"]:
cursor.execute("DELETE FROM tasker WHERE id LIKE %i" % int(sys.argv[2]))
#TODO Find a better way of reindexing the table
rows = []
for row in cursor.execute("SELECT * FROM tasker"):
id, name, desc = row
rows.append((id, name, desc))
cursor.execute("DROP TABLE tasker")
cursor.execute('CREATE TABLE tasker (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, description TEXT)')
for row in rows:
cursor.execute('INSERT INTO tasker (name, description) VALUES ("%s", "%s")'% (row[1], row[2]))
print("Task %i was removed" % int(sys.argv[2]))
connection.commit()
if sys.argv[1] in ["purge", "remove_all", "fuckit"]:
if str(raw_input("Are you sure you want to delete all your task?: ")) in ["y", "yes", "fuck yes"]:
cursor.execute("DROP TABLE tasker")
print("The evil has been purged.")
else:
for row in cursor.execute("SELECT * FROM tasker"):
id, name, description = row
print("[%i] %s: %s" % (id, name, description))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment