示例#1
0
文件: user.py 项目: guoku/Raspberry
def user_tag_list(request, user_id):
    _start_at = datetime.datetime.now()
    if request.method == "GET":
        _session = request.GET.get('session', None)
        if _session != None:
            _request_user_id = Session_Key.objects.get_user_id(_session)
        else:
            _request_user_id = None
        _user_context = MobileUser(user_id).read()
        _tag_list = Tag.user_tag_stat(user_id)
        _rslt = {'user': _user_context, 'tags': _tag_list}

        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration=_duration.seconds * 1000000 + _duration.microseconds,
            view='USER_TAG',
            request=request.REQUEST,
            ip=get_client_ip(request),
            log_time=datetime.datetime.now(),
            request_user_id=_request_user_id,
            appendix={
                'user_id': int(user_id),
                'result_tags': map(lambda x: x['tag'], _tag_list)
            },
        )
        return SuccessJsonResponse(_rslt)
示例#2
0
文件: user.py 项目: guoku/Raspberry
def user_tag_entity(request, user_id, tag):
    _start_at = datetime.datetime.now()
    if request.method == "GET":
        _session = request.GET.get('session', None)
        if _session != None:
            _request_user_id = Session_Key.objects.get_user_id(_session)
        else:
            _request_user_id = None

        _user_context = MobileUser(user_id).read(_request_user_id)
        _entity_id_list = Tag.find_user_tag_entity(user_id, tag)
        _rslt = {'user': _user_context, 'entity_list': []}
        for _entity_id in _entity_id_list:
            _rslt['entity_list'].append(
                MobileEntity(_entity_id).read(_request_user_id))

        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration=_duration.seconds * 1000000 + _duration.microseconds,
            view='USER_TAG_ENTITY',
            request=request.REQUEST,
            ip=get_client_ip(request),
            log_time=datetime.datetime.now(),
            request_user_id=_request_user_id,
            appendix={
                'user_id': int(user_id),
                'tag': tag
            },
        )
        return SuccessJsonResponse(_rslt)
示例#3
0
文件: user.py 项目: guoku/Raspberry
def user_detail(request, user_id):
    _start_at = datetime.datetime.now()
    if request.method == "GET":
        _session = request.GET.get('session', None)
        if _session != None:
            _request_user_id = Session_Key.objects.get_user_id(_session)
        else:
            _request_user_id = None

        _rslt = {}
        _rslt['user'] = MobileUser(user_id).read(_request_user_id)
        _last_note_id = MobileNote.get_user_last_note(user_id)
        if _last_note_id != None:
            _rslt['last_note'] = MobileNote(_last_note_id).read(
                _request_user_id)
        _last_like_entity_id = MobileEntity.get_user_last_like(user_id)
        if _last_like_entity_id != None:
            _rslt['last_like'] = MobileEntity(_last_like_entity_id).read(
                _request_user_id)

        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration=_duration.seconds * 1000000 + _duration.microseconds,
            view='USER',
            request=request.REQUEST,
            ip=get_client_ip(request),
            log_time=datetime.datetime.now(),
            request_user_id=_request_user_id,
            appendix={
                'user_id': int(user_id),
            },
        )
        return SuccessJsonResponse(_rslt)
示例#4
0
def __visit_jd_item(request, item_id):
    _start_at = datetime.datetime.now()
    if request.method == "GET":
        _session = request.GET.get('session', None)
        if _session != None:
            _request_user_id = Session_Key.objects.get_user_id(_session)
        else:
            _request_user_id = None
        _ttid = request.GET.get("ttid", None)
        _sid = request.GET.get("sid", None)
        _entry = request.GET.get("entry", "mobile")
        _outer_code = request.GET.get("outer_code", None)
        _sche = request.GET.get("sche", None)
        _item_context = JDItem(item_id).read()
        buy_link = get_jd_url(_item_context['jd_id'], is_mobile=True)
        _duration = datetime.datetime.now() - _start_at
        _entity_id = _item_context['entity_id'] if _item_context.has_key(
            'entity_id') else -1
        MobileLogTask.delay(entry=_entry,
                            duration=_duration.seconds * 1000000 +
                            _duration.microseconds,
                            view='CLICK',
                            request=request.REQUEST,
                            ip=get_client_ip(request),
                            log_time=datetime.datetime.now(),
                            request_user_id=_request_user_id,
                            appendix={
                                'site': 'jd',
                                'jd_id': _item_context['jd_id'],
                                'entity_id': _entity_id,
                                'tbk': False,
                            })
        return HttpResponseRedirect(decorate_jd_url(buy_link))
