package com.diaoyun.zion.chinafrica.bis.impl;

import com.diaoyun.zion.chinafrica.bis.IItemSpider;
import com.diaoyun.zion.chinafrica.enums.PlatformEnum;
import com.diaoyun.zion.master.util.HttpClientUtil;
import com.diaoyun.zion.master.util.spider.LilySpiderParse;
import net.sf.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;

/**
 * Lily 数据爬虫
 *
 * TODO 数据已分析，难度较大，延后处理
 *
 * @author 爱酱油不爱醋
 */
@Component("lilySpider")
public class LilySpider implements IItemSpider {
    private static Logger logger = LoggerFactory.getLogger(PullandbearSpider.class);

    /**
     * Lily 商品详情页 Url
     */
    private static final String ADIDAS_URL="http://www.lily.sh.cn/webapp/wcs/stores/servlet/lilystore";

    /**
     * Lily 数据爬虫
     * @see LilySpiderParse#formatProductResponse 格式化数据方法
     * @param targetUrl 接收的商品详情路径
     * @return 格式化与翻译后的 Json 数据
     */
    @Override
    public JSONObject captureItem(String targetUrl) throws InterruptedException, IOException, ExecutionException, URISyntaxException, TimeoutException {

        return null;
    }

    public static void main(String[] args) throws Exception {
        String targetUrl = "http://www.lily.sh.cn/webapp/wcs/stores/servlet/lilystore/24003/276409";
        String content = HttpClientUtil.getContentByUrl(targetUrl, PlatformEnum.LILY.getValue());
        Document document = Jsoup.parse(content);
        System.err.println(document);
    }
}
