python作业3

###用户管理和数据库#####


#!/bin/usr/env python

#coding = utf-8
from time import time,ctime
import MySQLdb
import getpass
conn = MySQLdb.connect(user="root",passwd="yiyibushe",db="westos",host="localhost",charset="utf-8")
cur=conn.cursor()

def menu():
    while True:
        print '''
            (A)dd user
            (L)ogin user
            (D)elete user
            (S)how user
            (E)xit
              '''
        choice=raw_input("please input your choice:").lower()
        if choice == "d":    
            deluser()
        elif choice == "a":
            adduser()
        elif choice == "l":
            login()
        elif choice == "s":
            showuser()
        elif choice == "e":
            exit(0)
        else:
            print "input error!"
def adduser():
    name=raw_input("please input username:")
    pwd=getpass.getpass("please input password:")
    logintime=time()
    cur.execute("insert into linux values('%s','%s','%s')"%(name,pwd,logintime))
    print "add success!"
def login():
    for i in range(3):
        name=raw_input("login username:")
        pwd=getpass.getpass("passwd:")
        data=cur.fetchone(execute("select * from linux where username='%s'"%(name)))
        if data[0]==name and  data[1]=pwd
            print "login success!"
            current=time()
            delta=current-data[2]
            if  delta<=14400:
                print "You already logged in 4 hours period!"
            else:
                cur.execute("update linux set logintime='%s' where username='%s'"%(time(),data[0]))
                cur.commit()
                break
        else:
            print "login incorrect"
def deluser():
    name=raw_input("please input delete username:")
    cur.execute("delete from linux where username=%s"%(naem))
    cur.commit()
    print "delete success!"
def showuser():
    for i in cur.fetchall(execute("select * from linux")):
        a,b,c=i
        print "%s %s %s"%(a,b,c)

menu()







###备份####


  1 #!/usr/bin/env python
  2 #coding=utf-8
  3 import os
  4 filelist=[]
  5 while True:
  6         back_file=raw_input("input load:")
  7         if back_file!='q':
  8                 filelist.append(back_file)
  9         else:
 10            break
 11 back_dir=raw_input("input dir:")
 12 for i in filelist:
 13         o=os.system("cp %s %s >/dev/null"%(i,back_dir))
 14         if o==0:
 15                 print "success!"
 16         else:
 17                 print "error!"
~                                     

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值