Beispiel #1
0
    def callback(sxv):
        if sxv['votetypeid'] == "2":
            comment_id = comments[int(sxv['postcommentid'])]
            user_id = uidmap[sxv['userid']]

            if not (comment_id, user_id) in user2vote:
                user2vote.append((comment_id, user_id))

                action = orm.Action(
                        action_type = "voteupcomment",
                        user_id = user_id,
                        action_date = readTime(sxv['creationdate']),
                        node_id = comment_id
                        )
                action.save()

                ov = orm.Vote(
                        node_id = comment_id,
                        user_id = user_id,
                        voted_at = action.action_date,
                        value = 1,
                        action = action
                        )

                ov.save()

                if not comment_id in comments2score:
                    comments2score[comment_id] = 1
                else:
                    comments2score[comment_id] += 1
Beispiel #2
0
    def callback(sxa):
        badge = sx_to_osqa[int(sxa['badgeid'])]

        user_id = uidmap[sxa['userid']]
        if not user_badge_count.get(user_id, None):
            user_badge_count[user_id] = 0

        action = orm.Action(
                action_type = "award",
                user_id = user_id,
                action_date = readTime(sxa['date'])
                )

        action.save()

        osqaa = orm.Award(
                user_id = uidmap[sxa['userid']],
                badge = badge,
                node_id = post_list[user_badge_count[user_id]],
                awarded_at = action.action_date,
                action = action
                )

        osqaa.save()
        badge.awarded_count += 1
        user_badge_count[user_id] += 1
Beispiel #3
0
    def callback(sxc):
        currid.inc()
        oc = orm.Node(
                id = currid.value,
                node_type = "comment",
                added_at = readTime(sxc['creationdate']),
                author_id = uidmap[sxc.get('userid', 1)],
                body = sxc['text'],
                parent_id = sxc.get('postid'),
                )

        if sxc.get('deletiondate', None):
            delete_action = orm.Action(
                    action_type = "delete",
                    user_id = uidmap[sxc['deletionuserid']],
                    action_date = readTime(sxc['deletiondate'])
                    )

            oc.author_id = uidmap[sxc['deletionuserid']]
            oc.save()

            delete_action.node = oc
            delete_action.save()

            add_post_state("deleted", oc, delete_action)
        else:
            oc.author_id = uidmap[sxc.get('userid', 1)]
            oc.save()

        create_action = orm.Action(
                action_type = "comment",
                user_id = oc.author_id,
                node = oc,
                action_date = oc.added_at
                )

        create_action.save()
        oc.save()

        posts.append(int(oc.id))
        mapping[int(sxc['id'])] = int(oc.id)
Beispiel #4
0
    def callback(sxp):
        currid.inc()
        page = orm.Node(
                id = currid.value,
                node_type = "page",
                title = sxp['name'],
                body = b64decode(sxp['value']),
                extra = dbsafe_encode({
                'path': sxp['url'][1:],
                'mimetype': sxp['contenttype'],
                'template': (sxp['usemaster'] == "true") and "default" or "none",
                'render': "html",
                'sidebar': "",
                'sidebar_wrap': True,
                'sidebar_render': "html",
                'comments': False
                }),
                author_id = 1
                )

        page.save()
        registry[sxp['url'][1:]] = page.id

        create_action = orm.Action(
                action_type = "newpage",
                user_id = page.author_id,
                node = page
                )

        create_action.save()

        if sxp['active'] == "true" and sxp['contenttype'] == "text/html":
            pub_action = orm.Action(
                    action_type = "publish",
                    user_id = page.author_id,
                    node = page
                    )

            pub_action.save()
            add_post_state("published", page, pub_action)
Beispiel #5
0
def actions_import(row, nodes, users, actions_map):
    node = row.get('node').as_int(None)
    user = row.get('user').as_int()
    real_user = row.get('realUser').as_int(None)

    action = orm.Action(
        #id           = row.get('id').as_int(),
        action_type=row.getc('type'),
        action_date=row.get('date').as_datetime(),
        node_id=nodes.get(node, node),
        user_id=users.get(user, user),
        real_user_id=users.get(real_user, real_user),
        ip=row.getc('ip'),
        extra=row.get('extraData').as_pickled(),
    )

    canceled = row.get('canceled')
    if canceled.get_attr('state').as_bool():
        by = canceled.get('user').as_int()
        action.canceled = True
        action.canceled_by_id = users.get(by, by)
        action.canceled_at = canceled.getc('date') #.as_datetime(),
        action.canceled_ip = canceled.getc('ip')

    action.save()

    actions_map[row.get('id').as_int()] = action.id

    for r in row.get('reputes').get_list('repute'):
        by_canceled = r.get_attr('byCanceled').as_bool()

        orm.ActionRepute(
            action=action,
            user_id=users[r.get('user').as_int()],
            value=r.get('value').as_int(),

            date=by_canceled and action.canceled_at or action.action_date,
            by_canceled=by_canceled
        ).save()

    if (not action.canceled) and (action.action_type in POST_ACTION):
        POST_ACTION[action.action_type](row, action, users, nodes, actions_map)
