python新闻管理系统_python项目——新闻管理系统
fromcolorama import Fore,Stylefromgetpass import getpass #獲取用輸入密碼fromservice.user_service import UserServicefromservice.news_service import NewsServicefromservice.role_service import RoleService
import os #為了清空控制臺內(nèi)容
import sys
import time
__user_service=UserService()
__news_service=NewsService()
__role_service=RoleService()whileTrue:
os.system("cls")
print(Fore.LIGHTBLUE_EX,"\n\t+++++++++++++++++++")
print(Fore.LIGHTBLUE_EX,"\n\t歡迎使用新聞管理系統(tǒng)")
print(Fore.LIGHTBLUE_EX,"\n\t+++++++++++++++++++")
print(Fore.LIGHTGREEN_EX,"\n\t1)登陸系統(tǒng)")
print(Fore.LIGHTGREEN_EX,"\n\t2)退出系統(tǒng)")
print(Style.RESET_ALL)
opt= input("\n\t輸入你的操作編號:")if opt == "1":
username= input("\n\t輸入你的用戶名:")
password= getpass("\n\t輸入你的密碼:")
result=__user_service.login(username,password)
#登陸成功if result ==True:
#查詢角色
role=__user_service.search_user_role(username)whileTrue:
os.system("cls")if role == "新聞編輯":
print("test")
elif role== "管理員":
print(Fore.LIGHTGREEN_EX,"\n\t1)新聞管理")
print(Fore.LIGHTGREEN_EX,"\n\t2)用戶管理")
print(Fore.LIGHTRED_EX,"\n\tback)退出登陸")
print(Fore.LIGHTRED_EX,"\n\texit)退出系統(tǒng)")
print(Style.RESET_ALL)
opt= input("\n\t輸入你的操作編號:")if opt == "1":whileTrue:
os.system("cls")
print(Fore.LIGHTGREEN_EX,"\n\t1)審批新聞")
print(Fore.LIGHTGREEN_EX,"\n\t2)刪除新聞")
print(Fore.LIGHTRED_EX,"\n\tback)返回")
print(Style.RESET_ALL)
opt= input("\n\t輸入你的操作編號:")if opt == "1":
page= 1
whileTrue:
os.system("cls")
count_page=__news_service.search_unreview_count_page()
result=__news_service.search_unreview_list(page)for index inrange(len(result)):
one=result[index]
print(Fore.LIGHTBLUE_EX,"\n\t{0}\t{1}\t{2}\t{3}".format(index+1,one[1],one[2],one[3]))
print(Fore.LIGHTBLUE_EX,"\n\t-------------------")
print(Fore.LIGHTBLUE_EX,"\n\t{0}/{1}".format(page,count_page))
print(Fore.LIGHTBLUE_EX,"\n\t-------------------")
print(Fore.LIGHTRED_EX,"\n\tback)返回")
print(Fore.LIGHTRED_EX,"\n\tprev)上一頁")
print(Fore.LIGHTRED_EX,"\n\tnext)下一頁")
print(Style.RESET_ALL)
opt= input("\n\t輸入你的操作編號:")if opt == "back":breakelif opt== "prev" and page > 1:
page-=1elif opt== "next" and page
page+=1elifint(opt) >= 1 and int(opt) <= 10:
news_id= result[int(opt) - 1][0]
__news_service.update_unreview_news(news_id)
elif opt== "2":
page= 1
whileTrue:
os.system("cls")
count_page=__news_service.search_count_page()
result=__news_service.search_list(page)for index inrange(len(result)):
one=result[index]
print(Fore.LIGHTBLUE_EX,"\n\t{0}\t{1}\t{2}\t{3}".format(index + 1, one[1], one[2], one[3]))
print(Fore.LIGHTBLUE_EX,"\n\t-------------------")
print(Fore.LIGHTBLUE_EX,"\n\t{0}/{1}".format(page, count_page))
print(Fore.LIGHTBLUE_EX,"\n\t-------------------")
print(Fore.LIGHTRED_EX,"\n\tback)返回")
print(Fore.LIGHTRED_EX,"\n\tprev)上一頁")
print(Fore.LIGHTRED_EX,"\n\tnext)下一頁")
print(Style.RESET_ALL)
opt= input("\n\t輸入你的操作編號:")if opt == "back":breakelif opt== "prev" and page > 1:
page-= 1elif opt== "next" and page
page+= 1elifint(opt) >= 1 and int(opt) <= 10:
news_id= result[int(opt) - 1][0]
__news_service.delete_by_id(news_id)
elif opt== "back":breakelif opt== "2":whileTrue:
os.system("cls")
print(Fore.LIGHTGREEN_EX,"\n\t1)添加用戶")
print(Fore.LIGHTGREEN_EX,"\n\t2)修改用戶")
print(Fore.LIGHTGREEN_EX,"\n\t3)刪除用戶")
print(Fore.LIGHTRED_EX,"\n\tback)返回")
print(Style.RESET_ALL)
opt= input("\n\t輸入你的操作編號:")if opt == "back":breakelif opt== "1":
os.system("cls")
username= input("\n\t你要添加的用戶名字")
password= getpass("\n\t輸入新用戶密碼")
repassword= getpass("\n\t再次輸入新用戶密碼")if password !=repassword:
print(Fore.LIGHTRED_EX,"\n\t兩次密碼不一致(3秒自動返回)")
time.sleep(3)continueemail= input("\n\t新用戶郵箱:")
result=__role_service.search_list()for index inrange(len(result)):
one=result[index]
print(Fore.LIGHTBLUE_EX,"\n\t{0}.{1}".format(index+1,one[1]))
print(Style.RESET_ALL)
opt= input("\n\t新用戶的角色編號:")
role_id= result[int(opt)-1][0]
__user_service.insert_user(username,password,email,role_id)
print("\n\t保存成功(3秒自動返回)")
time.sleep(3)
elif opt== "2":
page= 1
whileTrue:
os.system("cls")
count_page=__user_service.search_count_page()
result=__user_service.search_list(page)for index inrange(len(result)):
one=result[index]
print(Fore.LIGHTBLUE_EX,"\n\t{0}\t{1}\t{2}".format(index + 1, one[1], one[2]))
print(Fore.LIGHTBLUE_EX,"\n\t-------------------")
print(Fore.LIGHTBLUE_EX,"\n\t{0}/{1}".format(page, count_page))
print(Fore.LIGHTBLUE_EX,"\n\t-------------------")
print(Fore.LIGHTRED_EX,"\n\tback)返回")
print(Fore.LIGHTRED_EX,"\n\tprev)上一頁")
print(Fore.LIGHTRED_EX,"\n\tnext)下一頁")
print(Style.RESET_ALL)
opt= input("\n\t輸入你的操作編號:")if opt == "back":breakelif opt== "prev" and page > 1:
page-= 1elif opt== "next" and page
page+= 1elifint(opt) >= 1 and int(opt) <= 10:
os.system("cls")
user_id= result[int(opt)-1][0]
username= input("\n\t你要修改成的用戶名字")
password= getpass("\n\t輸入新密碼")
repassword= getpass("\n\t再次輸入新密碼")if password !=repassword:
print(Fore.LIGHTRED_EX,"\n\t兩次密碼不一致(3秒自動返回)")
time.sleep(3)
print(Style.RESET_ALL)breakemail= input("\n\t新用戶郵箱:")
result=__role_service.search_list()for index inrange(len(result)):
one=result[index]
print(Fore.LIGHTBLUE_EX,"\n\t{0}.{1}".format(index + 1, one[1]))
print(Style.RESET_ALL)
opt= input("\n\t新用戶的角色編號:")
role_id= result[int(opt) - 1][0]
opt= input("\n\t是否保存(Y/N)")if opt.upper() == "Y":
__user_service.update(user_id,username,password,email,role_id)
print("\n\t保存成功(3秒自動返回)")
time.sleep(3)
elif opt== "3":
page= 1
whileTrue:
os.system("cls")
count_page=__user_service.search_count_page()
result=__user_service.search_list(page)for index inrange(len(result)):
one=result[index]
print(Fore.LIGHTBLUE_EX,"\n\t{0}\t{1}\t{2}".format(index + 1, one[1], one[2]))
print(Fore.LIGHTBLUE_EX,"\n\t-------------------")
print(Fore.LIGHTBLUE_EX,"\n\t{0}/{1}".format(page, count_page))
print(Fore.LIGHTBLUE_EX,"\n\t-------------------")
print(Fore.LIGHTRED_EX,"\n\tback)返回")
print(Fore.LIGHTRED_EX,"\n\tprev)上一頁")
print(Fore.LIGHTRED_EX,"\n\tnext)下一頁")
print(Style.RESET_ALL)
opt= input("\n\t輸入你的操作編號:")if opt == "back":breakelif opt== "prev" and page > 1:
page-= 1elif opt== "next" and page
page+= 1elifint(opt) >= 1 and int(opt) <= 10:
os.system("cls")
user_id= result[int(opt) - 1][0]
__user_service.delete_by_id(user_id)
print("\n\t刪除成功(3秒自動返回)")
time.sleep(3)
elif opt== "back":breakelif opt== "exit":
sys.exit(0)else:
print("\n\t登陸失敗,3秒自動返回")
time.sleep(3)
elif opt== "2":
sys.exit(0)#0代表安全退出,等數(shù)據(jù)釋放等
總結(jié)
以上是生活随笔為你收集整理的python新闻管理系统_python项目——新闻管理系统的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: python程序多次运行_如何让编程语言
- 下一篇: python趣味编程_第6章 旋转的方块
