Example #1
0
    def checkThumbnails(self):
        ac = self.webapp.getContext()
        siteurl = ac.siteinfo['siteurl'] + ac.base
        for uri in self.thumbs.keys():
            page = self.thumbs[uri]['page']
            count = self.thumbs[uri]['count']
            data = self.thumbs[uri]['data']

            # check for invalid or stalled entries in list
            if self.thumbs[uri]['thumb'] is None or count > 20:
                print "LinkBlog: Thumbnail for %s could not be retrieved (tried %d times)." % (
                    uri, count)
                try:
                    ac.notifier.send(
                        self.webapp.getConfigItem('jid'),
                        "Thumbnail for %s could not be retrieved (tried %d times)."
                        % (uri, count))
                    ac.notifier.send(
                        self.webapp.getConfigItem('jid'),
                        "Stored entry %s without thumbnail" % (siteurl + page))
                except:
                    pass
                ac.store.updatePage(page, data)
                del self.thumbs[uri]  # remove from list
            else:
                key = self.thumbs[uri]['thumb']['key']
                (handle, thumbnail) = tempfile.mkstemp(dir='/tmp')
                print "LinkBlog: Trying to obtain thumbnail for %s, stored as %s." % (
                    key, thumbnail)
                # try getting the intermediate thumbnail first
                if webthumb.get_thumbnail(self.apikey, key, thumbnail,
                                          'large'):  # used to be 'medium2'
                    # stop storing this, we'll be resizing the largest on the fly
                    # ac.store.addAttachment(page,thumbnail,'thumbnail.jpg')
                    template = 'linkblog-with-thumbnail'
                    # large thumbnail should be done at the same time...
                    if webthumb.get_thumbnail(self.apikey, key, thumbnail,
                                              'full'):  # used to be 'large'
                        ac.store.addAttachment(page, thumbnail, 'large.jpg')
                        # ...but we upgrade the template only if it is
                        template = 'linkblog-with-quicklook'
                    # this runs the existing content through the template
                    data['content'] = ac.templates[template] % data
                    ac.store.updatePage(page, data)
                    del self.thumbs[uri]  # remove from list
                    print "LinkBlog: Stored entry %s using %s" % (page,
                                                                  template)
                else:
                    count = count + 1
                    self.thumbs[uri]['count'] = count
                os.close(handle)
                try:
                    os.remove(thumbnail)
                except:
                    pass
                print "LinkBlog: temporary file %s removed." % thumbnail
Example #2
0
    def checkThumbnails(self):
        ac = self.webapp.getContext()
        siteurl = ac.siteinfo['siteurl'] + ac.base
        for uri in self.thumbs.keys():
            page = self.thumbs[uri]['page']
            count = self.thumbs[uri]['count']
            data = self.thumbs[uri]['data']

            # check for invalid or stalled entries in list
            if self.thumbs[uri]['thumb'] is None or count > 20:
                print "LinkBlog: Thumbnail for %s could not be retrieved (tried %d times)." % (
                    uri, count)
                ac.notifier.send(
                    self.webapp.getConfigItem('jid'),
                    "Thumbnail for %s could not be retrieved (tried %d times)."
                    % (uri, count))
                ac.notifier.send(
                    self.webapp.getConfigItem('jid'),
                    "Stored entry %s without thumbnail" % (siteurl + page))
                ac.store.updatePage(page, data)
                del self.thumbs[uri]  # remove from list
            else:
                key = self.thumbs[uri]['thumb']['key']
                print "LinkBlog: Trying to obtain thumbnail for %s" % key
                thumbnail = tempfile.mktemp(dir='/tmp')
                # try getting the medium thumbnail first
                if webthumb.get_thumbnail(self.apikey, key, thumbnail,
                                          'medium'):
                    ac.store.addAttachment(page, thumbnail, 'thumbnail.jpg')
                    template = 'linkblog-with-thumbnail'
                    thumbnail = tempfile.mktemp(dir='/tmp')
                    # large thumbnail should be done at the same time...
                    if webthumb.get_thumbnail(self.apikey, key, thumbnail,
                                              'large'):
                        ac.store.addAttachment(page, thumbnail, 'large.jpg')
                        # ...but we upgrade the template only if it is
                        template = 'linkblog-with-quicklook'
                    # this runs the existing content through the template
                    data['content'] = ac.templates[template] % data
                    ac.store.updatePage(page, data)
                    del self.thumbs[uri]  # remove from list
                    print "LinkBlog: Stored entry %s using %s" % (page,
                                                                  template)
                    ac.notifier.send(
                        self.webapp.getConfigItem('jid'),
                        "Stored linkblog entry %s" % (siteurl + page))
                    try:
                        ac.twitter.send(siteurl + page, data['title'])
                    except:
                        print "LinkBlog: unable to send Twitter update for %s" % page
                        pass
                else:
                    count = count + 1
                    self.thumbs[uri]['count'] = count
