我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用auth.auth()。
def create_app(config_name): app = Flask(__name__) app.config.from_object(config[config_name]) config[config_name].init_app(app) bootstrap.init_app(app) mail.init_app(app) moment.init_app(app) pagedown.init_app(app) login_manager.init_app(app) if not app.debug and not app.testing and not app.config['SSL_DISABLE']: from flask.ext.sslify import SSLify sslify = SSLify(app) from main import main as main_blueprint app.register_blueprint(main_blueprint) from auth import auth as auth_blueprint app.register_blueprint(auth_blueprint,url_prefix='/auth') db.init_app(app) return app
def get_favorites(page=1, per_page=10): videos = [] username = control.setting('globoplay_username') password = control.setting('globoplay_password') # authenticate credentials = auth.auth().authenticate(username, password) headers = {'Accept-Encoding': 'gzip'} data = client.request(GLOBOPLAY_FAVORITES % (page, per_page), cookie=credentials, headers=headers) if not data or not 'data' in data: return [], None, 0 for item in data['data']: video = { 'id': item['resource_id'], 'title': item['metadata']['title'], 'tvshowtitle': item['metadata']['program']['title'], 'plot': item['metadata']['description'], 'duration': int(item['metadata']['duration'])/1000 if item['metadata']['duration'] else 0, 'thumb': THUMB_URL % item['resource_id'], 'fanart': THUMB_URL % item['resource_id'], 'date': item['metadata']['exhibited_at'], 'mediatype': 'episode', 'season': item['metadata']['season'] if 'season' in item['metadata'] else None, 'episode': item['metadata']['episode'] if 'episode' in item['metadata'] else None, 'year': item['metadata']['year'] if 'year' in item['metadata'] else None, 'originaltitle': item['metadata']['original_title'] if 'original_title' in item['metadata'] else None } videos.append(video) pager = data['pager'] return videos, pager['next_page'], pager['total_pages']
def get_continue_watching(): videos = [] limit = 15 username = control.setting('globoplay_username') password = control.setting('globoplay_password') # authenticate credentials = auth.auth().authenticate(username, password) headers = {'Accept-Encoding': 'gzip'} data = client.request(GLOBOPLAY_CONTINUEWATCHING_BYPROGRAM % limit, cookie=credentials, headers=headers) if not data or not 'data' in data: return [], None, 0 for item in data['data']: video = { 'id': item['resource_id'], 'title': item['metadata']['title'], 'tvshowtitle': item['metadata']['program']['title'], 'plot': item['metadata']['description'], 'duration': int(item['metadata']['duration'])/1000 if item['metadata']['duration'] else 0, 'thumb': THUMB_URL % item['resource_id'], 'fanart': THUMB_URL % item['resource_id'], 'aired': item['metadata']['exhibited_at'][:10], 'mediatype': 'episode', 'season': item['metadata']['season'] if 'season' in item['metadata'] else None, 'episode': item['metadata']['episode'] if 'episode' in item['metadata'] else None, 'year': item['metadata']['year'] if 'year' in item['metadata'] else None, 'originaltitle': item['metadata']['original_title'] if 'original_title' in item['metadata'] else None, 'milliseconds_watched': item['milliseconds_watched'], 'lastplayed': item['updated_at'][:19].replace('T', ' '), 'playcount': '1' } videos.append(video) return videos, None, 1
def test_create_source_outside_rev(self): pub = Socrata(auth) (ok, source) = pub.sources.create_upload('foo.csv') self.assertTrue(ok, source) self.assertEqual(source.attributes['source_type']['filename'], 'foo.csv') assert 'show' in source.list_operations() assert 'bytes' in source.list_operations()
def test_source_csv_outside_rev(self): pub = Socrata(auth) (ok, source) = pub.sources.create_upload('foo.csv') self.assertTrue(ok, source) df = pd.read_csv('test/fixtures/simple.csv') (ok, source) = source.df(df) self.assertTrue(ok, source) input_schema = source.get_latest_input_schema() names = sorted([ic['field_name'] for ic in input_schema.attributes['input_columns']]) self.assertEqual(['a', 'b', 'c'], names)
def test_put_source_in_revision(self): pub = Socrata(auth) (ok, source) = pub.sources.create_upload('foo.csv') self.assertTrue(ok, source) df = pd.read_csv('test/fixtures/simple.csv') (ok, input_schema) = source.df(df) self.assertTrue(ok, input_schema) rev = self.create_rev() (ok, source) = source.add_to_revision(rev) self.assertTrue(ok, source)
def create_app(config_name='default'): app = Flask(__name__) app.config.from_object(config[config_name]) db.init_app(app) bootstrap.init_app(app) login_manager.init_app(app) pagedown.init_app(app) # babel.init_app(app) Gravatar(app, size=64) from auth import auth as auth_blueprint from main import main as main_blueprint app.register_blueprint(auth_blueprint, url_prefix='/auth') app.register_blueprint(main_blueprint, static_folder='static') @app.template_test('current_link') def is_current_link(link): return link == request.path # @babel.localeselector # def get_locale(): # return current_user.locale return app # @app.route('/upload', methods=['GET', 'POST']) # def upload(): # if request.method == 'POST': # f = request.files['file'] # basepath = path.abspath(path.dirname(__file__)) # upload_path = path.join(basepath, 'static/uploads') # f.save(upload_path + '/' + secure_filename(f.filename)) # return redirect(url_for('upload')) # return render_template('upload.html')
def create_app(config_name): app = Flask(__name__) app.config.from_object(config[config_name]) config[config_name].init_app(app) bootstrap.init_app(app) mail.init_app(app) moment.init_app(app) db.init_app(app) login_manager.init_app(app) pagedown.init_app(app) assets.init_app(app) if config_name == "testing": assets._named_bundles = {} # quick fix for flask testng and flask assets js = Bundle('js/index.js',filters='jsmin', output='gen/packed.js') assets.register('js_all', js) css = Bundle('css/index.css',filters='cssmin',output='css/min.css') assets.register('css_all', css) from main import main as main_blueprint app.register_blueprint(main_blueprint) from auth import auth as auth_blueprint app.register_blueprint(auth_blueprint, url_prefix='/auth') from admin import admin as admin_blueprint app.register_blueprint(admin_blueprint, url_prefix='/admin') from api_1_0 import api as api_1_0_blueprint app.register_blueprint(api_1_0_blueprint, url_prefix='/api/v1.0') return app
def get_watch_history(): videos = [] limit = 15 username = control.setting('globoplay_username') password = control.setting('globoplay_password') # authenticate credentials = auth.auth().authenticate(username, password) headers = {'Accept-Encoding': 'gzip'} data = client.request(GLOBOPLAY_WATCHHISTORY_BYPROGRAM % limit, cookie=credentials, headers=headers) if not data or not 'data' in data: return [], None, 0 for item in data['data']: video = { 'id': item['resource_id'], 'title': item['metadata']['title'], 'tvshowtitle': item['metadata']['program']['title'], 'plot': item['metadata']['description'], 'duration': int(item['metadata']['duration'])/1000 if item['metadata']['duration'] else 0, 'thumb': THUMB_URL % item['resource_id'], 'fanart': THUMB_URL % item['resource_id'], 'clearlogo': GLOBO_LOGO, 'aired': item['metadata']['exhibited_at'][:10], 'mediatype': 'episode', 'season': item['metadata']['season'] if 'season' in item['metadata'] else None, 'episode': item['metadata']['episode'] if 'episode' in item['metadata'] else None, 'year': item['metadata']['year'] if 'year' in item['metadata'] else None, 'originaltitle': item['metadata']['original_title'] if 'original_title' in item['metadata'] else None, 'lastplayed': item['updated_at'][:19].replace('T', ' '), 'playcount': '1' } if 'fully_watched' not in item or not item['fully_watched']: video.update({'milliseconds_watched': item['milliseconds_watched']}) videos.append(video) return videos, None, 1