Saturday, June 21, 2014

StudyNote -- Set up ECShop using bluehost mail service

The procedure is normal but two points should be highlighted.

1. When configure without SSL, which is not suggested, mail.ozkaola.com is the receiving and sending server, but this should not be put into pop3 or smtp form. The point is to remove mail, just use ozkaola.com with port 26

2. When configure with SSL, which is suggested, one should use box1025.bluehost.com, the whole name is to be used with port 465.

The configure is indicated as blow

Monday, June 09, 2014

StudyNote -- Use Google Image Search by Image in Python

Image Search by Image is uploading an image or specify an image URL to Google, Google searches the web for the information which is related to this image.

Google does not provide any API on Image Search by Image. By searching the Internet, I found someone managed to do this by using this URL http://images.google.com/searchbyimage?site=search&image_url={Image URL}.

I used mechanize lib to simulate browser.

The code is as below


import socket;
import urllib2;
import mechanize


#Browser

br = mechanize.Browser()

#options

br.set_handle_equiv(True)
br.set_handle_gzip(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)

#Follows refresh 0 but not hangs on refresh > 0

br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)

#debugging?

br.set_debug_http(True)
br.set_debug_redirects(True)
br.set_debug_responses(True)

#User-Agent (this is cheating, ok?)

br.addheaders = [('User-agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36')]

    
def searchGoogle():

    
    google="http://images.google.com/searchbyimage?site=search&image_url="
    url=google+"imageURL
    br.open(url)



In Google returned content, there is a tag called "Best guess for this image". Google put the name of what it thinks the thing in the image should be. I use this method to name a large amount of un-named images automatically.

This is basic code, more details code should be written for exceptions.