diff --git a/feeds.py b/feeds.py index ce4110f..9b75444 100644 --- a/feeds.py +++ b/feeds.py @@ -35,13 +35,16 @@ def parse_feeds(feeds): return sorted(results, key=operator.itemgetter(4), reverse=True) -def set_title_by_feed(url): +def set_title_by_feed(url,city=""): # return tuple of porject name and specific title for new feeds project_name = get_project_by_feed_url(url) try: title = feedparser.parse(url).feed.title except: - title=None + title="" + if project_name=='תב"ע פתוחה': + title+=" " + str(city) + print(title) return (project_name,title) def relevant_feeds(user_id=None): @@ -59,7 +62,7 @@ def relevant_feeds_urls(): def get_project_by_feed_url(url): # return project name (and subclass,if relevant, by feed address) - domain_first_part = urllib.parse.urlparse(url).netloc.split(".")[0] + domain_first_part = url.split(".")[0] if "opentaba" in domain_first_part: return 'תב"ע פתוחה' elif domain_first_part == "kikar": diff --git a/views.py b/views.py index 2022717..e9a8f38 100644 --- a/views.py +++ b/views.py @@ -141,32 +141,20 @@ def add_feed_kikar(): @notifier.route('/addfeed/opentaba', methods=['GET']) @login_required def add_feed_opentaba(): - url = request.args.get('link','') - relevantfeeds = relevant_feeds_urls() try: + url = request.args.get('link','') + city = request.args.get('city') + if city is None: + city="" + relevantfeeds = relevant_feeds_urls() if url not in relevantfeeds: - try: - city = request.args.get('city', '') - except: - city = "" - - if "gush" not in url: - name = set_title_by_feed(url)[1] - try: - name_temp = name.split(" ") - except: - name_temp = [name,"",""] - name_temp[2] = city+", " - name= " ".join(name_temp) - else: - name= 'תב"ע פתוחה '+city - + name = set_title_by_feed(url,city=city)[1] a_new_feed = Feed( user_id=session['user_id'], url=request.args.get('link', ''), name=name, - project='תב"ע פתוחה ' + city, - ) + project=get_project_by_feed_url(url), + ) db.session.add(a_new_feed) db.session.commit() flash(u'ההזנה החדשה נוספה למאגר') @@ -175,7 +163,6 @@ def add_feed_opentaba(): else: flash(u'את/ה כבר עוקבים אחרי מקור מידע זה') return redirect(url_for('notifier.feeds_editor')) - except (ValueError, KeyError, TypeError): errormsg = "type: " + str(sys.exc_info()[0]) + ", value: " + str(sys.exc_info()[1]) + ", traceback: " + str(sys.exc_info()[2]) return render_template('error.html', errormsg=errormsg)