示例#5
0
def entity_note_detail(request, note_id):
    _start_at = datetime.datetime.now()
    if request.method == "GET":
        _session = request.GET.get('session', None)
        if _session != None:
            _request_user_id = Session_Key.objects.get_user_id(_session)
        else:
            _request_user_id = None
        
        _rslt = {}
        _rslt = MobileNote(note_id).read_note_full_context(_request_user_id)
        if _rslt['note'].has_key('entity_id'):
            _rslt['entity'] = MobileEntity(_rslt['note']['entity_id']).read(_request_user_id)
        
        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration = _duration.seconds * 1000000 + _duration.microseconds, 
            view = 'NOTE', 
            request = request.REQUEST, 
            ip = get_client_ip(request), 
            log_time = datetime.datetime.now(),
            request_user_id = _request_user_id,
            appendix = { 
                'note_id' : int(note_id), 
            },
        )
        return SuccessJsonResponse(_rslt)
示例#6
0
def guess_entity(request):
    _start_at = datetime.datetime.now()
    if request.method == "GET":
        _session = request.GET.get('session', None)
        if _session != None:
            _request_user_id = Session_Key.objects.get_user_id(_session)
        else:
            _request_user_id = None
        _category_id = request.GET.get('cid', None)
        _count = int(request.GET.get('count', '5'))
        if _category_id != None:
            _category_id = int(_category_id)
        _rslt = []
        _entity_id_list = []
        for _entity_id in MobileEntity.roll(category_id=_category_id,
                                            count=_count):
            _rslt.append(MobileEntity(_entity_id).read(_request_user_id))
            _entity_id_list.append(_entity_id)

        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration=_duration.seconds * 1000000 + _duration.microseconds,
            view='GUESS_ENTITY',
            request=request.REQUEST,
            ip=get_client_ip(request),
            log_time=datetime.datetime.now(),
            request_user_id=_request_user_id,
            appendix={
                'neo_category_id': int(_category_id),
                'result_entities': _entity_id_list
            },
        )

        return SuccessJsonResponse(_rslt)
示例#7
0
文件: user.py 项目: guoku/Raspberry
def user_following(request, user_id):
    _start_at = datetime.datetime.now()
    if request.method == "GET":
        _session = request.GET.get('session', None)
        if _session != None:
            _request_user_id = Session_Key.objects.get_user_id(_session)
        else:
            _request_user_id = None
        _offset = int(request.GET.get('offset', '0'))
        _count = int(request.GET.get('count', '30'))

        _rslt = []
        _following_user_id_list = MobileUser(
            user_id).read_following_user_id_list()
        for _following_user_id in _following_user_id_list[_offset:_offset +
                                                          _count]:
            _rslt.append(MobileUser(_following_user_id).read(_request_user_id))

        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration=_duration.seconds * 1000000 + _duration.microseconds,
            view='USER_FOLLOWING',
            request=request.REQUEST,
            ip=get_client_ip(request),
            log_time=datetime.datetime.now(),
            request_user_id=_request_user_id,
            appendix={
                'user_id': int(user_id),
                'result_users':
                _following_user_id_list[_offset:_offset + _count]
            },
        )
        return SuccessJsonResponse(_rslt)
示例#8
0
文件: user.py 项目: guoku/Raspberry
def search_user(request):
    _start_at = datetime.datetime.now()
    if request.method == "GET":
        _session = request.GET.get('session', None)
        if _session != None:
            _request_user_id = Session_Key.objects.get_user_id(_session)
        else:
            _request_user_id = None

        _query_string = request.GET.get('q')
        _offset = int(request.GET.get('offset', '0'))
        _count = int(request.GET.get('count', '30'))
        _user_id_list = MobileUser.search(query_string=_query_string,
                                          offset=_offset,
                                          count=_count)
        _rslt = []
        for _user_id in _user_id_list:
            _rslt.append(MobileUser(_user_id).read(_request_user_id))

        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration=_duration.seconds * 1000000 + _duration.microseconds,
            view='SEARCH_USER',
            request=request.REQUEST,
            ip=get_client_ip(request),
            log_time=datetime.datetime.now(),
            request_user_id=_request_user_id,
            appendix={
                'query': _query_string,
                'result_users': _user_id_list
            },
        )
        return SuccessJsonResponse(_rslt)
