Beispiel #1
0
def search(request):
    req = request.GET
    tag = req['tag']
    tag.replace(' ', '+')
    print tag
    if tag is not None:
        r = HttpUtils.url_fix(tag);
        logger.debug('Found request as %s', r)
        try:
            ps = getPhotosByTag(r)
            details = getInfoOnRelatedPhotos(ps)

            if details is not None:
                data = generateTimelineJson(tag, details)
                # write to json file for generating the timeline
                fileName = writeJson(tag, data)
                t = get_template('timeline.html')
                html = t.render(Context({'file_name': fileName}))
                respond = HttpResponse(html, content_type="text/html")
                respond['Cache-Control'] = "no-cache"
                # return render_to_response('timeline.html', locals(), context_instance = RequestContext(request))

                return respond
        except Exception as e:
            return HttpUtils.getBadRequestJsonResponse("Error Retrieving photos for tag", 404)
Beispiel #2
0
 def getStat(self):
     """
     Returns the HTTP response headers as a dictionary.
     """
     try:
         fh = urllib2.urlopen(self.__pathStr)
         d = fh.info()
         fh.close()
     except Exception, e:
         HttpUtils.handleException(e, self.__pathStr)
Beispiel #3
0
 def getStat(self):
     """
     Returns the HTTP response headers as a dictionary.
     """
     try:
         fh=urllib2.urlopen(self.__pathStr)
         d=fh.info()
         fh.close()
     except Exception,e:
         HttpUtils.handleException(e,self.__pathStr)
Beispiel #4
0
 def __execute(self, request, url_path):
     request['apikey'] = self.apikey
     req_url = self.serverUrl + url_path
     res = HttpUtils.post_json(req_url, request)
     if res['code'] == 200:
         return res['response']
     raise RebaApiError(res['code'], res['message'])
Beispiel #5
0
def getPhotosByTag(tag):
        try:
            url = Flickr_Urls._SEARCH_URL.format(tag).encode('utf-8')
            photoList = HttpUtils.sendRequest(url)
            p = models.RelatedList(photoList)._photoList
            return p
        except Exception as e:
            raise e.message()
Beispiel #6
0
def search(request, tag=None):

    if tag is not None:
        r = HttpUtils.url_fix(tag);
        logger.debug('Found request as %s', r )
        try :
            ps = getPhotosByTag(r)
            details = getInfoOnRelatedPhotos(ps)

            if details is not None:
                data = generateTimelineJson(tag, details)
                # write to json file for generating the timeline
                fileName = writeJson(tag, data)
                t = get_template('timeline.html')
                html = t.render(Context({'file_name' : fileName}))
                respond =  HttpResponse(html, content_type="text/html")
                respond['Cache-Control'] = "no-cache"
                return respond
        except Exception as e:
            return HttpUtils.getBadRequestJsonResponse("Error Retrieving photos for tag", 404)
    else:
        return HttpUtils.getBadRequestJsonResponse("No tag received", 404)
Beispiel #7
0
    def open(self, mode='r'):
        """
        Opens a HTTP connection to the file. If a previous connection
        was opened it is first closed. TODO: currently, mode is
        ignored but we should do a little more validation on it.

        TODO: add this level of error checking to other open methods
        TODO: make mode='r' for all, ie part of the interface
        TODO: write Interface Implementation certification code to
        ensure an implementation adheres to at least the method sigs

        Note: if you get freezes from any of the methods that open a
        connection to the server, it may be some issue between the
        sockets (or something to do with the makefile layer of
        socket). I have only experienced these problems using
        IIS5.something. Good Luck! :-)
        
        """
        self.close()
        if mode in ('r', 'rb'):
            try:
                self.__fileHandle = urllib2.urlopen(self.__pathStr)
            except Exception, e:
                HttpUtils.handleException(e, self.__pathStr)
