Subversion Repositories SmartDukaan

Rev

Rev 15033 | Rev 15185 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 15033 Rev 15183
Line 15... Line 15...
15
import org.jsoup.Jsoup;
15
import org.jsoup.Jsoup;
16
import org.jsoup.nodes.Document;
16
import org.jsoup.nodes.Document;
17
 
17
 
18
import com.whalin.MemCached.MemCachedClient;
18
import com.whalin.MemCached.MemCachedClient;
19
import in.shop2020.dtrapi.services.MemCache;
19
import in.shop2020.dtrapi.services.MemCache;
-
 
20
import in.shop2020.dtrapi.services.UserMessagePojo;
20
 
21
 
21
public class SnapdealProductPageParserController extends BaseController{
22
public class SnapdealProductPageParserController extends BaseController{
22
 
23
 
23
    private static Logger log = Logger.getLogger(Class.class);
24
    private static Logger log = Logger.getLogger(Class.class);
24
    private static final long serialVersionUID = 1L;
25
    private static final long serialVersionUID = 1L;
Line 32... Line 33...
32
    private static MemCache memCache = new MemCache();
33
    private static MemCache memCache = new MemCache();
33
    private static MemCachedClient memcachedClient = memCache.getClient();
34
    private static MemCachedClient memcachedClient = memCache.getClient();
34
    
35
    
35
    
36
    
36
 
37
 
37
    public String getJavaScriptToEmbedd() throws IOException, JSONException, URISyntaxException{
38
    public String getColorMessage() throws IOException, JSONException, URISyntaxException{
38
        try{
39
        try{
39
            parseUrl();
40
            parseUrl();
40
            if (!checkCache()){
41
            if (!checkCache()){
41
                System.out.println(productUrl);
42
                System.out.println(productUrl);
42
                Document doc = Jsoup.connect(productUrl).get();
43
                Document doc = Jsoup.connect(productUrl).get();
Line 47... Line 48...
47
                        color = jsonArray.getJSONObject(element).getString("value");
48
                        color = jsonArray.getJSONObject(element).getString("value");
48
                        populateCache(supc, color);
49
                        populateCache(supc, color);
49
                    }
50
                    }
50
                }
51
                }
51
            }
52
            }
52
            setResultJson(getJavaScriptCode());
-
 
53
        }
53
        }
54
        catch (Exception e){
54
        catch (Exception e){
55
            log.error("Error while getting product details " +e);
55
            log.error("Error while getting product details " +e);
56
            setResultJson(getJavaScriptCode());
-
 
57
        }
56
        }
-
 
57
        setResultJson(getMsg());
58
        return INDEX;
58
        return INDEX;
59
 
59
 
60
    }
60
    }
61
    
61
    
-
 
62
    private UserMessagePojo getMsg(){
-
 
63
    	UserMessagePojo ump = new UserMessagePojo();
-
 
64
    	if (color.isEmpty()){
-
 
65
    		ump.setResult(false);
-
 
66
    		ump.setMessage("");
-
 
67
    	}
-
 
68
    	else{
-
 
69
    		ump.setResult(true);
-
 
70
    		ump.setMessage("Please select "+color+" to get this price");
-
 
71
    	}
-
 
72
		return ump;
-
 
73
    	
-
 
74
    }
-
 
75
    
62
    private String getJavaScriptCode(){
76
    private String getJavaScriptCode(){
63
        String jsCode = "javascript:try{var ele=document.getElementById('attribute-select-0');ele.value ="+"'"+color+"'"+";ele.onchange();}catch(error){Android.onError(error.message);}";
77
        String jsCode = "javascript:try{var ele=document.getElementById('attribute-select-0');ele.value ="+"'"+color+"'"+";ele.onchange();}catch(error){Android.onError(error.message);}";
64
        return jsCode;
78
        return jsCode;
65
    }
79
    }
66
 
80
 
Line 117... Line 131...
117
 
131
 
118
    public static void main(String[] args) throws URISyntaxException, IOException, JSONException{
132
    public static void main(String[] args) throws URISyntaxException, IOException, JSONException{
119
        SnapdealProductPageParserController s = new SnapdealProductPageParserController();
133
        SnapdealProductPageParserController s = new SnapdealProductPageParserController();
120
        String url = "http://m.snapdeal.com/product/samsung-galaxy-grand-max/647437791381?supc=SDL021483758&aff_id=1&bhalala=0";
134
        String url = "http://m.snapdeal.com/product/samsung-galaxy-grand-max/647437791381?supc=SDL021483758&aff_id=1&bhalala=0";
121
        s.setUrl(Base64.encode(url.getBytes()));
135
        s.setUrl(Base64.encode(url.getBytes()));
122
        s.getJavaScriptToEmbedd();
136
        s.getColorMessage();
-
 
137
        System.out.println(s.getResultJson());
123
    }
138
    }
124
 
139
 
125
}
140
}
126
141