예제 #1
0
 def db_send(self, remote_addr=None, db_connection=None):
     try:
         _insert_data = {
             'date': self._now,
             'remote_addr': remote_addr,
             'name': str(self.params.username),
             'url': self._db_url_param,
             'dir': self._hashdir,
             'oldfile': None,
             'newfile': self.filename,
             'dataobj': json.dumps(dict(self._input_kwargs)),
             'cmd': "; ".join(self.commands),
             'tag': self.tag,
         }
         ImCmd.create(**_insert_data)
     except Exception as e:
         self.err_warn("Problem sending to database:\n %s\n" % str(e))
예제 #2
0
        def gallery():
            search_params = {}
            qs = []
            if request.args.get('tag'):
                search_params['tag'] = GALLERY_TAG_TRANS[request.args['tag']]
                qs.append("tag=" + request.args['tag'])
            if request.args.get('name'):
                search_params['name'] = request.args['name']
                qs.append("name=" + request.args['name'])
            if request.args.get('addr'):
                search_params['remote_addr'] = request.args['remote_addr']
                qs.append("addr=" + request.args['addr'])
            limit = request.args.get('limit') or 20
            if limit > 100:
                limit = 100
            offset = int(request.args.get('start', 0))
            if request.args.get('random'):
                results = ImCmd.search_random(**search_params)
                qs.append("random=" + request.args['random'])
            else:
                results = ImCmd.search(**search_params)
            images = results.limit(limit).offset(offset).all()
            if LOCAL:
                images = ["/im/cache/%s" % image.newfile for image in images]
            else:
                images = [
                    "http://i.asdf.us/im/%s/%s" %
                    (image.dir, image.newfile) for
                    image in images
                ]
            older = offset + limit
            newer = offset - limit
            qs = "&".join(qs)

            return render_template(
                'gallery.html',
                images=images,
                older=older,
                newer=newer,
                qs=qs
            )
예제 #3
0
 def get_data():
     args_dict = request.args.to_dict()
     query_dict = {}
     for elem in ["newfile", "time"]:
         if args_dict.get(elem):
             query_dict[elem] = args_dict.get(elem)
     if args_dict:
         try:
             return Response(
                 # flask prevents from returning arrays,
                 # so we need the json module
                 json.dumps(ImCmd.search(**query_dict)),
                 mimetype='application/json'
             )
         except Exception as e:
             return str(e)
     else:
         raise InvalidUsage('Improper Usage', status_code=410)
예제 #4
0
def data_from_url(url):
    """
    retrieves image params from db using the url
    """
    newfile = os.path.split(url)[-1]
    if OFFLINE:
        sys.path.append("./photoblaster")
        from photoblaster.db.models.imcmd import ImCmd
        result = ImCmd.search(newfile=newfile).first()
        try:
            return {
                "module": result.tag.split(":")[0],
                "params": json.loads(result.dataobj)
            }
        except AttributeError:
            sys.stderr.write("No usable data found in db\n")
            return None
    else:
        print http_request("%s?newfile=%s" % (PB_DATA_URL, newfile))
        raise NotImplementedError("Not yet implemented\n")