示例#9
0
def feed(request):
    _start_at = datetime.datetime.now()
    if request.method == "GET":
        _session = request.GET.get('session', None)
        _type = request.GET.get('type', 'entity')
        _scale = request.GET.get('scale', 'all')
        if _session != None:
            _request_user_id = Session_Key.objects.get_user_id(_session)
        else:
            _request_user_id = None
        _timestamp = request.GET.get('timestamp', None)
        if _timestamp != None:
            _timestamp = datetime.datetime.fromtimestamp(float(_timestamp))
        _offset = int(request.GET.get('offset', '0'))
        _count = int(request.GET.get('count', '30'))

        if _scale == 'friend':
            _following_user_id_list = MobileUser(
                _request_user_id).read_following_user_id_list()
            _log_appendix = {'scale': 'FRIEND'}
            #MobileUser(_request_user_id).mark_footprint(friend_feed = True)
        else:
            _following_user_id_list = MobileUser.read_seed_users()
            _log_appendix = {'scale': 'SOCIAL'}
            #MobileUser(_request_user_id).mark_footprint(social_feed = True)

        _note_id_list = MobileNote.find(timestamp=_timestamp,
                                        creator_set=_following_user_id_list,
                                        offset=_offset,
                                        count=_count)
        _log_appendix['result_notes'] = _note_id_list

        _rslt = []
        for _note_id in _note_id_list:
            try:
                _note_context = MobileNote(_note_id).read(_request_user_id)
                if _note_context.has_key('entity_id'):
                    _entity = MobileEntity(_note_context['entity_id'])
                    _rslt.append({
                        'type': 'entity',
                        'content': {
                            'entity': _entity.read(_request_user_id),
                            'note': _note_context
                        }
                    })
            except Exception, e:
                pass

        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(duration=_duration.seconds * 1000000 +
                            _duration.microseconds,
                            view='FEED',
                            request=request.REQUEST,
                            ip=get_client_ip(request),
                            log_time=datetime.datetime.now(),
                            request_user_id=_request_user_id,
                            appendix=_log_appendix)

        return SuccessJsonResponse(_rslt)
示例#10
0
def entity_list(request):
    _start_at = datetime.datetime.now()
    if request.method == "GET":
        _session = request.GET.get('session', None)
        if _session != None:
            _request_user_id = Session_Key.objects.get_user_id(_session)
        else:
            _request_user_id = None
        _timestamp = request.GET.get('timestamp', None)
        if _timestamp != None:
            _timestamp = datetime.datetime.fromtimestamp(float(_timestamp))

        _sort_by = request.GET.get('sort', 'novus_time')
        _reverse = request.GET.get('reverse', '0')
        if _reverse == '0':
            _reverse = False
        else:
            _reverse = True
        _offset = int(request.GET.get('offset', '0'))
        _count = int(request.GET.get('count', '30'))
        _root_old_cat_id = request.GET.get('rcat', None)
        if _root_old_cat_id != None:
            _root_old_cat_id = int(_root_old_cat_id)

        _entity_id_list = MobileEntity.find(
            root_old_category_id=_root_old_cat_id,
            timestamp=_timestamp,
            offset=_offset,
            count=_count,
            sort_by=_sort_by,
            reverse=_reverse,
            status='novus')

        _rslt = []
        for _entity_id in _entity_id_list:
            try:
                _entity = MobileEntity(_entity_id)
                _entity_context = _entity.read(_request_user_id)
                _entity_context['updated_time'] = _entity_context['novus_time']
                _rslt.append(_entity_context)
            except Exception, e:
                pass

        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration=_duration.seconds * 1000000 + _duration.microseconds,
            view='NOVUS',
            request=request.REQUEST,
            ip=get_client_ip(request),
            log_time=datetime.datetime.now(),
            request_user_id=_request_user_id,
            appendix={'result_entities': _entity_id_list},
        )

        return SuccessJsonResponse(_rslt)
