filmaster-api-sample / test_client.py

import logging
logger = logging.getLogger(__name__)

from filmaster_auth import FilmasterOAuthClient
from urllib import urlencode
import urllib2
import json
from pprint import pprint
import datetime


if __name__ == '__main__':
    import sys, optparse

    op = optparse.OptionParser(usage="usage: python test_client.py [options] filmaster_app_key filmaster_app_secret")
    op.add_option('-t', '--access-token', dest='access_token', help='OAuth access token')
    op.add_option('-c', '--callback-url', dest='callback_url', help='OAuth callback url')
    op.add_option('-f', '--fb-access-token', dest='fb_access_token', help='Facebook access token, for login/auto-create users associated with fb account')
    op.add_option('-v', '--verbose', dest='verbose', action='store_true', help='Verbose')

    opts, args = op.parse_args()
    if len(args) != 2:
        op.print_help()
        sys.exit()

    logging.basicConfig(level=logging.DEBUG if opts.verbose else logging.INFO)
    logger.debug('test')
    key, secret = args

    try:
        client = FilmasterOAuthClient(key, secret, opts.access_token)
        if not opts.access_token:
            if opts.fb_access_token and not opts.callback_url:
                request_token = client.fetch_request_token()
                access_token = client.facebook_login(opts.fb_access_token)
            else:
                request_token = client.fetch_request_token()
                authorize_url = client.get_authorize_url(request_token, callback_url=opts.callback_url)
                print 'open in browser:', authorize_url
                verifier = raw_input('oauth_verifier:')
                access_token = client.fetch_access_token(request_token, verifier)
        logger.info("access_token: %s", client.access_token)

        client.put('/1.1/profile/', {'latitude': '52.3', 'longitude': '21'})
        pprint(client.get('/1.1/profile/'))
    except urllib2.HTTPError, e:
        print e.read()
        raise
    """
    today = datetime.date.today()
    showtimes = client.get('/1.1/profile/showtimes/%s/?limit=50&include=film' % today)
    for s in showtimes['objects']:
        print s['film']['title']
        print s['film']['guess_rating']

    pprint(client.get('/1.1/profile/meta/film/jestes-bogiem/?include=channels&date=%s' % today))
    """
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.