コード例 #1
0
def roll(request):
    _token = request.GET.get('token', None)
    _session = request.GET.get('session', None)
    _player = Player.objects.get(token=_token)
    _code = 0
    
    if not _is_the_same_date(_player.last_share_time, datetime.datetime.now()):
        return HttpResponseRedirect(reverse('lotto_share_to_sina_weibo') + '?session=' + _session + '&token=' + _token)
    
    if _player.share_count <= _player.roll_count:
        return SuccessJsonResponse({ 'code': 4 })

    try:
        _acc_obj = Accumulate.objects.get(key=CURRENT_KEY)
    except Accumulate.DoesNotExist:
        _acc_obj = Accumulate.objects.create(
            key=CURRENT_KEY,
            count=0
        )
    
    _acc_obj.count += 1
    if _acc_obj.count % 29 == 0:
        if Reward.objects.filter(level=1).count() < 28:
            _code = 1
            Reward.objects.create(
                player_id=_player.id,
                level=1
            )
    elif _acc_obj.count % 17  == 0:
        if Reward.objects.filter(level=2).count() < 50:
            _code = 2
            Reward.objects.create(
                player_id=_player.id,
                level=2
            )
    elif _acc_obj.count % 23 == 0:
        if Reward.objects.filter(level=3).count() < 28:
            _code = 3
            Reward.objects.create(
                player_id=_player.id,
                level=3
            )
        
    _acc_obj.save()
    _player.roll_count += 1
    _player.save()

    _left_roll_count = _player.share_count - _player.roll_count
    
    return SuccessJsonResponse({ 
        'code' :  _code,
        'leftrollcount' : str(_left_roll_count) 
    })
コード例 #2
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)
コード例 #3
0
ファイル: sync.py プロジェクト: guoku/Raspberry
def sync_update_entity_title(request, entity_id):
    if request.method == 'POST':
        _brand = request.POST.get("brand", None)
        _title = request.POST.get("title", None)

        _entity = Entity(entity_id)
        _entity.update(brand=_brand, title=_title)
        _rslt = {'status': 'success'}
        return SuccessJsonResponse(_rslt)
コード例 #4
0
def unread_count(request):
    if request.method == "GET":
        _session = request.GET.get('session', None)
        _request_user_id = Session_Key.objects.get_user_id(_session)
        return SuccessJsonResponse({
            'unread_message_count':
            MobileUser(_request_user_id).get_unread_message_count(),
            'unread_selection_count':
            MobileUser(_request_user_id).get_unread_selection_count()
        })
コード例 #5
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)
コード例 #6
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)
コード例 #7
0
ファイル: stats.py プロジェクト: guoku/Raspberry
def feature_stat(request, feature="user"):
    if request.method == "GET":
        group = request.GET.get("group")
        start = request.GET.get("time_begin")
        end = request.GET.get("time_end")
        start_time = datetime.fromtimestamp(int(start))
        end_time = datetime.fromtimestamp(int(end))

        feature = feature.lower()
        if feature == "user":
            user = UserStats.new_user_count(start_time, end_time, group=group)
            return SuccessJsonResponse(user)

        elif feature == "like":
            like = EntityStats.new_like_count(start_time,
                                              end_time,
                                              group=group)
            return SuccessJsonResponse(like)

        elif feature == "follow":
            follow = UserStats.new_follow_count(start_time,
                                                end_time,
                                                group=group)
            return SuccessJsonResponse(follow)

        elif feature == "entity":
            entity = EntityStats.new_entity_count(start_time,
                                                  end_time,
                                                  group=group)
            return SuccessJsonResponse(entity)

        elif feature == "note":
            note = NoteStats.new_note_count(start_time, end_time, group=group)
            return SuccessJsonResponse(note)

        elif feature == "poke":
            poke = NoteStats.new_poke_count(start_time, end_time, group=group)
            return SuccessJsonResponse(poke)

        elif feature == "tag":
            tag = TagStats.new_tag_count(start_time, end_time, group=group)
            return SuccessJsonResponse(tag)
        else:
            comment = NoteStats.new_note_comment(start_time,
                                                 end_time,
                                                 group=group)
            return SuccessJsonResponse(comment)
コード例 #8
0
ファイル: stats.py プロジェクト: guoku/Raspberry
def general_stat(request):
    if request.method == "GET":
        start = request.GET.get("time_begin")
        end = request.GET.get("time_end")
        start_time = datetime.fromtimestamp(int(start))
        end_time = datetime.fromtimestamp(int(end))

        uctmp = UserStats.new_user_count(start_time, end_time)
        user_count = uctmp[0]["count"]

        folltmp = UserStats.new_follow_count(start_time, end_time)
        follow_count = folltmp[0]["count"]

        enttmp = EntityStats.new_entity_count(start_time, end_time)
        entity_count = enttmp[0]["count"]

        liketmp = EntityStats.new_like_count(start_time, end_time)
        like_count = liketmp[0]["count"]

        notetmp = NoteStats.new_note_count(start_time, end_time)
        note_count = notetmp[0]["count"]

        poketmp = NoteStats.new_poke_count(start_time, end_time)
        poke_count = poketmp[0]["count"]

        commenttmp = NoteStats.new_note_comment(start_time, end_time)
        comment_count = commenttmp[0]["count"]

        tagtmp = TagStats.new_tag_count(start_time, end_time)
        tag_count = tagtmp[0]["count"]

        resp = {
            "user_count": user_count,
            "like_count": like_count,
            "entity_count": entity_count,
            "note_count": note_count,
            "poke_count": poke_count,
            "tag_count": tag_count,
            "follow_count": follow_count,
            "comment_count": comment_count
        }

        return SuccessJsonResponse(resp)
