Backend Development 11 min read

Automated Reminder App for Youth Study Using Flask and uni‑app

This article presents a step‑by‑step guide for building a Flask‑based backend and uni‑app frontend that automatically reminds class members to complete the Youth Study program, covering database configuration, model definitions, API routes, email notifications, data handling, and deployment screenshots.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Automated Reminder App for Youth Study Using Flask and uni‑app

The author, a class youth league secretary, created an automated reminder system for the Youth Study program, initially as a script and later packaged as a full application using a Flask backend and a uni‑app frontend.

Backend Configuration

<code>HOSTNAME = '127.0.0.1'  # MySQL host
PORT = '3306'
DATABASE = 'teenstudy'
USERNAME = 'root'
PASSWORD = 'root'

db_url = 'mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8'.format(
    USERNAME,
    PASSWORD,
    HOSTNAME,
    PORT,
    DATABASE,
)

class Config(object):
    SQLALCHEMY_DATABASE_URI = db_url
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True

app = Flask(__name__)
CORS(app, supports_credentials=True)
pymysql.install_as_MySQLdb()
app.config.from_object(Config)
db = SQLAlchemy(app)
manager = Manager(app)      # data migration
Migrate(app, db)
manager.add_command("db", MigrateCommand)

engin = create_engine(db_url)  # create engine
Base = declarative_base(engin)
Session = sessionmaker(engin)
session = Session()</code>

Database Models

<code># User model
class User(db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    account = db.Column(db.String(18))  # account
    add_time = db.Column(db.DateTime, index=True, default=datetime.datetime.now())
    email = db.Column(db.String(100))
    name = db.Column(db.String(16))
    province = db.Column(db.String(255))
    school = db.Column(db.String(255))
    college = db.Column(db.String(255))
    origirtion = db.Column(db.String(255))
    grade = db.Column(db.String(255))
    major = db.Column(db.String(255))
    count = db.Column(db.Boolean, default=False)
    history_count = db.Column(db.Integer, default=False)
    role_id = db.Column(db.Integer, db.ForeignKey('roles.id'), default=3)
    def __repr__(self):
        return "%s" % self.email

# Role model
class Role(db.Model):
    __tablename__ = 'roles'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(8), unique=True)  # 1: admin, 2: secretary, 3: member
    users = db.relationship('User', backref='role')
    def __repr__(self):
        return "<roles(id:%d,name:%s)" % (self.id, self.name)

# Youth Study model
class TeenStudy(db.Model):
    __tablename__ = 'teenstudy'
    id = db.Column(db.Integer, primary_key=True)
    study_id = db.Column(db.String(255))  # period identifier
    study_title = db.Column(db.String(255))
    add_time = db.Column(db.DateTime, index=True, default=datetime.datetime.now())
    def __repr__(self):
        return "<teenstudy(id:%d,study_id:%s,study_title:%s,add_time:%s)>" % (self.id, self.study_id, self.study_title, self.add_time)

# Admin model
class admin(db.Model):
    __tablenaem__ = 'admin'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255))
    password = db.Column(db.String(255))
    add_time = db.Column(db.DateTime, index=True, default=datetime.datetime.now())
    def __repr__(self):
        return "<admin(id:%d,name:%s,password:%s,add_time:%s)>" % (self.id, self.name, self.password, self.add_time)</code>

API Routes

<code>@app.route('/login', methods=['GET', 'POST'])
def login():
    username = request.form.get("username")
    password = request.form.get("password")
    cookie = GetCookie(username, password)
    if cookie == "500":
        return {"code": "500", "msg": "发生了点错误,请稍后重试"}
    headers = {
        'Host': 'm.fjcyl.com',
        'Referer': 'http://m.fjcyl.com/logout',
        'User-Agent': 'Mozilla/5.0 (iPad; CPU OS 13_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/7.0.12(0x17000c33) NetType/WIFI Language/zh_CN',
        'Cookie': cookie
    }
    GetSchoolInfo(headers)
    cate, infoDetail, reg = GetStuInfo(headers)
    # ... handle different roles and return appropriate JSON ...

@app.route('/init_email', methods=['GET', 'POST'])
def init_email():
    QQEmail = request.form.get("QQEmail")
    UserName = request.form.get("UserName")
    acctId = request.form.get("acctId")
    colName = request.form.get("colName")
    grade = request.form.get("grade")
    major = request.form.get("major")
    positionName = request.form.get("positionName")
    schoolName = request.form.get("schoolName")
    count = db.session.query(func.count(User.id)).filter(
        User.school == schoolName,
        User.college == colName,
        User.major == major,
        User.account == acctId
    ).scalar()
    if count == 0:
        user = User(account=acctId, name=UserName, school=schoolName, college=colName,
                    grade=grade, major=major, origirtion=positionName, email=QQEmail)
        db.session.add(user)
        db.session.commit()
        return {"msg": 200, "data": "success"}
    else:
        return {"msg": 200, "data": 10001}

@app.route('/sendMail', methods=['GET', 'POST'])
def sendMail():
    DidDoneLists = request.form.get("EmailList")
    DidDoneList = DidDoneLists.split(",")
    Email = []
    count = 1
    for k in DidDoneList:
        count += 1
        if count == 2:
            Email.append(k)
            count = 0
    msg = MIMEText('青年大学习!不用回复!赶紧做!!')
    msg["Subject"] = "青年大学习!!又是你!!!"
    msg["From"] = '辛苦勤劳艰苦奋斗的团支书'
    msg["To"] = '未做人员'
    from_addr = ''
    password = ''
    smtp_server = 'smtp.qq.com'
    to_addr = Email
    try:
        server = smtplib.SMTP_SSL(smtp_server, 465, timeout=2)
        server.login(from_addr, password)
        server.sendmail(from_addr, to_addr, msg.as_string())
        server.quit()
        logging.info("EMAIL SUCCESS")
        return {"code": "200", "info": "success"}
    except Exception as e:
        logging.error("EMAIL FAIL")
        return {"code": "500", "info": "fail"}</code>

Data Exchange

<code>strinfo = re.compile("'")
Num_Email = str(DidDoneNumList_Json)
Num_Email_Json = strinfo.sub('"', Num_Email)</code>

Frontend with uni‑app

The frontend is built with uni‑app for cross‑platform compatibility. Screenshots show the login page, reminder page, and overall effect. The author downloaded HBuilder X as the development environment.

Conclusion

The system enables all class members to receive timely reminders and complete the Youth Study tasks without manual follow‑up, emphasizing that the tool is solely for convenience and not for any other purpose.

DatabaseWeb Developmentuni-appEmail Automation
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.