Beispiel #1
0
def userMain():

    # todo ensure twurlie is topic if none
    data = {}

    # get user
    app.logger.info('formdata {}'.format(request.form))
    user_key = request.form.get('user_key')
    user = User.fetchByKey(user_key)
    if not user:
        abort(403)

    # get last userlink per topic
    for topic in user.topics:
        userLink = UserLink.findLastByUser(topic, user)
        if userLink:
            data[topic] = {
                'key': userLink.key.urlsafe(),
                'link_id': userLink.link_id,
                'tweeted_count': userLink.tweeted_count,
                'priority': userLink.priority,
                'read_at': hasattr(userLink, 'read_at') and userLink.read_at
            }
        else:
            data[topic] = None

    return data
Beispiel #2
0
def userMain():

    # todo ensure twurlie is topic if none
    data = {}

    # get user
    app.logger.info('formdata {}'.format(request.form))
    user_key = request.form.get('user_key')
    user = User.fetchByKey(user_key)
    if not user:
        abort(403)

    # get last userlink per topic
    for topic in user.topics:
        userLink = UserLink.findLastByUser(topic, user)
        if userLink:
            data[topic] = {
                'key': userLink.key.urlsafe(),
                'link_id': userLink.link_id,
                'tweeted_count': userLink.tweeted_count,
                'priority': userLink.priority,
                'read_at': hasattr(userLink, 'read_at') and userLink.read_at
            }
        else:
            data[topic] = None

    return data
Beispiel #3
0
def userRead():

    # get user
    app.logger.info('formdata {}'.format(request.form))
    user_key = request.form.get('user_key')
    user = User.fetchByKey(user_key)
    if not user:
        abort(403)

    # mark last link
    topic = request.form.get('topic')
    userLink = UserLink.readLastByUser(topic, user)

    return userLink.read_at
Beispiel #4
0
def userRead():

    # get user
    app.logger.info('formdata {}'.format(request.form))
    user_key = request.form.get('user_key')
    user = User.fetchByKey(user_key)
    if not user:
        abort(403)

    # mark last link
    topic = request.form.get('topic')
    userLink = UserLink.readLastByUser(topic, user)

    return userLink.read_at
Beispiel #5
0
def scheduleLink():
    if request.method == 'POST':
        app.logger.info('request form: {}'.format(request.form))
        topic = request.form.get('topic')
    elif request.method == 'GET':
        app.logger.info('request args: {}'.format(request.args))
        topic = request.args.get('topic')
    if not topic:
        abort(400)
    app.logger.info('Topic param received: {}'.format(topic))

    # get users by topic
    users = User.fetchByTopic(topic)

    # get ordered links by topic
    # two inequality filters not supported
    week_ago = datetime.datetime.utcnow() - datetime.timedelta(days=7)
    links = Link.fetchByTopic(topic)

    spamLinks = []
    info = {}
    # for every user
    for user in users:
        info[user.email] = None

        # get last userlink:
        # if not read => skip
        # if too soon => skip
        lastUserLink = UserLink.findLastByUser(topic, user)
        if lastUserLink and not hasattr(lastUserLink, 'read'):
            app.logger.info('User has unread UserLink')
            continue

        # then loop through ordered links
        for link in links:
            # skip links that has been spammed
            # ignore links created before a week ago
            # these links will go away since updated_at will keep renewing
            if link.created_at < week_ago:
                app.logger.debug('Skipping spam link: {}'.format(link.id))
                spamLinks.append(link.id)
                continue

            # and assign first non-userlink to user
            # note: search without topic:
            # this gives unique link for a list of similar topics
            if not UserLink.findByUserAndLink(user, link):
                # assign new userlink to user for the topic
                UserLink.create(topic, user, link)
                info[user.email] = link.id
                break

    body = '\n'.join(['User {} got link {}'.format(userEmail, linkId) for userEmail, linkId in info.iteritems()])
    body += '\n'.join(spamLinks)
    mail.send_mail(
        sender='*****@*****.**',
        to='*****@*****.**',
        subject='Schedule Link {}'.format(topic),
        body=body,
    )

    app.logger.info('{} users got links'.format(len(info)))
    return Response('OK')
Beispiel #6
0
def scheduleLink():
    if request.method == 'POST':
        app.logger.info('request form: {}'.format(request.form))
        topic = request.form.get('topic')
    elif request.method == 'GET':
        app.logger.info('request args: {}'.format(request.args))
        topic = request.args.get('topic')
    if not topic:
        abort(400)
    app.logger.info('Topic param received: {}'.format(topic))

    # get users by topic
    users = User.fetchByTopic(topic)

    # get ordered links by topic
    # two inequality filters not supported
    week_ago = datetime.datetime.utcnow() - datetime.timedelta(days=7)
    links = Link.fetchByTopic(topic)

    spamLinks = []
    info = {}
    # for every user
    for user in users:
        info[user.email] = None

        # get last userlink:
        # if not read => skip
        # if too soon => skip
        lastUserLink = UserLink.findLastByUser(topic, user)
        if lastUserLink and not hasattr(lastUserLink, 'read'):
            app.logger.info('User has unread UserLink')
            continue

        # then loop through ordered links
        for link in links:
            # skip links that has been spammed
            # ignore links created before a week ago
            # these links will go away since updated_at will keep renewing
            if link.created_at < week_ago:
                app.logger.debug('Skipping spam link: {}'.format(link.id))
                spamLinks.append(link.id)
                continue

            # and assign first non-userlink to user
            # note: search without topic:
            # this gives unique link for a list of similar topics
            if not UserLink.findByUserAndLink(user, link):
                # assign new userlink to user for the topic
                UserLink.create(topic, user, link)
                info[user.email] = link.id
                break

    body = '\n'.join([
        'User {} got link {}'.format(userEmail, linkId)
        for userEmail, linkId in info.iteritems()
    ])
    body += '\n'.join(spamLinks)
    mail.send_mail(
        sender='*****@*****.**',
        to='*****@*****.**',
        subject='Schedule Link {}'.format(topic),
        body=body,
    )

    app.logger.info('{} users got links'.format(len(info)))
    return Response('OK')