Exemple #1
0
    def render_embed(self, request):
        """Return JS for embedding a random ad."""
        name = util.getArg(request, "name")
        section = util.getArg(request, "section")
        batching = util.getArg(request, "batch")
        if name:
            banner = self.service.banners[name]
        else:
            batch = None
            if batching:
                try:
                    batch, numBatches = map(int, batching.split('/'))
                    if batch <= 0 or batch > numBatches:
                        batch = None
                except ValueError:
                    batch = None
            if batch is not None:
                banner = self.service.banners.getRandomBanner(batch - 1, numBatches, section=section)
            else:
                banner = self.service.banners.getRandomBanner(section=section)
        if banner is None:
            return ""

        request.setHeader('content-type', 'text/javascript')
        self._setNoCaching(request)
        if banner.mimeType == "application/x-shockwave-flash":
            return self.embedFlash(banner, request)
        else:
            return self.embedImage(banner, request)
Exemple #2
0
 def embedImage(self, banner, request):
     """Return JS for embedding a banner that is an image."""
     nolog = (util.getArg(request, "nolog") and "&nolog=1") or ""
     s = """document.write('<a href=\"%s/redirect?name=%s%s\">');\n""" % (request.prePathURL(), banner.getId(), nolog)
     s += """document.write('<img border=\"0\" src=\"%s/view?name=%s%s\" width=\"%s\" height=\"%s\" alt=\"%s\"></a>');""" % (
         request.prePathURL(), banner.getId(), nolog, banner.width, banner.height, banner.title)
     return s
Exemple #3
0
    def render_redirect(self, request):
        """Redirect to banner's destination."""
        banner = util.getBanner(self.service, request)
        if banner is None:
            return "No such banner."

        if not util.getArg(request, "nolog"):
            banner.addClick()
        request.redirect(banner.URL)
        return ""
Exemple #4
0
    def render_view(self, request):
        """Return banner's image or Flash contents."""
        banner = util.getBanner(self.service, request)
        if banner is None:
            return "No such banner."

        if not util.getArg(request, "nolog"):
            banner.addView() # we record view of ad here
        self._setNoCaching(request)
        request.setHeader("content-type", banner.mimeType)
        request.setHeader("content-length", len(banner.file))
        return banner.file
Exemple #5
0
    def stream(self, write, request):
        banner = util.getBanner(self.service, request)
        password = util.getArg(request, "password")
        if banner is None or banner.password != password:
            write(('<form action="%s">' % request.prePathURL()) +
                  'Banner ID: <input name="name" /><br />'
                  'Password: <input type="password" name="password" /><br />'
                  '<input type="submit" /></form>')
            return
        write("<h2>Banner title: %s</h2>\n" % banner.title)
        write("<p>Paid views: %s</p>\n" % banner.paidViews)
        write("<p>Views: %s</p>\n" % banner.views)
        write("<p>Clicks: %s</p>\n" % banner.clicks)
        write("<p>Currently running: %s</p>\n" % (banner.isViewable() and "Yes") or "No")

        parts = list(urlparse.urlsplit(request.prePathURL()))
        parts[2] = posixpath.dirname(parts[2])
        baseURL = urlparse.urlunsplit(parts)
        write('<h2>Preview</h2>\n')
        write('<script src="%spublish/embed?name=%s&nolog=1"></script>'
              % (baseURL, util.getArg(request, "name")))
Exemple #6
0
 def embedFlash(self, banner, request):
     """Return JS for embedding a banner that is a flash object."""
     nolog = (util.getArg(request, "nolog") and "&nolog=1") or ""
     url = "%s/view?name=%s%s" % (request.prePathURL(), banner.getId(), nolog)
     h, w = banner.height, banner.width
     s = ("document.write('<OBJECT CLASSID=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\""
          "WIDTH=\"%s\" HEIGHT=\"%s\""
          "CODEBASE=\"http://active.macromedia.com/flash5/cabs/swflash.cab#version=5,0,0,0\">"
          '<PARAM NAME="MOVIE" VALUE="%s">'
          '<PARAM NAME="PLAY" VALUE="true">'
          '<PARAM NAME="QUALITY" VALUE="best">'
          '<PARAM NAME="LOOP" VALUE="true">'
          '<EMBED SRC="%s" WIDTH="%s" HEIGHT="%s" PLAY="true" LOOP="true" QUALITY="best" '
          'PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">' 
          "</EMBED></OBJECT>');") % (w, h, url, url, w, h)
     return s
Exemple #7
0
    gffFormatter = GFFFormatter(feature, rows, relations, residues)
    gffFormatter.parse()
    format = gffFormatter.format()
    
    # try to stop leaks...
    gffFormatter = None
    relations = None
    residues = None
    
    return format


if __name__ == "__main__":
    
    featureUniqueName = getArg("featureUniqueName")
    if featureUniqueName == None or len(featureUniqueName) == 0:
        raise Exception("Please supply a feature uniquename using the -featureUniqueName argument")
    
    gffQueries = GFFQueries(host, database, user, password)
    
    featureID = gffQueries.getFeatureIDFromUniqueName(featureUniqueName)
    
    if featureID == None:
        raise Exception("Sorry, this uniquename has not been recognised.")
    
    feature = Feature(featureUniqueName, featureID)
    
    print gffTopLevelFeature(gffQueries, feature)