コード例 #9
0
ファイル: category.py プロジェクト: guoku/Raspberry
def category_stat(request, category_id):
    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 = {
            'entity_count':
            MobileEntity.count(category_id=category_id, status='normal'),
            'entity_note_count':
            MobileNote.count(category_id=category_id),
        }
        if _request_user_id != None:
            _rslt['like_count'] = MobileUser(
                _request_user_id).entity_like_count(
                    neo_category_id=category_id)
        else:
            _rslt['like_count'] = 0

        return SuccessJsonResponse(_rslt)
コード例 #10
0
ファイル: sync.py プロジェクト: guoku/Raspberry
def sync_selection(request):
    _offset = int(request.GET.get('offset', '0'))
    _count = int(request.GET.get('count', '100'))
    _rslt = []
    for _doc in NoteSelection.objects.all().order_by(
            '-post_time')[_offset:_offset + _count]:
        _entity_id = _doc.entity_id
        _entity_context = Entity(_entity_id).read()
        _taobao_id_list = []
        for _item_id in _entity_context['item_id_list']:
            _item_context = Item(_item_id).read()
            _taobao_id_list.append({
                'taobao_id': _item_context['taobao_id'],
                'shop_nick': _item_context['shop_nick'],
            })
        _rslt.append({
            'entity_id': _entity_id,
            'note_id': _doc.note_id,
            'post_time': time.mktime(_doc.post_time.timetuple()),
            'taobao_item_list': _taobao_id_list
        })

    return SuccessJsonResponse(_rslt)
コード例 #11
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)
コード例 #12
0
    #    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)
        else:
            _request_user_id = None
        _timestamp = request.GET.get('timestamp', None)
        if _timestamp != None:
コード例 #13
0
ファイル: category.py プロジェクト: guoku/Raspberry
def all_category(request):
    _all_categories = Category.all_group_with_full_category()
    return SuccessJsonResponse(_all_categories)
コード例 #14
0
ファイル: sync.py プロジェクト: guoku/Raspberry
def create_entity_from_offline(request):
    if request.method == 'POST':
        _taobao_id = request.POST.get("taobao_id", None)
        _cid = request.POST.get("cid", None)
        _taobao_shop_nick = request.POST.get("taobao_shop_nick", None)
        _taobao_title = request.POST.get("taobao_title", None)
        _taobao_price = request.POST.get("taobao_price", None)
        _taobao_soldout = request.POST.get("taobao_soldout", '0')
        if _taobao_soldout == '0':
            _taobao_soldout = False
        else:
            _taobao_soldout = True
        _rank_score = int(request.POST.get("item_score", '0'))
        _chief_image_url = request.POST.get("chief_image_url", None)
        _chief_image_url = re.sub('_\d+x\d+\.jpg|_b.jpg', '', _chief_image_url)
        _brand = request.POST.get("brand", "")
        _title = request.POST.get("title", "")
        _intro = request.POST.get("intro", "")
        _category_id = Category.get_category_by_taobao_cid(_cid)
        _origin_detail_image_urls = request.POST.getlist("image_url")
        _detail_image_urls = []
        for _url in _origin_detail_image_urls:
            _detail_image_urls.append(re.sub('_\d+x\d+\.jpg|_b.jpg', '', _url))

        if _chief_image_url in _detail_image_urls:
            _detail_image_urls.remove(_chief_image_url)

        _item = Item.get_item_by_taobao_id(_taobao_id)
        if _item == None:
            _entity = Entity.create_by_taobao_item(
                creator_id=request.user.id,
                category_id=_category_id,
                chief_image_url=_chief_image_url,
                taobao_item_info={
                    'taobao_id': _taobao_id,
                    'cid': _cid,
                    'title': _taobao_title,
                    'shop_nick': _taobao_shop_nick,
                    'price': _taobao_price,
                    'soldout': _taobao_soldout,
                },
                brand=_brand,
                title=_title,
                intro=_intro,
                detail_image_urls=_detail_image_urls,
                weight=-1,
                rank_score=_rank_score)
            _rslt = {
                'entity_id': _entity.entity_id,
                'item_id': _entity.read()['item_id_list'][0],
                'status': 'success'
            }
            return SuccessJsonResponse(_rslt)
        else:
            _item.update(cid=_cid,
                         title=_taobao_title,
                         shop_nick=_taobao_shop_nick,
                         price=_taobao_price,
                         soldout=_taobao_soldout)
            _rslt = {
                'message': 'item_exist',
                'item_id': _item.item_id,
                'status': 'updated'
            }
            return SuccessJsonResponse(_rslt)
コード例 #15
0
ファイル: sync.py プロジェクト: guoku/Raspberry
def sync_taobao_item(request):
    _offset = int(request.GET.get('offset', '0'))
    _count = int(request.GET.get('count', '100'))

    _taobao_id_list = Item.find(offset=_offset, count=_count, full_info=True)
    return SuccessJsonResponse(_taobao_id_list)