Пример #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)
Пример #2
0
 def api(self):
     if self._api_cache is None:
         self._api_cache = simpleflickrapi.SimpleFlickrAPI(
             utils.get_flickr_api_key(), utils.get_flickr_secret())
         #TODO: For now 'pics' is just read-only so this is good
         #      enough. However, eventually we'll want separate
         #      `self.read_api', `self.write_api' and
         #      `self.delete_api' or similar mechanism.
         #TODO: cache this auth token in the pics user data dir
         self._api_cache.get_auth_token("read")
     return self._api_cache
Пример #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()