示例#11
0
def selection(request):
    _start_at = datetime.datetime.now()
    if request.method == "GET":
        _session = request.GET.get('session', None)
        if _session != None:
            _request_user_id = Session_Key.objects.get_user_id(_session)
        else:
            _request_user_id = None
        _timestamp = request.GET.get('timestamp', None)
        if _timestamp != None:
            _timestamp = datetime.datetime.fromtimestamp(float(_timestamp))
        else:
            _timestamp = datetime.datetime.now()
        _count = int(request.GET.get('count', '30'))
        _root_cat_id = int(request.GET.get('rcat', '0'))

        _hdl = NoteSelection.objects.filter(post_time__lt=_timestamp)
        if _root_cat_id > 0 and _root_cat_id < 12:
            _hdl = _hdl.filter(root_category_id=_root_cat_id)

        _rslt = []
        _entity_id_list = []
        for _selection in _hdl.order_by('-post_time')[0:30]:
            if isinstance(_selection, NoteSelection):
                _context = {
                    'type': 'note_selection',
                    'post_time': time.mktime(_selection.post_time.timetuple()),
                    'content': {
                        'entity':
                        MobileEntity(
                            _selection.entity_id).read(_request_user_id),
                        'note':
                        MobileNote(_selection.note_id).read(_request_user_id),
                    }
                }
                _rslt.append(_context)
                _entity_id_list.append(_selection.entity_id)

        if _request_user_id != None:
            MarkFootprint.delay(user_id=_request_user_id, selection=True)

        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration=_duration.seconds * 1000000 + _duration.microseconds,
            view='SELECTION',
            request=request.REQUEST,
            ip=get_client_ip(request),
            log_time=datetime.datetime.now(),
            request_user_id=_request_user_id,
            appendix={
                'root_category_id': int(_root_cat_id),
                'result_entities': _entity_id_list,
            },
        )
        return SuccessJsonResponse(_rslt)
示例#12
0
def popular(request):
    _start_at = datetime.datetime.now()
    if request.method == "GET":
        _session = request.GET.get('session', None)
        if _session != None:
            _request_user_id = Session_Key.objects.get_user_id(_session)
        else:
            _request_user_id = None
        _scale = request.GET.get('scale', 'daily')

        _popular_entities = popularity.read_popular_entity_from_cache(
            scale=_scale, json=True)
        if _popular_entities != None:
            _rslt = {
                'scale': _scale,
                'updated_time': _popular_entities['updated_time'],
                'content': []
            }
            _entity_id_list = []
            for _row in _popular_entities['data'][0:60]:
                _entity_id = _row[0]
                _hotness = _row[1]
                _entity_context = MobileEntity(_entity_id).read(
                    _request_user_id)
                _rslt['content'].append({
                    'entity': _entity_context,
                    'hotness': _hotness
                })
                _entity_id_list.append(_entity_id)

            if _scale == 'weekly':
                _log_appendix = {'scale': 'WEEK'}
            else:
                _log_appendix = {'scale': 'DAY'}
            _log_appendix['result_entities'] = _entity_id_list

            _duration = datetime.datetime.now() - _start_at
            MobileLogTask.delay(duration=_duration.seconds * 1000000 +
                                _duration.microseconds,
                                view='POPULAR',
                                request=request.REQUEST,
                                ip=get_client_ip(request),
                                log_time=datetime.datetime.now(),
                                request_user_id=_request_user_id,
                                appendix=_log_appendix)
            return SuccessJsonResponse(_rslt)
        else:
            return ErrorJsonResponse(data={
                'type': 'no_popular_data',
                'message': 'no popular data'
            },
                                     status=400)