Beispiel #6
0
    def callback(sxv):
        action = orm.Action(
                user_id=uidmap[sxv['userid']],
                action_date = readTime(sxv['creationdate']),
                )

        if not int(sxv['postid']) in posts: return
        node = orm.Node.objects.get(id=sxv['postid'])
        action.node = node

        if sxv['votetypeid'] == '1':
            answer = node
            question = orm.Node.objects.get(id=answer.parent_id)

            action.action_type = "acceptanswer"
            action.save()

            answer.marked = True

            question.extra_ref_id = answer.id

            answer.save()
            question.save()

        elif sxv['votetypeid'] in ('2', '3'):
            if not (action.node.id, action.user_id) in user2vote:
                user2vote.append((action.node.id, action.user_id))

                action.action_type = (sxv['votetypeid'] == '2') and "voteup" or "votedown"
                action.save()

                ov = orm.Vote(
                        node_id = action.node.id,
                        user_id = action.user_id,
                        voted_at = action.action_date,
                        value = sxv['votetypeid'] == '2' and 1 or -1,
                        action = action
                        )
                ov.save()
            else:
                action.action_type = "unknown"
                action.save()

        elif sxv['votetypeid'] in ('4', '12', '13'):
            action.action_type = "flag"
            action.save()

            of = orm.Flag(
                    node = action.node,
                    user_id = action.user_id,
                    flagged_at = action.action_date,
                    reason = '',
                    action = action
                    )

            of.save()

        elif sxv['votetypeid'] == '5':
            action.action_type = "favorite"
            action.save()

        elif sxv['votetypeid'] == '6':
            action.action_type = "close"
            action.extra = dbsafe_encode(close_reasons[sxv['comment']])
            action.save()

            node.marked = True
            node.save()

        elif sxv['votetypeid'] == '7':
            action.action_type = "unknown"
            action.save()

            node.marked = False
            node.save()

            remove_post_state("closed", node)

        elif sxv['votetypeid'] == '10':
            action.action_type = "delete"
            action.save()

        elif sxv['votetypeid'] == '11':
            action.action_type = "unknown"
            action.save()

            remove_post_state("deleted", node)

        else:
            action.action_type = "unknown"
            action.save()

        if sxv.get('targetrepchange', None):
            rep = orm.ActionRepute(
                    action = action,
                    date = action.action_date,
                    user_id = uidmap[sxv['targetuserid']],
                    value = int(sxv['targetrepchange'])
                    )

            rep.save()

        if sxv.get('voterrepchange', None):
            rep = orm.ActionRepute(
                    action = action,
                    date = action.action_date,
                    user_id = uidmap[sxv['userid']],
                    value = int(sxv['voterrepchange'])
                    )

            rep.save()

        if action.action_type in ("acceptanswer", "delete", "close"):
            state = {"acceptanswer": "accepted", "delete": "deleted", "close": "closed"}[action.action_type]
            add_post_state(state, node, action)
Beispiel #7
0
    def callback(sxpost):
        nodetype = (sxpost.get('posttypeid') == '1') and "nodetype" or "answer"

        post = orm.Node(
                node_type = nodetype,
                id = sxpost['id'],
                added_at = readTime(sxpost['creationdate']),
                body = sxpost['body'],
                score = sxpost.get('score', 0),
                author_id = sxpost.get('deletiondate', None) and 1 or uidmap[sxpost.get('owneruserid', 1)]
                )

        post.save()

        create_action = orm.Action(
                action_type = (nodetype == "nodetype") and "ask" or "answer",
                user_id = post.author_id,
                node = post,
                action_date = post.added_at
                )

        create_action.save()

        if sxpost.get('lasteditoruserid', None):
            revise_action = orm.Action(
                    action_type = "revise",
                    user_id = uidmap[sxpost.get('lasteditoruserid')],
                    node = post,
                    action_date = readTime(sxpost['lasteditdate']),
                    )

            revise_action.save()
            post.last_edited = revise_action

        if sxpost.get('communityowneddate', None):
            wikify_action = orm.Action(
                    action_type = "wikify",
                    user_id = 1,
                    node = post,
                    action_date = readTime(sxpost['communityowneddate'])
                    )

            wikify_action.save()
            add_post_state("wiki", post, wikify_action)

        if sxpost.get('lastactivityuserid', None):
            post.last_activity_by_id = uidmap[sxpost['lastactivityuserid']]
            post.last_activity_at = readTime(sxpost['lastactivitydate'])

        if sxpost.get('posttypeid') == '1': #question
            post.node_type = "question"
            post.title = sxpost['title']

            tagnames = sxpost['tags'].replace(u'ö', '-').replace(u'é', '').replace(u'à', '')
            post.tagnames = tagnames

            post.extra_count = sxpost.get('viewcount', 0)

            add_tags_to_post(post, tagmap)

        else:
            post.parent_id = sxpost['parentid']

        post.save()

        all.append(int(post.id))

        del post