Beispiel #8
0
    def open(self,mode='r'):
        """
        Opens a HTTP connection to the file. If a previous connection
        was opened it is first closed. TODO: currently, mode is
        ignored but we should do a little more validation on it.

        TODO: add this level of error checking to other open methods
        TODO: make mode='r' for all, ie part of the interface
        TODO: write Interface Implementation certification code to
        ensure an implementation adheres to at least the method sigs

        Note: if you get freezes from any of the methods that open a
        connection to the server, it may be some issue between the
        sockets (or something to do with the makefile layer of
        socket). I have only experienced these problems using
        IIS5.something. Good Luck! :-)
        
        """
        self.close()
        if mode in ('r','rb'):
            try:
                self.__fileHandle=urllib2.urlopen(self.__pathStr)
            except Exception,e:
                HttpUtils.handleException(e,self.__pathStr)
Beispiel #9
0
def getInfoOnRelatedPhotos(photoList):
    # get info on each photo and
    outputPhotoList = []
    dateConflictHash = {}

    if photoList is not None:
        for photo in photoList:
            url = Flickr_Urls._GET_INFO_URL.format(photo._id).encode('utf-8')
            photoInfo = HttpUtils.sendRequest(url)
            info = photo.populatePhotoInfo(photoInfo)
            if info is not None:
                #to do:  resolve conflicting taken dates
                outputPhotoList.append(info)
    # generate json data for timeline of photos
        return outputPhotoList
    else:
        return None
Beispiel #10
0
class HttpPath(ufsi.AbstractUrlPath):
    """
    HttpPath is an implementation of ``ufsi.PathInterface`` that
    interfaces with HTTP file systems. A HTTP path is a standard url
    and therefore uses several of the ``UrlPathUtils`` functions.
    
    """
    __super = ufsi.AbstractUrlPath

    def __init__(self, path):
        """
        Creates a Path object from a HTTP path.
        """
        self.__super.__init__(self, path)
        self.__split = None

    def split(self):
        """
        Splits the path into:

        * protocol - should always be 'http'
        * user - optional user. This will only be populated if the
          user is actually included in the path. That is, if an
          Authentication object has been set it will not be used to
          populate this field.
        * password - only present if a user was given and even then
          it's optional.
        * host - either an ip address or a host name. Must be present
          for a valid HTTP url.
        * port - optional port number.
        * urlPath - everything after the '/' after the host and
          optional port or None.
        * dirs - a list of directory names which will always be
          present.
        * fileBase - the part of the fileName before the last
          period. If no '/' is present after the host (or port), the
          fileBase value will be None, otherwise it will be a
          (possibly empty) string.
        * fileExt - the part of the fileName after the last period. If
          fileBase is None it will also be None and if no period
          exists in the fileName it will be None.

        """
        # check for a cached version
        if self.__split is not None:
            return self.__split.copy()

        # else split it and cache it
        d = self.__super.split(self)
        # TODO: later also split ;type?param#andFragments
        d.update(UrlPathUtils.splitHeirarchicalUrlPath(d['urlPath']))
        self.__split = d
        return d

    def join(self, other):
        """
        Joins a relative path on to the end of this path, correcting
        separator characters if necessary. If ``other`` is an absolute
        path ``other`` is returned, otherwise a new Path object is
        created using the joined path and returned.
        """
        return self.__super.join(self, other)

    def getSeparator(self):
        """
        Returns '/' which is the standard heirarchical url separator
        character.
        """
        return '/'

    def isAbsolute(self):
        """
        Returns True since all HTTP paths are absolute.
        """
        return True

    def isFile(self):
        """
        Returns True if the path exists. All HTTP paths refer to a
        file so if the path exists, it's a file.
        """
        try:
            f = self.getFile()
            f.open()
            f.close()
            return True
        except ufsi.PathNotFoundError, e:
            return False
        except Exception, e:
            # Some other error - handle it
            HttpUtils.handleException(e, self._path)