def add(): error = None if 'login' not in session: return redirect(url_for('login')) user = dbservice.get_user(username=session['login']) if user is None: return redirect(url_for('login')) if request.method == 'POST': url = request.form['url'] description = request.form['description'] description = "" existing_item = dbservice.get_feed_by_url(url) if existing_item is None: print("No existing feed item found") item = rss.get_feed_item(url, description, user.username) dbservice.store_item(item) error = "Success" elif rss.is_feed_allowed(existing_item.date, datetime.datetime.now()): item = rss.get_feed_item(url, description, user.username) dbservice.store_item(item) error = "Success" else: error = "Feed was added less than 7 days ago" return render_template("add_item.html", error=error)
def handle_slack(): if settings.slack_token is None or settings.slack_user is None: return get_response('Error: Slack configuration not found') token = request.form['token'] print('Got token ' + token + " given " + settings.slack_token) if settings.slack_token != token: return get_response('Error: Slack token does not match') user = dbservice.get_user(settings.slack_user) if user is None: return get_response('Error: Slack user does not exist') text = request.form['text'] if text is not None: return execute_command(text, user) else: return get_response("No Command Found")
def add(): error = None if 'login' not in session: return redirect(url_for('login')) user = dbservice.get_user(username=session['login']) if user is None: return redirect(url_for('login')) if request.method == 'POST': url = request.form['url'] description = request.form['description'] title = request.form['title'] try: result = rss.add_artcle(url, description, title, user) if result == rss.STATUS_OK: error = "Success" elif result == rss.STATUS_EXISTS: error = "Feed was added less than 7 days ago" except: error = 'Could not save' return render_template("add_item.html", error=error, title=settings.title)
def create_user(username, password): user = dbservice.get_user(username) if user is None: dbservice.add_user(username, password) else: print("User already exists")