Ejemplo n.º 1
0
    def _do_flickr(self, subcmd, opts, method, *args):
        """${cmd_name}: Call the given Flickr API method (for debugging).

        ${cmd_usage}
        ${cmd_option_list}
        Examples:
            pics flickr reflection.getMethods
            pics flickr reflection.getMethodInfo method_name=flickr.photos.getInfo
            pics flickr photos.getInfo photo_id=140542114
            pics flickr -d photos.recentlyUpdated min_date=2007-02-11 extras=last_update
        """
        api_key = utils.get_flickr_api_key()
        secret = utils.get_flickr_secret()
        flickr = simpleflickrapi.SimpleFlickrAPI(api_key, secret)
        auth_token = flickr.get_auth_token(perms="read")
        kwargs = dict(a.split('=', 1) for a in args)
        if opts.format_dates:
            if method == "photos.recentlyUpdated" and "min_date" in kwargs:
                d = kwargs["min_date"]
                if re.match("\d+-\d+-\d+", d):
                    dt = datetime.datetime.strptime(d, "%Y-%m-%d")
                    t = str(int(utils.timestamp_from_datetime(dt)))
                    log.debug("min_date: %r -> %r", kwargs["min_date"], t)
                    kwargs["min_date"] = t
        if opts.paging:
            per_page = int(kwargs.get("per_page", 100))
            for i, item in enumerate(flickr.paging_call("flickr."+method, **kwargs)):
                if i and i % per_page == 0:
                    raw_input("Press <Enter> for next page of results...")
                utils.xpprint(item)
        else:
            xml = flickr.call("flickr."+method, **kwargs)
            utils.xpprint(xml)
Ejemplo n.º 2
0
 def info(self, path):
     """Dump info (retrieved from flickr) about the identified photos."""
     for p in utils.paths_from_path_patterns([path],
                 dirs="if-not-recursive",
                 recursive=False,
                 on_error="yield"):
         for dir, id in self._local_photo_dirs_and_ids_from_target(p):
             log.debug("dump info for photo", id)
             info = self.api.photos_getInfo(photo_id=id)
             xpprint(info)
Ejemplo n.º 3
0
    def _do_play(self, subcmd, opts):
        """Run my current play/dev code.

        ${cmd_usage}
        ${cmd_option_list}
        """
        if False:
            api_key = utils.get_flickr_api_key()
            secret = utils.get_flickr_secret()
            flickr = simpleflickrapi.SimpleFlickrAPI(api_key, secret)
            auth_token = flickr.get_auth_token(perms="read")
            t = time.time()
            t -= 30 * 24 * 60 * 60.0
            t = str(int(t))
            utils.xpprint(
                #flickr.favorites_getList()
                flickr.photos_recentlyUpdated(min_date=t, extras="date_taken,media,original_format")
            )
        if True:
            import sqlite3
            cx = sqlite3.connect("photos.sqlite3")
            cu = cx.cursor()
            cu.executescript("""
                -- List of photos in the working copy.
                CREATE TABLE photos (
                    id INTEGER UNIQUE,
                    datedir TEXT
                );
                -- List of photos to update.
                CREATE TABLE updates (
                    id INTEGER UNIQUE,
                    datedir TEXT
                );
            """)
            cx.commit()

            # Gather all the updates to do.
            for row in [(1,'a'), (2,'b'), (3,'c')]:
                cu.execute("INSERT INTO updates VALUES (?,?)", row)
            cx.commit()

            # Do all the updates.
            cu.execute("SELECT * from updates")
            for row in cu:
                print row

            cu.close()
            cx.close()