Month: November 2012

  • PhantomSQL released

    Finally I have released my PhantomSQL project.

    PhantomSQL is a domain specific language designed for mining content from static and dynamic sources, It closely resembles SQL with features borrowed from other popular dynamic languages.
    It can be run as a interpreter or ‘server’ mode, it comes with type 4 JDBC driver for ease of integration with java applications.

    Sample Queries

    Here are just few examples taken from the project site to display some of the syntax of the language.

    Hello World

    Following example illustrates how to query google.com for some blog search results.

    
     select first css("#ires a") as title from https://www.google.com/search
      using get with {'q': "josh bloch", 'tbm':"blg"}
      
      print @title +" : "+ @title['href']
    

    Crawling Flicker.com

    Flicker Integration
    This query does nothing more than query flicker.com for ‘nabilishes’ and then crawl the site using GET while the ‘css(“a.Next”)’ condition matches, at the end it prints how many results have been found.

     @result = select css(".pc_img") from http://www.flickr.com/search 
     using get with {'q': "nabilishes", 'm' : "text"}
     crawl(css("a.Next")) 
     print @result.length()
    
    

    Extracting images from Flicker.com search results

    Here we build on previous example by adding the ‘WHILE-SELECT’ construct and actually saving the image with the ‘save’ function.

    while select css(".pc_img", "src", true) as img from http://www.flickr.com/search  
           using get with {'q': "nabilishes", 'm' : "text"}
           crawl(css("a.Next")) 
     begin
       save (@img)
     end
    

    Retrieving Binary Content

    Following two examples are equivalent.

    Following example illustrates how to retrieve binary content from a site and save it on the filesystem when running via interpreter.

    
    select first css("#main_image", "src", true) as item from https://1saleaday.com
    save(@item)
    

    Following example illustrates how to retrieve binary content from a site with JDBC Driver and dump the file to file system.

        public void retieveFile()
        {
            try
            {
                try
                {
                    Class.forName("com.gbltech.phantomsql.driver.PhantomDriver");
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }
                Connection conn = DriverManager.getConnection("jdbc:phantomsql://localhost?characterEncoding=utf8");
                Statement statement = conn.createStatement();
                ResultSet resultSet = statement
                    .executeQuery("select first css(\"#main_image\", \"src\", true) as item from https://1saleaday.com");
                if (resultSet.next())
                {
                    OutputStream out = null;
                    Blob blob = resultSet.getBlob(1);
                    try
                    {
                        out = new FileOutputStream(new File("./test.jpg"));
                        InputStream is = blob.getBinaryStream();
                        byte[] buff = new byte[1024];
                        int read = 0;
                        while ((read = is.read(buff, 0, buff.length)) != -1)
                        {
                            out.write(buff, 0, read);
                        }
                        out.flush();
                    }
                    catch (FileNotFoundException e)
                    {
                        e.printStackTrace();
                    }
                    catch (IOException e)
                    {
                        e.printStackTrace();
                    }
                    finally
                    {
                        if (out != null)
                        {
                            try
                            {
                                out.close();
                            }
                            catch (IOException e)
                            {
                                e.printStackTrace();
                            }
                        }
                    }
                }
            }
            catch (SQLException e)
            {
                e.printStackTrace();
            }
        }
    

    This is just a taste of what the PhantomSQL can do, there is much more so go check it out.
    I am looking for feedback, criticism and bug reports to let me make the project better, so if you have something drop me a line.

  • BigCommerce Mod : Custom product tabs

    This is a simple mod that allow us to have custom product tabs in BigCommerce system, there is no limit on how many tabs you can have. Our final result will be this.

    Mod

    This mod requires modification to only one file /Panels/ProductTabs.html

    Step 1

    Add current JavaScript to the existing script tag

    	/**
    	 * Overrides  parts of /javascript/product.functions.js#GenerateProductTabs() function
    	 * as it does not support related products	 
    	*/
    	$(document).ready(function()
    	{
    			var id = 'RelatedProducts';
    			var TabName = 'Related Products';
    			 var ProductTab = '
  • '+TabName+'
  • '; $('#ProductTabsList').append(ProductTab); });

    Step 2

    Here we actually add content of our tab.

    	
    

    One thing to not is that the div id ‘RelatedProducts’ relates to javascript id ‘RelatedProducts’ so if you change that you need to change the div id.

    That is, if we wanted to add additional tabs we simply would use an array.

  • BigCommerce Mod : Show brand logo image on Product Page

    Showing brand logos on product pages in BigCommerce sites is harder than it should be. Here is a quick mod that will let us do that without need of using the API.
    Here is the desired result

    Code

    This works by parsing you /brands page and then comparing current brand name to the one from parsed page.

    Lets edit Panels/ProductPanels.html and change the current brand code into this

    %%LNG_Brand%%:

    %%GLOBAL_BrandName%%