示例#13
0
def search_entity(request):
    _start_at = datetime.datetime.now()
    if request.method == "GET":
        _session = request.GET.get('session', None)
        _type = request.GET.get('type', None)
        if _session != None:
            _request_user_id = Session_Key.objects.get_user_id(_session)
        else:
            _request_user_id = None

        _query_string = request.GET.get('q')
        _offset = int(request.GET.get('offset', '0'))
        _count = int(request.GET.get('count', '30'))

        _entity_id_list = MobileEntity.search(query_string=_query_string, )
        _rslt = {
            'stat': {
                'all_count': len(_entity_id_list),
                'like_count': 0,
            },
            'entity_list': []
        }

        if _request_user_id != None:
            _like_set = MobileEntity.like_set_of_user(_request_user_id)
            _like_entity_id_list = _like_set.intersection(_entity_id_list)
            _rslt['stat']['like_count'] = len(_like_entity_id_list)
            if _type == 'like':
                _entity_id_list = list(_like_entity_id_list)

        for _entity_id in _entity_id_list[_offset:_offset + _count]:
            _entity = MobileEntity(_entity_id)
            _rslt['entity_list'].append(_entity.read(_request_user_id))

        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration=_duration.seconds * 1000000 + _duration.microseconds,
            view='SEARCH_ENTITY',
            request=request.REQUEST,
            ip=get_client_ip(request),
            log_time=datetime.datetime.now(),
            request_user_id=_request_user_id,
            appendix={
                'query': _query_string,
                'result_entities': _entity_id_list[_offset:_offset + _count],
            },
        )

        return SuccessJsonResponse(_rslt)
示例#14
0
文件: user.py 项目: guoku/Raspberry
def user_entity_note(request, user_id):
    _start_at = datetime.datetime.now()
    if request.method == "GET":
        _session = request.GET.get('session', None)
        if _session != None:
            _request_user_id = Session_Key.objects.get_user_id(_session)
        else:
            _request_user_id = None
        _timestamp = request.GET.get('timestamp', None)
        if _timestamp != None:
            _timestamp = datetime.datetime.fromtimestamp(float(_timestamp))
        _offset = int(request.GET.get('offset', '0'))
        _count = int(request.GET.get('count', '30'))

        _rslt = []
        _note_id_list = MobileNote.find(creator_set=[user_id],
                                        timestamp=_timestamp,
                                        offset=_offset,
                                        count=_count)
        for _note_id in _note_id_list:
            try:
                _note_context = MobileNote(_note_id).read(_request_user_id)
                if _note_context.has_key('entity_id'):
                    _entity = MobileEntity(_note_context['entity_id'])
                    _rslt.append({
                        'entity': _entity.read(_request_user_id),
                        'note': _note_context,
                    })
            except:
                pass

        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration=_duration.seconds * 1000000 + _duration.microseconds,
            view='USER_NOTE',
            request=request.REQUEST,
            ip=get_client_ip(request),
            log_time=datetime.datetime.now(),
            request_user_id=_request_user_id,
            appendix={
                'user_id': int(user_id),
                'result_notes': _note_id_list
            },
        )
        return SuccessJsonResponse(_rslt)
示例#15
0
文件: user.py 项目: guoku/Raspberry
def user_like(request, user_id):
    _start_at = datetime.datetime.now()
    if request.method == "GET":
        _session = request.GET.get('session', None)
        if _session != None:
            _request_user_id = Session_Key.objects.get_user_id(_session)
        else:
            _request_user_id = None
        _timestamp = request.GET.get('timestamp', None)
        if _timestamp != None:
            _timestamp = datetime.datetime.fromtimestamp(float(_timestamp))
        _offset = int(request.GET.get('offset', '0'))
        _count = int(request.GET.get('count', '30'))

        _list = []
        _last_like_time = None
        _entity_id_list = []
        for _item in MobileUser(user_id).find_like_entity(timestamp=_timestamp,
                                                          offset=_offset,
                                                          count=_count,
                                                          with_timestamp=True):
            _list.append(MobileEntity(_item[0]).read(_request_user_id))
            _entity_id_list.append(_item[0])
            _last_like_time = _item[1]

        if _last_like_time == None:
            _timestamp = 0.0
        else:
            _timestamp = time.mktime(_last_like_time.timetuple())
        _rslt = {'timestamp': _timestamp, 'entity_list': _list}

        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration=_duration.seconds * 1000000 + _duration.microseconds,
            view='USER_LIKE',
            request=request.REQUEST,
            ip=get_client_ip(request),
            log_time=datetime.datetime.now(),
            request_user_id=_request_user_id,
            appendix={
                'user_id': int(user_id),
                'result_entities': _entity_id_list
            },
        )
        return SuccessJsonResponse(_rslt)
