求助各位大佬,这是什么问题
import os
import sys
import pandas as pd
import re # 正则表达式
from datetime import datetime,timedelta
import uuid # 随机字符串
import time
#显示所有列
pd.set_option('display.max_columns', None)
#显示所有行
pd.set_option('display.max_rows', None)
#设置value的显示长度为100,默认为50
pd.set_option('max_colwidth',100)
# 格式输出
def print_message(*message):
print("【{}】 【{}】".format(datetime.now(), message))
# 判断字符串是否是手机号码格式
def check_phone(n):
if re.match(r'1[3,4,5,7,8]\d{9}',n):
print("您输入的的手机号码是:\n",n)
#中国联通:
# 130,131,132,155,156,185,186,145,176
if re.match(r'13[0,1,2]\d{8}',n) or \
re.match(r"15[5,6]\d{8}",n) or \
re.match(r"18[5,6]",n) or \
re.match(r"145\d{8}",n) or \
re.match(r"176\d{8}",n):
print("该号码属于:中国联通")
#中国移动
# 134, 135 , 136, 137, 138, 139, 147, 150, 151,
# 152, 157, 158, 159, 178, 182, 183, 184, 187, 188;
elif re.match(r"13[4,5,6,7,8,9]\d{8}",n) or \
re.match(r"147\d{8}|178\d{8}",n) or \
re.match(r"15[0,1,2,7,8,9]\d{8}",n) or \
re.match(r"18[2,3,4,7,8]\d{8}",n):
print("该号码属于:中国移动")
else:
#中国电信
#133,153,189
print("该号码属于:中国电信")
return True
else:
print("请输入正确的手机号")
return False
def get_uuid():
time_stamp = str(time.time())
namespace = uuid.NAMESPACE_URL
uuuid = uuid.uuid5(namespace,time_stamp)
uuuid_string = str(uuuid).split("-")[-1]
# print(time_stamp_uuid)
return uuuid_string
def read_user_csv_names():
# 读入user.csv文件
users = pd.read_csv("db/user.csv", index_col= False)
user_names = []
if len(users) > 0:
# 设定index
users.columns = ["user_id" , "name" , "password" , "phone" , "status" , "role"]
# 已注册用户名
user_names = users['name'].values
return user_names
# 获取user.csv的全部users
def read_user_csv_users():
users = pd.read_csv("db/user.csv", index_col= False)
return users
# 获取book.csv的全部books
def read_book_csv_books():
books = pd.read_csv("db/book.csv", index_col= False)
return books
# 获取history.csv的全部history
def read_history_csv_history():
history = pd.read_csv("db/history.csv", index_col= False)
return history
# 保存cache
def save_cache(cache_name, cache):
with open("cache/{}".format(cache_name), "w") as f:
f.write(cache)
# 获取用户权限
def get_role(role):
role_dict = {1: "普通用户", 999: "管理员"}
return role_dict[role]
# 获取今日日期
def get_today():
# 获取今日日期
now = datetime.now()
# print(now)
year = now.year
month = now.month
day = now.day
today = f"{year}/{month}/{day}"
# print(today)
return today
# 注册管理员用户
while True:
name = input("姓名(输入q结束流程):")
# 输入q结束
if name == "q":
print_message("结束")
break
# 判断用户是否存在?
if name in read_user_csv_names():
print_message("该用户已存在,请重新输入")
continue
password = input("密码:")
confirm_password = input("确认密码:")
if password != confirm_password:
print_message("两次密码不一致,注册失败!请重新注册")
continue
phone = input("手机:")
if not check_phone(phone):
print_message("手机号输入错误,注册失败!请重新注册")
continue
try:
users = read_user_csv_users()
users=users.append({"user_id": get_uuid() , "name":name , "password":password, "phone":phone, "status":"1", "role":"999"} , ignore_index=True)
users.to_csv("db/user.csv", index = False)
print_message("注册成功")
break
except Exception as e:
print_message("保存失败", e)