Skip to content

Instantly share code, notes, and snippets.

@Thuruv
Created November 9, 2015 12:45
Show Gist options
  • Save Thuruv/841ec2034ef10ed09223 to your computer and use it in GitHub Desktop.
Save Thuruv/841ec2034ef10ed09223 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
"""
Created on Mon Nov 9 13:11:35 2015
@author: mendox
"""
import argparse
import MySQLdb
from prettytable import PrettyTable
db = MySQLdb.connect("localhost","root","mendox","test" )
cursor = db.cursor()
parser = argparse.ArgumentParser(description='Custom Task Manager for Myself')
parser.add_argument('-v','-version',
action="store_true",
help = 'See the Version')
parser.add_argument('-n',
type = str,
nargs='*',
help='What\'s the Task?')
parser.add_argument('-p',
help='Set the priority' )
parser.add_argument('-s',
help='Set the Status')
parser.add_argument('-show',
action="store_true",
help='Show Tasks')
args = parser.parse_args()
if args.v:
print 'version is 2.2'
sqlnewdb = """CREATE TABLE tasker (
TASK CHAR(50) NOT NULL,
PRIORITY INT,
STATUS CHAR(10))
"""
sqladd = "INSERT INTO test.tasker (task,priority,status) VALUES (%s, %s, %s)"
sqlsee = """select * from tasker"""
if args.n:
#print (' '.join(args.n),args.p,args.s)
cursor.execute(sqladd,(' '.join(args.n),int(args.p),args.s))
db.commit()
print 'added'
if args.show:
cursor.execute(sqlsee)
resultset = cursor.fetchall()
x = PrettyTable(['id','task','priority','status'])
# x = PrettyTable(['id','task'])
x.align["id"] = "l" # Left align city names
x.padding_width = 1 # One space between column edges and contents (default)
for res in resultset:
x.add_row(list(res))
print x
# disconnect from server
db.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment