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 add_artcle(url, description, title, user): existing_item = dbservice.get_feed_by_url(url) if existing_item is None: print("No existing feed item found") item = None if is_valid_title(title): item = create_feed_item(url, description, user.username, title) dbservice.store_item(item) return STATUS_OK else: try: item = get_feed_item(url, description, user.username) dbservice.store_item(item) return STATUS_OK except: raise elif is_feed_allowed(existing_item.date, datetime.datetime.now()): item = None if is_valid_title(title): item = create_feed_item(url, description, user.username, title) else: try: item = get_feed_item(url, description, user.username) dbservice.store_item(item) return STATUS_OK except: raise else: return STATUS_EXISTS