Example #3
0
def main(site_list_file, img_dir):
    site_list = open(site_list_file,'r')
    for site in site_list.readlines():
        site = site[0:len(site)-1]
        if site:
	    print site
            file = site.replace('/','_')
            file = img_dir+os.sep+file+'.png'
            print file
            get_thumbnail('http://'+site, file,'large')
    site_list.close()
    print 'Webthumbs created !'
Example #4
0
  def checkThumbnails(self):
    ac = self.webapp.getContext()
    siteurl = ac.siteinfo['siteurl'] + ac.base
    for uri in self.thumbs.keys():
      page = self.thumbs[uri]['page']
      count = self.thumbs[uri]['count']
      data = self.thumbs[uri]['data']

      # check for invalid or stalled entries in list
      if self.thumbs[uri]['thumb'] is None or count > 20:
        log.warning("Thumbnail for %s could not be retrieved (tried %d times)." % (uri, count))
        try:
          ac.notifier.send(self.webapp.getConfigItem('jid'), "Thumbnail for %s could not be retrieved (tried %d times)." % (uri, count))
          ac.notifier.send(self.webapp.getConfigItem('jid'), "Stored entry %s without thumbnail" % (siteurl + page))
        except:
          pass
        ac.store.updatePage(page,data)
        del self.thumbs[uri] # remove from list
      else:
        key = self.thumbs[uri]['thumb']['key']
        log.debug("Trying to obtain thumbnail for %s" % key)
        thumbnail = tempfile.mktemp(dir='/tmp')
        # try getting the medium thumbnail first
        if webthumb.get_thumbnail(self.apikey,key,thumbnail,'medium'):
          ac.store.addAttachment(page,thumbnail,'thumbnail.jpg')
          template = 'linkblog-with-thumbnail'
          thumbnail = tempfile.mktemp(dir='/tmp')
          # large thumbnail should be done at the same time...
          if webthumb.get_thumbnail(self.apikey,key,thumbnail,'large'):
            ac.store.addAttachment(page,thumbnail,'large.jpg')
            # ...but we upgrade the template only if it is
            template = 'linkblog-with-quicklook'
          # this runs the existing content through the template
          data['content'] = ac.templates[template] % data
          ac.store.updatePage(page,data)
          del self.thumbs[uri] # remove from list
          log.info("Stored entry %s using %s" % (page,template))
          try:
            ac.notifier.send(self.webapp.getConfigItem('jid'), "Stored linkblog entry %s" % (siteurl + page))
          except:
            pass
          try:
            ac.twitter.send(siteurl + page, data['title'])
          except:
            log.warning("Unable to send Twitter update for %s" % page)
            pass
        else:
          count = count + 1
          self.thumbs[uri]['count'] = count
Example #5
0
  def checkThumbnails(self):
    ac = self.webapp.getContext()
    siteurl = ac.siteinfo['siteurl'] + ac.base
    for uri in self.thumbs.keys():
      page = self.thumbs[uri]['page']
      count = self.thumbs[uri]['count']
      data = self.thumbs[uri]['data']

      # check for invalid or stalled entries in list
      if self.thumbs[uri]['thumb'] is None or count > 20:
        print "LinkBlog: Thumbnail for %s could not be retrieved (tried %d times)." % (uri, count)
        try:
          ac.notifier.send(self.webapp.getConfigItem('jid'), "Thumbnail for %s could not be retrieved (tried %d times)." % (uri, count))
          ac.notifier.send(self.webapp.getConfigItem('jid'), "Stored entry %s without thumbnail" % (siteurl + page))
        except:
          pass
        ac.store.updatePage(page,data)
        del self.thumbs[uri] # remove from list
      else:
        key = self.thumbs[uri]['thumb']['key']
        (handle,thumbnail) = tempfile.mkstemp(dir='/tmp')
        print "LinkBlog: Trying to obtain thumbnail for %s, stored as %s." % (key, thumbnail)
        # try getting the intermediate thumbnail first
        if webthumb.get_thumbnail(self.apikey,key,thumbnail,'large'): # used to be 'medium2'
          # stop storing this, we'll be resizing the largest on the fly
          # ac.store.addAttachment(page,thumbnail,'thumbnail.jpg')
          template = 'linkblog-with-thumbnail'
          # large thumbnail should be done at the same time...
          if webthumb.get_thumbnail(self.apikey,key,thumbnail,'full'): # used to be 'large'
            ac.store.addAttachment(page,thumbnail,'large.jpg')
            # ...but we upgrade the template only if it is
            template = 'linkblog-with-quicklook'
          # this runs the existing content through the template
          data['content'] = ac.templates[template] % data
          ac.store.updatePage(page,data)
          del self.thumbs[uri] # remove from list
          print "LinkBlog: Stored entry %s using %s" % (page,template)
        else:
          count = count + 1
          self.thumbs[uri]['count'] = count
        os.close(handle)
        try:
          os.remove(thumbnail)
        except:
          pass
        print "LinkBlog: temporary file %s removed." % thumbnail