示例#16
0
def category_entity_note(request, category_id):
    _start_at = datetime.datetime.now()
    if request.method == "GET":
        _session = request.GET.get('session', None)
        if _session != None:
            _request_user_id = Session_Key.objects.get_user_id(_session)
        else:
            _request_user_id = None
        _sort_by = request.GET.get('sort', 'poke')
        if _sort_by == '':
            _sort_by = 'poke'
        _offset = int(request.GET.get('offset', '0'))
        _count = int(request.GET.get('count', '30'))
        
        _note_id_list = MobileNote.find(
            category_id = category_id,
            offset = _offset,
            count = _count,
            sort_by = _sort_by
        )
        _rslt = []
        for _note_id in _note_id_list:
            _note_context = MobileNote(_note_id).read(_request_user_id)
            if _note_context.has_key('entity_id'):
                _entity = MobileEntity(_note_context['entity_id'])
                _rslt.append({
                    'entity' : _entity.read(_request_user_id),
                    'note' : _note_context,
                })
            
        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration = _duration.seconds * 1000000 + _duration.microseconds, 
            view = 'CATEGORY_NOTE_LIST', 
            request = request.REQUEST, 
            ip = get_client_ip(request), 
            log_time = datetime.datetime.now(),
            request_user_id = _request_user_id,
            appendix = { 
                'neo_category_id' : int(category_id),
                'result_notes' : _note_id_list
            },
        )
        return SuccessJsonResponse(_rslt)
示例#17
0
文件: user.py 项目: guoku/Raspberry
def category_user_like(request, category_id, user_id):
    _start_at = datetime.datetime.now()
    if request.method == "GET":
        _session = request.GET.get('session', None)
        if _session != None:
            _request_user_id = Session_Key.objects.get_user_id(_session)
        else:
            _request_user_id = None

        _offset = int(request.GET.get('offset', '0'))
        _count = int(request.GET.get('count', '30'))
        _sort_by = request.GET.get('sort', 'new')
        _reverse = request.GET.get('reverse', '0')
        if _reverse == '0':
            _reverse = False
        else:
            _reverse = True

        _entity_id_list = MobileUser(user_id).find_like_entity(
            neo_category_id=category_id,
            offset=_offset,
            count=_count,
            sort_by=_sort_by,
            reverse=_reverse)
        _rslt = []
        for _entity_id in _entity_id_list:
            _entity = MobileEntity(_entity_id)
            _rslt.append(_entity.read(_request_user_id))

        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration=_duration.seconds * 1000000 + _duration.microseconds,
            view='CATEGORY_USER_LIKE',
            request=request.REQUEST,
            ip=get_client_ip(request),
            log_time=datetime.datetime.now(),
            request_user_id=_request_user_id,
            appendix={
                'neo_category_id': int(category_id),
                'user_id': int(user_id),
                'result_entities': _entity_id_list
            },
        )
        return SuccessJsonResponse(_rslt)
示例#18
0
def entity_detail(request, entity_id):
    _start_at = datetime.datetime.now()
    print 'detail'
    if request.method == "GET":
        _session = request.GET.get('session', None)
        if _session != None:
            _request_user_id = Session_Key.objects.get_user_id(_session)
        else:
            _request_user_id = None

        _rslt = MobileEntity(entity_id).read_full_context(_request_user_id)

        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration=_duration.seconds * 1000000 + _duration.microseconds,
            view='ENTITY',
            request=request.REQUEST,
            ip=get_client_ip(request),
            log_time=datetime.datetime.now(),
            request_user_id=_request_user_id,
            appendix={'entity_id': int(entity_id)},
        )

        return SuccessJsonResponse(_rslt)
