Skip to content

Latest commit

 

History

History
170 lines (113 loc) · 3.81 KB

File metadata and controls

170 lines (113 loc) · 3.81 KB

최종 프로젝트

[TOC]

이름 짓기

flix : 영화

match : 추천

jisu : ji

flixmatji : 맞지?

추천한거 잘 맞지??

너의 취향 꿰뚫는중.

프로젝트 생성

  • 프로젝트 만들기
$ django-admin startproject flixmatji .
  • account 앱 만들기
$ python manage.py startapp accounts
  • 덤프데이터 만들기
$ python manage.py dumpdata --indent 4 accounts.user > users.json
$ python manage.py dumpdata --indent 4 movies.movie > movies.json
  • 덤프 데이터 받아오기
python manage.py loaddata users.json

영화데이터 받아오기

def test(request):
    url = 'https://api.themoviedb.org/3/'
    key = '13e257e737120d9f2a156d9edd56d945'
    URL = f'{url}genre/movie/list?api_key={key}&language=ko-KR'
    raw_data = requests.get(URL).json()
    data = raw_data.get('genres')
    for genre in data:
        g = Genre()
        g.id = genre.get("id")
        g.name = genre.get("name")

        g.save()



    for page in range(1, 500):
        URL = f'{url}movie/popular?api_key={key}&language=ko-KR&page={page}'
        raw_data = requests.get(URL).json()
        data = raw_data.get('results')
        # print(data)
        for movie in data:
            m = Movie()
            m.id = movie.get("id")
            m.title = movie.get("title")
            m.popularity = movie.get("popularity")
            m.release_date = movie.get("release_date") or None
            m.vote_average = movie.get("vote_average")
            m.vote_count = movie.get("vote_count")
            m.overview = movie.get("overview")
            m.poster_path = movie.get("poster_path")
            m.save()

            y = movie.get("genre_ids")
            for h in range(len(y)):
                a = y[h]
                m.genre_ids.add(a)

    return HttpResponse('ok')

슬픈 대댓글 달기.. => 시간 있으면 다시 구현

# comments 조회
# get일 때
def comments(request, article_id):
    parent_id = int(request.Get.get("parent_id", "0"))

    if parent_id == 0:
        all_comments = Comment.objects.filter(article_id=article_id, parent_comment__isnull=True).select_related('user')
    
    else:
        all_comments = Comment.objects.filter(article_id=article_id, parent_comment_id=parent_id).select_related('user')
        # limit = int(request.Get.get('limit', '10'))
        # offset = int(request.Get.get('offset', '0'))
        # comments = all_comments[offset:offset+limit]
        comment_list = [{
            'comment_id' : comment.id,
            'user_id' : comment.user_id,
            'content': comment.content,
            'created_at': comment.created_at,
            'updated_at':comment.updated_at,
            'parent_id': comment.parent_comment_id
        } for comment in all_comments] 

    return JsonResponse({'comments':comment_list}, status=200)

@api_view(['POST'])
def create_comment(request, article_pk):
    try:
        data = json.loads(request.body)
        user = request.user
        print(data)

        content = data.get('content', None)
        article_id = article_pk
        parent_comment = data.get('parent_comment', None)
    
        if not(content and article_id):
            return JsonResponse({})
        
        if not Article.objects.filter(id=article_id).exists():
            return JsonResponse({})
        
        article = Article.objects.get(id=article_id)

        Comment.objects.create(
            content= content,
            user = user,
            article = article,
            parent_comment = parent_comment
        )
        return JsonResponse({'message':'SUCCESS'}, status=status.HTTP_201_CREATED)

    except JSONDecodeError:
        return JsonResponse({'message':'JSON_DECODE_ERROR'}, status=400)

추가 설치 프로그램

numpy

ast

scikit-learn

pandas