コード例 #1
0
 def test_fetch_url_headers(self):
     responses.add(responses.GET,
                   'https://foo.bar/',
                   body='foo',
                   status=200)
     s = requests.Session()
     with mock.patch('resources.lib.comm.session.Session', return_value=s):
         comm.fetch_url('https://foo.bar', headers={'foo': 'bar'})
         self.assertIn('foo', s.headers)
コード例 #2
0
def parse_livestreams_from_feed(data):
    collection_json_data = json.loads(data)['_embedded'].get('collections')

    for collection in collection_json_data:
        if collection.get('title'):
            if 'watch abc channels live' in collection['title'].lower():
                collection_id = collection.get('id')
    import resources.lib.comm as comm
    data = comm.fetch_url(
        config.API_BASE_URL.format(
            path='/v2/collection/{0}'.format(collection_id)))
    json_data = json.loads(data)
    programs_list = []

    for item in json_data.get('items'):
        if item.get('type') != 'livestream':
            continue
        p = classes.Program()
        title = item.get('showTitle')
        p.title = title
        p.house_number = item.get('houseNumber')
        p.description = item.get('description')
        p.thumb = item.get('thumbnail')
        p.fanart = item.get('thumbnail')
        p.url = item['_links']['self'].get('href')
        p.rating = item.get('classification')
        p.duration = item.get('duration')
        p.captions = item.get('captions')
        p.set_date(item.get('pubDate'))
        p.set_expire(item.get('expireDate'))
        programs_list.append(p)
    return programs_list
コード例 #3
0
 def test_fetch_url(self):
     responses.add(responses.GET,
                   'http://foo.bar/',
                   body=u'\ufeffHello World',
                   status=200)
     observed = comm.fetch_url('http://foo.bar/').decode('utf-8')
     self.assertEqual(observed, 'Hello World')
コード例 #4
0
def get_media_auth_token(pai, video_id):
    """
    send our user token to get our embed token, including api key
    """
    url = config.MEDIA_AUTH_URL.format(code=video_id, pai=pai)

    try:
        data = comm.fetch_url(url, request_token=True)
        json_data = json.loads(data)
        if json_data.get('Fault'):
            raise AussieAddonsException(
                json_data.get('fault').get('faultstring'))
        media_auth_token = json_data.get('urlSigningToken')
    except requests.exceptions.HTTPError as e:
        utils.log('Error getting embed token. '
                  'Response: {0}'.format(e.response.text))
        cache.delete('AFLTOKEN')
        if e.response.status_code in [400, 401]:
            raise AussieAddonsException('Login token has expired, '
                                        'please try again.')
        elif e.response.status_code == 404:
            raise AussieAddonsException(
                'Unknown error, please wait a few moments and try again.')
        else:
            raise e
    return media_auth_token
コード例 #5
0
 def test_fetch_url(self):
     responses.add(responses.GET,
                   'https://foo.bar/',
                   body='foo',
                   status=200)
     observed = comm.fetch_url('https://foo.bar')
     expected = 'foo'
     self.assertEqual(expected, observed)