Skip to content

Instantly share code, notes, and snippets.

@anishm10
anishm10 / myntra_shirts_data.json
Created May 24, 2024 22:02
Myntra dummy shirts data
[
{
"brandName": "Kook N Keech",
"productName": "Striped Pure Cotton Relaxed T-shirt",
"price": {
"mrp": 1099,
"fsp": 494,
"discount": "55"
}
},
@anishm10
anishm10 / scraping_script.js
Created May 24, 2024 21:54
Myntra data scraping script
// Myntra Page : https://www.myntra.com/men-tshirts
const productResultsContainer = document.querySelector('#desktopSearchResults > div.search-searchProductsContainer.row-base > section > ul')
const productResultNodes = productResultsContainer ? Array.from(productResultsContainer.querySelectorAll('li')) : []
const final = []
productResultNodes.forEach((productNode)=>{
const productDataNode = productNode.querySelector('a > div.product-productMetaInfo');
@anishm10
anishm10 / grofer-category-product-scraper.js
Created September 9, 2021 17:55
Grofers Category page Scraper code
/**
* Run the following script on any page following this url pattern : https://grofers.com/cn/<some-category>/cid/1487
* Variable result at the end of execution will have the list of all products in the particular category
**/
const products=document.querySelectorAll('.plp-product');
const category=location.pathname.split('/')[2].split('-').join('_')
const result=[];
products.forEach(p=>{
package com.demo.SpringMongoCRUD.controller;
import com.demo.SpringMongoCRUD.exception.MovieCollectionException;
import com.demo.SpringMongoCRUD.model.Movie;
import com.demo.SpringMongoCRUD.service.MovieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
public void updateMovie(String id,Movie newMovie) throws ConstraintViolationException,MovieCollectionException
{
Optional<Movie> movieWithId=movieRepo.findById(id);
Optional<Movie> movieWithSameTitle=movieRepo.findByTitle(newMovie.getTitle());
if(movieWithId.isPresent())
{
if(movieWithSameTitle.isPresent() && !movieWithSameTitle.get().getId().equals(id))
{
throw new MovieCollectionException(MovieCollectionException.TitleAlreadyExists());
package com.demo.SpringMongoCRUD.repository;
import com.demo.SpringMongoCRUD.model.Movie;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import java.util.Optional;
public interface MovieRepository extends MongoRepository<Movie,String> {
public void createMovie(Movie movie) throws ConstraintViolationException,MovieCollectionException
{
Optional<Movie> movieNameOptional=movieRepo.findByTitle(movie.getTitle());
if(movieNameOptional.isPresent())
{
throw new MovieCollectionException(MovieCollectionException.TitleAlreadyExists());
}
else
{
public void deleteMovieById(String id) throws MovieCollectionException
{
Optional<Movie> movieOptional=movieRepo.findById(id);
if(!movieOptional.isPresent())
{
throw new MovieCollectionException(MovieCollectionException.NotFoundException(id));
}
else
{
movieRepo.deleteById(id);
public List<Movie> getAllMovies()
{
List<Movie> movies=movieRepo.findAll();
if(movies.size()>0)
{
return movies;
}
else
{
return new ArrayList<Movie>();
package com.demo.SpringMongoCRUD.exception;
public class MovieCollectionException extends Exception {
public MovieCollectionException(String message)
{
super(message);
}
public static String NotFoundException(String id)