Exemplo n.º 1
0
def test_api_get_post_content(gk: GkApiClient):
    article = gk.get_post_content(333)
    assert article and isinstance(article, dict)
    for key in {'id', 'article_title', 'article_content', 'column_id'}:
        assert article.get(key) is not None, '{} 不存在'.format(key)

    # mp3
    assert article.get('audio_download_url')
    # mp4
    article = gk.get_post_content(2184)
    vm = article.get('video_media_map')
    assert vm, 'video_media_map 不存在'
    assert vm['sd']['url']
    assert vm['hd']['url']
Exemplo n.º 2
0
def test_api_get_post_content(gk: GkApiClient, article_id):
    article = gk.get_post_content(article_id)
    assert article and isinstance(article, dict)
    for key in post_keys_needed:
        assert article.get(key) is not None, '{} 不存在'.format(key)

    # mp3
    assert article.get('audio_download_url')
    # mp4
    article = gk.get_post_content(video_id)
    vm = article.get('video_media_map')
    assert vm, 'video_media_map 不存在'
    assert vm['sd']['url']
    assert vm['hd']['url']
Exemplo n.º 3
0
    def run(self, args: dict):

        area = args.get('area')
        account = args.get('account')
        password = args.get('password')
        need_save = not (area and account and password)

        if not account:
            account = input("enter your registered account(phone): ")
        if not area:
            area = input("enter country code: ")
        if not password:
            password = input("account: +{} {}\n"
                             "enter password: "******"Login succeed\n")
Exemplo n.º 4
0
def test_api_get_course_intro(gk: GkApiClient):
    course = gk.get_course_intro(48)
    assert isinstance(course, dict)
    for key in {
            'id', 'column_title', 'had_sub', 'is_finish', 'update_frequency'
    }:
        assert course.get(key) is not None, '{} 不存在'.format(key)
Exemplo n.º 5
0
def test_api_get_vedio_content(gk: GkApiClient):
    video = gk.get_post_content(daily_id)
    assert video and isinstance(video, dict)
    for key in daily_video_keys_needed:
        assert video.get(key) is not None, '{} 不存在'.format(key)

    # video_url
    assert 'video_media_map' in video
Exemplo n.º 6
0
def test_api_get_course_list(gk: GkApiClient):
    res = gk.get_course_list()

    assert isinstance(res, dict)
    assert {'1', '2', '3', '4'} & set(res.keys())
    for type_ in {'1', '2', '3', '4'}:
        course_list = res[type_]['list']
        course = course_list[0]
        assert isinstance(course, dict)
        for key in course_keys_needed:
            assert course.get(key) is not None, '{} 不存在'.format(key)
Exemplo n.º 7
0
def get_data_client(cfg: dict) -> DataClient:
    gk = GkApiClient(account=cfg['account'],
                     password=cfg['password'],
                     area=cfg['area'])
    f = os.path.expanduser(
        os.path.join(cfg['output_folder'], 'geektime-localstorage.json'))
    db = TinyDB(f, storage=_JSONStorage)

    dc = DataClient(gk, db)

    return dc
Exemplo n.º 8
0
def test_api_get_course_list(gk: GkApiClient):
    res = gk.get_course_list()

    assert isinstance(res, dict)
    assert {'1', '2', '3', '4'} & set(res.keys())
    for type_ in {'1', '2', '3', '4'}:
        course_list = res[type_]['list']
        course = course_list[0]
        assert isinstance(course, dict)
        for key in {
                'id', 'column_title', 'had_sub', 'is_finish',
                'update_frequency'
        }:
            assert course.get(key) is not None, '{} 不存在'.format(key)
Exemplo n.º 9
0
    def run(self, args: dict):
        area = args['area']
        account = args['account']
        password = args['password']
        need_save = not (area and account and password)

        if not account:
            account = input("enter your registered account(phone): ")
        if not area:
            area = input("enter country code: enter for 86 ") or '86'
        if not password:
            password = input("account: +{} {}\n"
                             "enter password: "******"{}\nEnter again\n".format(e))
            area = input("enter country code: enter for 86 ") or '86'
            account = input("enter your registered account(phone): ")
            password = input("account: +{} {}\n"
                             "enter password: "******"Login succeed\n")
Exemplo n.º 10
0
def test_api_get_video_collection_intro(gk: GkApiClient):
    course = gk.get_video_collection_intro(collection_id)
    assert isinstance(course, dict)
    for key in {'cid', 'title'}:
        assert course.get(key) is not None, '{} 不存在'.format(key)
Exemplo n.º 11
0
def test_api_get_post_comments(gk: GkApiClient, article_id):
    res = gk.get_post_comments(article_id)
    assert res and isinstance(res, list)
    comment = res[0]
    for key in comment_keys_needed:
        assert comment.get(key) is not None, '{} 不存在'.format(key)
Exemplo n.º 12
0
def test_api_get_course_content(gk: GkApiClient):
    gk.get_course_content(48)
Exemplo n.º 13
0
def test_api_get_course_post_list(gk: GkApiClient, column_id):
    course = gk.get_post_list_of(column_id)
    assert course and isinstance(course, list)
    article = course[0]
    for key in {'id'}:
        assert article.get(key) is not None, '{} 不存在'.format(key)
Exemplo n.º 14
0
def test_api_get_course_intro(gk: GkApiClient, column_id):
    course = gk.get_course_intro(column_id)
    assert isinstance(course, dict)
    for key in course_keys_needed:
        assert course.get(key) is not None, '{} 不存在'.format(key)
Exemplo n.º 15
0
def test_api_get_post_content(gk: GkApiClient):
    gk.get_post_content(333)
Exemplo n.º 16
0
# coding=utf8

import os
from geektime_dl.data_client.gk_apis import GkApiClient

gk = GkApiClient()


def test_api_login():
    gk.login(os.getenv('account'), os.getenv('password'))


def test_api_get_course_list():
    gk.get_course_list()


def test_api_get_course_intro():
    gk.get_course_intro(48)


def test_api_get_course_content():
    gk.get_course_content(48)


def test_api_get_post_content():
    gk.get_post_content('333')
Exemplo n.º 17
0
def test_api_get_course_list(gk: GkApiClient):
    gk.get_course_list()
Exemplo n.º 18
0
def test_api_get_video_collection_list(gk: GkApiClient):
    col_list = gk.get_video_collection_list()
    assert col_list and isinstance(col_list, list)
    col = col_list[0]
    for key in {'collection_id'}:
        assert col.get(key) is not None, '{} 不存在'.format(key)
Exemplo n.º 19
0
def test_api_get_course_intro(gk: GkApiClient):
    gk.get_course_intro(48)
Exemplo n.º 20
0
def test_api_get_collection_video_list(gk: GkApiClient):
    v_list = gk.get_video_list_of(collection_id)
    assert v_list and isinstance(v_list, list)
    video = v_list[0]
    for key in {'article_id', 'is_sub'}:
        assert video.get(key) is not None, '{} 不存在'.format(key)
Exemplo n.º 21
0
def test_api_get_post_comments(gk: GkApiClient):
    res = gk.get_post_comments(109572)
    assert res and isinstance(res, list)
    comment = res[0]
    for key in {'user_name', 'like_count', 'comment_content', 'comment_ctime'}:
        assert comment.get(key) is not None, '{} 不存在'.format(key)
Exemplo n.º 22
0
def gk() -> GkApiClient:
    account = os.getenv('account')
    password = os.getenv('password')
    return GkApiClient(account=account, password=password)
Exemplo n.º 23
0
def gk() -> GkApiClient:
    return GkApiClient(None, None, no_login=True)