示例#19
0
def old_visit_item(request):
    _start_at = datetime.datetime.now()

    if request.method == "GET":
        _session = request.GET.get('session', None)
        if _session != None:
            _request_user_id = Session_Key.objects.get_user_id(_session)
        else:
            _request_user_id = None
        _ttid = request.GET.get("ttid", None)
        _sid = request.GET.get("sid", None)
        _entry = request.GET.get("entry", "mobile")
        _outer_code = request.GET.get("outer_code", None)
        _sche = request.GET.get("sche", None)

        _taobao_id = request.GET.get("item_id", None)
        _item = Item.get_item_by_taobao_id(_taobao_id)
        _item_context = _item.read()

        if _taobao_id == '38232357603':
            _duration = datetime.datetime.now() - _start_at
            MobileLogTask.delay(entry="jd_bilang",
                                duration=_duration.seconds * 1000000 +
                                _duration.microseconds,
                                view='CLICK',
                                request=request.REQUEST,
                                ip=get_client_ip(request),
                                log_time=datetime.datetime.now(),
                                request_user_id=_request_user_id,
                                appendix={})
            return HttpResponseRedirect("http://item.jd.com/1076756.html")

        _taobaoke_info = taobaoke_mobile_item_convert(
            _item_context['taobao_id'])
        _entity_id = _item_context['entity_id'] if _item_context.has_key(
            'entity_id') else -1
        _duration = datetime.datetime.now() - _start_at

        if _taobaoke_info and _taobaoke_info.has_key('click_url'):
            MobileLogTask.delay(entry=_entry,
                                duration=_duration.seconds * 1000000 +
                                _duration.microseconds,
                                view='CLICK',
                                request=request.REQUEST,
                                ip=get_client_ip(request),
                                log_time=datetime.datetime.now(),
                                request_user_id=_request_user_id,
                                appendix={
                                    'site': 'taobao',
                                    'taobao_id': _item_context['taobao_id'],
                                    'item_id': _item_context['item_id'],
                                    'entity_id': _entity_id,
                                    'tbk': True,
                                })
            return HttpResponseRedirect(
                decorate_taobao_url(_taobaoke_info['click_url'], _ttid, _sid,
                                    _outer_code, _sche))

        MobileLogTask.delay(entry=_entry,
                            duration=_duration.seconds * 1000000 +
                            _duration.microseconds,
                            view='CLICK',
                            request=request.REQUEST,
                            ip=get_client_ip(request),
                            log_time=datetime.datetime.now(),
                            request_user_id=_request_user_id,
                            appendix={
                                'site': 'taobao',
                                'taobao_id': _item_context['taobao_id'],
                                'item_id': _item_context['item_id'],
                                'entity_id': _entity_id,
                                'tbk': False,
                            })
        return HttpResponseRedirect(
            decorate_taobao_url(
                get_taobao_url(_item_context['taobao_id'], True), _ttid, _sid,
                _outer_code, _sche))
