コード例 #1
0
def get_user_name():
    name = ""
    while not name:
        name = input("Author:")
        if not str(name).isalnum():
            print("Only alphanumeric chars.")
            name = ""
        db_cur = db.cursor()
        db_cur.execute("SELECT Name FROM Users")
        user = db_cur.fetchall()
        for i in user:
            if not name == i[0]:
                registration = input("There is no user like {0}. Want to register? (y/n)".format(name))
                db_cur.close()
                if not registration == "y" and not registration == "n":
                    print("y/n")
                if registration == "y":
                    register.main()
                else:
                    break
            else:
                print("You will post as {0}".format(name))
                break

        db_cur.close()
    return name
コード例 #2
0
def menu():
    os.system('CLS')
    print("""
    ---------------------------------------------------
    Lightweight Python News System Admin
    ---------------------------------------------------
    """)
    chosen = ""
    while not chosen:
        chosen = input("Press '1' to add new user or press '2' to add new article.")
        if not chosen == "2" and not chosen == "1":
            print("Please chose from the options. 1 - New User 2 - New Article.")
            chosen = ""
    if chosen == "1":
        register.main()
    elif chosen == "2":
        addnews.main()