Exemplo n.º 1
0
def save_movie_from_row(movie_row):
    movie = Movie()
    movie.movie_id = movie_row[0]
    movie.tmdbId = movie_row[1]
    movie.name = movie_row[2]
    movie.genre = movie_row[3]
    movie.save()
Exemplo n.º 2
0
def scrape_data(request):
    url_to_scrap = request.GET.get('url', '')
    data = scrape(url_to_scrap)
    for index in range(0, len(data)):
        scraped_movie = data[index]
        try:
            movie_obj = Movie.objects.get(name=scraped_movie['name'])
            movie_obj.updated = datetime.now()
            if movie_obj.image != scraped_movie['image']:
                movie_obj.image = scraped_movie['image']
            movie_obj.save()

        except Movie.DoesNotExist:
            movie = Movie()
            movie.name = scraped_movie['name']
            movie.image = scraped_movie['image']
            movie.year_of_release = scraped_movie['year_of_release']
            movie.director = scraped_movie['director']
            movie.save()

    return JsonResponse({'detail': 'Scraping completed successfully'},
                        status=201)