Beispiel #1
0
def add_feed(id):
    property = Property.query.get(id)
    if property == None:
        flash('Property not found.')
        abort(404)
    form = AddFeedForm()
    if form.validate_on_submit():
        newFeed = Feed(xively_id=form.xively_id.data,api_key=form.api_key.data,property=property,info=form.info.data)
        db.session.add(newFeed)
        db.session.commit()
        xively_datastreams = get_datastreams(newFeed)
        if xively_datastreams != 'error':
            for i in range(0, len(xively_datastreams)):
                datastream_id = xively_datastreams[i]['id']
                j = 0
                datastream_tags = None
                while True:
                    try:
                        if datastream_tags == None:
                            datastream_tags = xively_datastreams[i]['tags'][j]
                        else:
                            datastream_tags += ', ' + xively_datastreams[i]['tags'][j]
                        j = j+1
                    except Exception, e:
                        break
                try:
                    datastream_unit = xively_datastreams[i]['unit']['label']
                except Exception, e:
                    datastream_unit = None
                newDatastream = Datastream(feed=newFeed,xively_id=datastream_id,unit=datastream_unit,info=datastream_tags)
                db.session.add(newDatastream)
            db.session.commit()
Beispiel #2
0
def feeds_editor():
    user_email = session['user_email']
    return render_template('feeds_editor.html', user_email=user_email,
        form=AddFeedForm(request.form),
        feeds=relevant_feeds(),
        parsed_feeds=parse_feeds(relevant_feeds()),
        days_no=relevant_days_for_feed
        )
Beispiel #3
0
def edit_feed(id):
    feed = Feed.query.get(id)
    if feed == None:
        flash('Feed not found.')
        abort(404)
    form = AddFeedForm() #edit form is equal to add form
    if form.validate_on_submit():
        feed.xively_id = form.xively_id.data
        feed.api_key = form.api_key.data
        feed.info = form.info.data
        db.session.add(feed)
        db.session.commit()
        flash('Your changes have been saved.')
        return redirect(url_for('feed', id = id))
    elif request.method != "POST":
        form.xively_id.data = feed.xively_id
        form.api_key.data = feed.api_key
        form.info.data = feed.info
    return render_template('edit_feed.html',
        feed = feed,
        form = form)
Beispiel #4
0
def root() -> str:
    """Root index/landing route. Landing page for the site. Currently the only page with content.

    :return: A string of the rendered page.
    """

    context: dict = {
        'add_feed_form': AddFeedForm(),
        'login_form': LoginForm(),
        'opml_upload_form': OpmlUploadForm()
    }
    output: str = render_template('root.html', **context)
    return output
Beispiel #5
0
def new_feed():
    error = None
    form = AddFeedForm(request.form)
    try:
        project = get_project_by_feed_url(url)

    except:
        project =''

    if request.method == 'POST':
        url = form.url.data
        name = " ".join(set_title_by_feed(url))
        if project==u'תב"ע פתוחה':
            return redirect(url_for('notifier.opentaba_feed', link= url))
        elif project==u'כיכר המדינה':
            return redirect(url_for('notifier.kikar_feed', link= url))

        elif form.validate_on_submit():
            a_new_feed = Feed(
                user_id=session['user_id'],
                name=name,
                url=url,
                project=project,
                )
            db.session.add(a_new_feed)
            db.session.commit()
            flash(u'ההזנה החדשה נוספה למאגר')
            return redirect(url_for('notifier.feeds_editor'))

    elif request.method == 'GET':
        if project == u'תב"ע פתוחה':
            return redirect(url_for('notifier.opentaba_feed',link=request.args.get('link')))
        elif project == u'כיכר המדינה':
            return redirect(url_for('notifier.kikar_feed',link=request.args.get('link'), type=request.args.get('type')))

    user_email = session['user_email']
    return redirect(url_for('notifier.feeds_editor'))
Beispiel #6
0
def add_feed() -> Response:
    """Add feed route. Takes a URL, tries to fetch it as a feed, then adding or updating a source for that feed as
    necessary.

    :return: A redirect to the landing page.
    """

    # build the redirect, regardless of the result, we're currently always redirecting to the landing
    url: str = url_for('root')
    output: Response = redirect(url)

    # validate form data
    form: AddFeedForm = AddFeedForm()
    if not form.validate_on_submit():
        flash('Invalid feed.', 'warning')
        return output

    url: str = form.url.data
    with db_session:
        user: UserModel = UserModel[current_user.user_id]
        fetch_and_store_feed(url, [], user)

    return output