示例#20
0
def message(request):
    _start_at = datetime.datetime.now()
    if request.method == "GET":
        _session = request.GET.get('session', None)
        if _session != None:
            _request_user_id = Session_Key.objects.get_user_id(_session)
        _timestamp = request.GET.get('timestamp', None)
        if _timestamp != None:
            _timestamp = datetime.datetime.fromtimestamp(float(_timestamp))
        else:
            _timestamp = datetime.datetime.now()
        _count = int(request.GET.get('count', '30'))

        _rslt = []
        for _message in NeoMessage.objects.filter(
                user_id=_request_user_id,
                created_time__lt=_timestamp).order_by(
                    '-created_time')[0:_count]:
            try:
                if isinstance(_message, UserFollowMessage):
                    _context = {
                        'type':
                        'user_follow',
                        'created_time':
                        time.mktime(_message.created_time.timetuple()),
                        'content': {
                            'follower':
                            MobileUser(
                                _message.follower_id).read(_request_user_id)
                        }
                    }
                    _rslt.append(_context)
                elif isinstance(_message, NotePokeMessage):
                    _context = {
                        'type':
                        'note_poke_message',
                        'created_time':
                        time.mktime(_message.created_time.timetuple()),
                        'content': {
                            'note':
                            MobileNote(
                                _message.note_id).read(_request_user_id),
                            'poker':
                            MobileUser(
                                _message.poker_id).read(_request_user_id)
                        }
                    }
                    _rslt.append(_context)
                elif isinstance(_message, NoteCommentMessage):
                    _context = {
                        'type':
                        'note_comment_message',
                        'created_time':
                        time.mktime(_message.created_time.timetuple()),
                        'content': {
                            'note':
                            MobileNote(
                                _message.note_id).read(_request_user_id),
                            'comment':
                            MobileNote(_message.note_id).read_comment(
                                _message.comment_id),
                            'comment_user':
                            MobileUser(_message.comment_creator_id).read(
                                _request_user_id)
                        }
                    }
                    _rslt.append(_context)
                elif isinstance(_message, NoteCommentReplyMessage):
                    _context = {
                        'type':
                        'note_comment_reply_message',
                        'created_time':
                        time.mktime(_message.created_time.timetuple()),
                        'content': {
                            'note':
                            MobileNote(
                                _message.note_id).read(_request_user_id),
                            'comment':
                            MobileNote(_message.note_id).read_comment(
                                _message.comment_id),
                            'replying_comment':
                            MobileNote(_message.note_id).read_comment(
                                _message.replying_comment_id),
                            'replying_user':
                            MobileUser(_message.replying_user_id).read(
                                _request_user_id)
                        }
                    }
                    _rslt.append(_context)
                elif isinstance(_message, EntityLikeMessage):
                    _context = {
                        'type':
                        'entity_like_message',
                        'created_time':
                        time.mktime(_message.created_time.timetuple()),
                        'content': {
                            'liker':
                            MobileUser(
                                _message.liker_id).read(_request_user_id),
                            'entity':
                            MobileEntity(
                                _message.entity_id).read(_request_user_id)
                        }
                    }
                    _rslt.append(_context)
                elif isinstance(_message, EntityNoteMessage):
                    _context = {
                        'type':
                        'entity_note_message',
                        'created_time':
                        time.mktime(_message.created_time.timetuple()),
                        'content': {
                            'note':
                            MobileNote(
                                _message.note_id).read(_request_user_id),
                            'entity':
                            MobileEntity(
                                _message.entity_id).read(_request_user_id)
                        }
                    }
                    _rslt.append(_context)
                elif isinstance(_message, NoteSelectionMessage):
                    _context = {
                        'type':
                        'note_selection_message',
                        'created_time':
                        time.mktime(_message.created_time.timetuple()),
                        'content': {
                            'note':
                            MobileNote(
                                _message.note_id).read(_request_user_id),
                            'entity':
                            MobileEntity(
                                _message.entity_id).read(_request_user_id)
                        }
                    }
                    _rslt.append(_context)
            except:
                # TODO : logger
                pass

        if _request_user_id != None:
            MarkFootprint.delay(user_id=_request_user_id, message=True)

        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration=_duration.seconds * 1000000 + _duration.microseconds,
            view='MESSAGE',
            request=request.REQUEST,
            ip=get_client_ip(request),
            log_time=datetime.datetime.now(),
            request_user_id=_request_user_id,
        )
        return SuccessJsonResponse(_rslt)
示例#21
0
    _rslt['config'] = {}
    _rslt['config']['taobao_ban_count'] = 2
    _rslt['config']['url_ban_list'] = [
        'http://m.taobao.com/go/act/mobile/cloud-jump.html'
    ]

    #    if settings.JUMP_TO_TAOBAO:
    #        _rslt['config']['jump_to_taobao'] = 1
    #    else:
    #        _rslt['config']['jump_to_taobao'] = 0

    _duration = datetime.datetime.now() - _start_at
    MobileLogTask.delay(duration=_duration.seconds * 1000000 +
                        _duration.microseconds,
                        view='HOMEPAGE',
                        request=request.REQUEST,
                        ip=get_client_ip(request),
                        log_time=datetime.datetime.now(),
                        request_user_id=_request_user_id,
                        appendix=_log_appendix)
    return SuccessJsonResponse(_rslt)


@check_sign
def feed(request):
    _start_at = datetime.datetime.now()
    if request.method == "GET":
        _session = request.GET.get('session', None)
        _type = request.GET.get('type', 'entity')
        _scale = request.GET.get('scale', 'all')
        if _session != None:
            _request_user_id = Session_Key.objects.get_user_id(_session)