def generate(): #yield '<meta http-equiv="content-Type" content="text/html; charset=utf-8">' #yield '<pre>' for user in User.query.filter(User.last_checked != today()): yield 'Fetching data for ' yield user.omikk_uid yield ' - ' yield user.email yield '\n' data = omikk.get_data(user.omikk_uid, user.omikk_password) if(not mailvalidator.validate(data['email'])): yield "Mail not valid.\n\n" continue days_left = (data['closest_expiration'] - today()).days if(days_left<=7): yield "Sending mail to " yield data['email'] yield ' with content: ' content = 'Hátralévő napok a következő lejáratig: %d (%s)' % (days_left, data['closest_expiration']) yield content yield '\n' sendmail.send('"OMIKK lejárat értesítő bot" <'+SOURCE_EMAIL+'>', data['email'], 'Könyvtári értesítő', content) yield 'Sent.\n' else: yield ' -> No action needed. \n' user.last_checked = today() db.session.commit() yield 'Last checked date commited.\n' yield '\n'
def register(): if request.method == 'POST': omikk_user = request.form['omikk_user'] omikk_pass = request.form['omikk_pass'] email = request.form['email'] data = omikk.get_data(omikk_user, omikk_pass) if(data==False): return render_template('register.html', bad_attempt = True) else: User.query.filter(User.omikk_uid == omikk_user).delete() sendmail.remove_from_unsubscribe_list(email) user = User(email, omikk_user, omikk_pass) db.session.add(user) db.session.commit() days_left = (data['closest_expiration'] - today()).days return render_template('register_success.html', days_left = days_left) else: return render_template('register.html')
def kalmi_days_left(): user_data = omikk.get_data('12345678','DummyPassword') days_left = (user_data['closest_expiration'] - today()).days return "%s days left (%s)" % (days_left, user_data['closest_expiration'])