Example #1
0
def feed_posts_xml(schannel):
    activity = []
    activity_item = ""
    count = 0
    limit = 40

    schannel = d2_channels.query.filter(
        d2_channels.short_name == schannel).first()
    posts = d2_activity.query.filter(d2_activity.replyto != 0).order_by(
        d2_activity.time.desc()).limit(limit).all()

    for post in posts:
        activity.append([post.time, "post", post.id])

    activity.sort(reverse=True)

    for item in activity:
        if count < limit:
            if item[1] == "post":
                post = d2_activity.query.filter(
                    d2_activity.id == item[2]).first()
                thread = d2_activity.query.filter(
                    d2_activity.id == post.replyto).first()
                channel = d2_channels.query.filter(
                    d2_channels.id == thread.category).first()

                if thread.category == schannel.id:
                    if post and thread and channel:
                        if post.anonymous == 0:
                            latestreplier = post.user.username
                        else:
                            latestreplier = 'Anonymous'

                        activity_item += '''<item>
                                                <guid>''' + str(
                            post.id) + '''</guid>
                                                <title>''' + latestreplier + ''' replied to "''' + html_escape(
                                thread.title) + '''" in ''' + html_escape(
                                    channel.name) + '''</title>
                                                <link>https://syn.d2k5.com/''' + str(
                                        channel.short_name) + '''/''' + str(
                                            thread.id) + '''#''' + str(
                                                post.id) + '''</link>
                                                <pubDate>''' + human_date(
                                                    post.time) + '''</pubDate>
                                            </item>'''
                    count += 1

    template = syndbb.render_template('post_feed.xml', posts=activity_item)
    response = make_response(template)
    response.headers['Content-Type'] = 'application/xml'
    return response
Example #2
0
def feed_threads_xml(schannel):
    activity = []
    activity_item = ""
    count = 0
    limit = 40

    schannel = d2_channels.query.filter(
        d2_channels.short_name == schannel).first()
    threads = d2_activity.query.filter(d2_activity.category != 0).filter(
        d2_activity.category == schannel.id).order_by(
            d2_activity.reply_time.desc()).limit(limit).all()

    for thread in threads:
        activity.append([thread.time, "thread", thread.id])

    activity.sort(reverse=True)

    for item in activity:
        if count < limit:
            if item[1] == "thread":
                thread = d2_activity.query.filter(
                    d2_activity.id == item[2]).first()
                channel = d2_channels.query.filter(
                    d2_channels.id == thread.category).first()

                if thread and channel:
                    if thread.anonymous == 0:
                        threadcreator = thread.user.username
                    else:
                        threadcreator = 'Anonymous'

                    activity_item += '''<item>
                                    		<guid>''' + str(thread.id) + '''</guid>
                                    		<title>''' + threadcreator + ''' created "''' + html_escape(
                        thread.title) + '''" in ''' + html_escape(
                            channel.name) + '''</title>
                                    		<link>https://syn.d2k5.com/''' + str(
                                channel.short_name) + '''/''' + str(
                                    thread.id) + '''</link>
                                    		<pubDate>''' + human_date(
                                        thread.time) + '''</pubDate>
                                    	</item>'''
            count += 1

    template = syndbb.render_template('thread_feed.xml', threads=activity_item)
    response = make_response(template)
    response.headers['Content-Type'] = 'application/xml'
    return response