Beispiel #8
0
    def callback(sxu):
        create = True

        if sxu.get('id') == '-1':
            return
        #print "\n".join(["%s : %s" % i for i in sxu.items()])
        if int(sxu.get('id')) == int(owneruid):
            osqau = orm.User.objects.get(id=1)
            for assoc in orm.AuthKeyUserAssociation.objects.filter(user=osqau):
                openids.add(assoc.key)
            uidmapper[owneruid] = 1
            uidmapper[-1] = 1
            create = False
        else:
            username = unicode(sxu.get('displayname',
                               sxu.get('displaynamecleaned', sxu.get('realname', final_username_attempt(sxu)))))[:30]

            if username in usernames:
            #if options.get('mergesimilar', False) and sxu.get('email', 'INVALID') == user_by_name[username].email:
            #    osqau = user_by_name[username]
            #    create = False
            #    uidmapper[sxu.get('id')] = osqau.id
            #else:
                inc = 0

                while True:
                    inc += 1
                    totest = "%s %d" % (username[:29 - len(str(inc))], inc)

                    if not totest in usernames:
                        username = totest
                        break          

        sxbadges = sxu.get('badgesummary', None)
        badges = {'1':'0', '2':'0', '3':'0'}

        if sxbadges:
            badges.update(dict([b.split('=') for b in sxbadges.split()]))

        if create:
            osqau = orm.User(
                    id           = sxu.get('id'),
                    username     = username,
                    password     = '******',
                    email        = sxu.get('email', ''),
                    is_superuser = sxu.get('usertypeid') == '5',
                    is_staff     = sxu.get('usertypeid') == '4',
                    is_active    = True,
                    date_joined  = readTime(sxu.get('creationdate')),
                    last_seen    = readTime(sxu.get('lastaccessdate')),
                    about         = sxu.get('aboutme', ''),
                    date_of_birth = sxu.get('birthday', None) and readTime(sxu['birthday']) or None,
                    email_isvalid = int(sxu.get('usertypeid')) > 2,
                    website       = sxu.get('websiteurl', ''),
                    reputation    = int(sxu.get('reputation')),
                    gold          = int(badges['1']),
                    silver        = int(badges['2']),
                    bronze        = int(badges['3']),
                    real_name     = sxu.get('realname', '')[:30],
                    location      = sxu.get('location', ''),
                    )

            osqau.save()

            user_joins = orm.Action(
                    action_type = "userjoins",
                    action_date = osqau.date_joined,
                    user = osqau
                    )
            user_joins.save()

            rep = orm.ActionRepute(
                    value = 1,
                    user = osqau,
                    date = osqau.date_joined,
                    action = user_joins
                    )
            rep.save()

            try:
                orm.SubscriptionSettings.objects.get(user=osqau)
            except:
                s = orm.SubscriptionSettings(user=osqau)
                s.save()

            uidmapper[osqau.id] = osqau.id
        else:
            new_about = sxu.get('aboutme', None)
            if new_about and osqau.about != new_about:
                if osqau.about:
                    osqau.about = "%s\n|\n%s" % (osqau.about, new_about)
                else:
                    osqau.about = new_about

            osqau.username = sxu.get('displayname',
                                     sxu.get('displaynamecleaned', sxu.get('realname', final_username_attempt(sxu))))
            osqau.email = sxu.get('email', '')
            osqau.reputation += int(sxu.get('reputation'))
            osqau.gold += int(badges['1'])
            osqau.silver += int(badges['2'])
            osqau.bronze += int(badges['3'])

            osqau.date_joined = readTime(sxu.get('creationdate'))
            osqau.website = sxu.get('websiteurl', '')
            osqau.date_of_birth = sxu.get('birthday', None) and readTime(sxu['birthday']) or None
            osqau.location = sxu.get('location', '')
            osqau.real_name = sxu.get('realname', '')

            #merged_users.append(osqau.id)
            osqau.save()

        usernames.append(osqau.username)

        openid = sxu.get('openid', None)
        if openid and openidre.match(openid) and (not openid in openids):
            assoc = orm.AuthKeyUserAssociation(user=osqau, key=openid, provider="openidurl")
            assoc.save()
            openids.add(openid)

        openidalt = sxu.get('openidalt', None)
        if openidalt and openidre.match(openidalt) and (not openidalt in openids):
            assoc = orm.AuthKeyUserAssociation(user=osqau, key=openidalt, provider="openidurl")
            assoc.save()
            openids.add(openidalt)