diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 910ab21..1613f2b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,3 +1,10 @@ +# Twitcaspy +# Copyright 2021 Alma-field +# See LICENSE for details. +# +# based on tweepy(https://github.com/tweepy/tweepy) +# Copyright (c) 2009-2021 Joshua Roesslein + name: Deploy on: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4a3866a..31796fd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,3 +1,10 @@ +# Twitcaspy +# Copyright 2021 Alma-field +# See LICENSE for details. +# +# based on tweepy(https://github.com/tweepy/tweepy) +# Copyright (c) 2009-2021 Joshua Roesslein + name: test on: [push, pull_request] @@ -18,7 +25,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install .[dev,test] + pip install .[test] - name: Run tests run: | python setup.py nosetests diff --git a/LICENSE b/LICENSE index b4ecd07..19623aa 100644 --- a/LICENSE +++ b/LICENSE @@ -19,3 +19,8 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +based on tweepy(https://github.com/tweepy/tweepy): +Copyright (c) 2009-2021 Joshua Roesslein +Released under the MIT license +https://github.com/tweepy/tweepy/blob/master/LICENSE diff --git a/README.md b/README.md index 3b3ecb8..3017493 100644 --- a/README.md +++ b/README.md @@ -9,14 +9,16 @@ [![Python Versions](https://img.shields.io/pypi/pyversions/twitcaspy?label=Python)](https://pypi.org/project/twitcaspy/) Twitcatting for Python +Python 3.7 - 3.9 are supported. ## Other language version - [English](https://github.com/Alma-field/twitcaspy/blob/master/README.md) - [Japanese](https://github.com/Alma-field/twitcaspy/blob/master/README_JA.md) ## Document - - [develop](https://twitcaspy.alma-field.com/en/latest) - - [latest (v1.0.2)](https://twitcaspy.alma-field.com/en/stable) + - [develop version](https://twitcaspy.alma-field.com/en/latest) + - [latest version(v1.1.0)](https://twitcaspy.alma-field.com/en/stable) + - [v1.1.0](https://twitcaspy.alma-field.com/en/1.1.0) - [v1.0.2](https://twitcaspy.alma-field.com/en/1.0.2) - [v1.0.1](https://twitcaspy.alma-field.com/en/1.0.1) - [v1.0.0](https://twitcaspy.alma-field.com/en/1.0.0) @@ -40,7 +42,28 @@ Alternatively, install directly from the GitHub repository: pip install git+https://github.com/Alma-field/twitcaspy.git ``` -Python 3.7 - 3.9 are supported. +## Examples +This is an execution example in the application scope. +Get the account name of ***@twitcasting_jp***. +```python +from twitcaspy import API, AppAuthHandler +auth = AppAuthHandler(client_id, client_secret) +api = API(auth) + +print(api.get_user_info(id='twitcasting_jp').user.name) +# > ツイキャス公式 +``` + +See in [examples](https://github.com/Alma-field/twitcaspy/tree/master/examples) for other examples and the entire code. +### Included example + - [Authorization](https://github.com/Alma-field/twitcaspy/tree/master/examples/auth) + - [AppAuthHandler](https://github.com/Alma-field/twitcaspy/tree/master/examples/auth/app.py) + - [GrantAuthHandler](https://github.com/Alma-field/twitcaspy/tree/master/examples/auth/grant.py) + - [ImplicitAuthHandler](https://github.com/Alma-field/twitcaspy/tree/master/examples/auth/implicit.py) + - [Realtime API](https://github.com/Alma-field/twitcaspy/blob/master/examples/realtime) + - [Webhook](https://github.com/Alma-field/twitcaspy/blob/master/examples/webhook) + - [Server](https://github.com/Alma-field/twitcaspy/blob/master/examples/webhook/server.py) + - [Client](https://github.com/Alma-field/twitcaspy/blob/master/examples/webhook/client.py) ## Source This library is based on: diff --git a/README_JA.md b/README_JA.md index 77d1570..aa2b649 100644 --- a/README_JA.md +++ b/README_JA.md @@ -9,6 +9,7 @@ [![Python Versions](https://img.shields.io/pypi/pyversions/twitcaspy?label=Python)](https://pypi.org/project/twitcaspy/) Python用Twitcattingクライアントライブラリ +Python 3.7 - 3.9 がサポートされています。 ## Other language version/他言語版 - [English/英語](README.md) @@ -16,7 +17,8 @@ Python用Twitcattingクライアントライブラリ ## ドキュメント - [開発版](https://twitcaspy.alma-field.com/ja/latest) - - [最新版 (v1.0.2)](https://twitcaspy.alma-field.com/ja/stable) + - [最新版 (v1.1.0)](https://twitcaspy.alma-field.com/ja/stable) + - [v1.1.0](https://twitcaspy.alma-field.com/ja/1.1.0) - [v1.0.2](https://twitcaspy.alma-field.com/ja/1.0.2) - [v1.0.1](https://twitcaspy.alma-field.com/ja/1.0.1) - [v1.0.0](https://twitcaspy.alma-field.com/ja/1.0.0) @@ -39,7 +41,28 @@ pip install . pip install git+https://github.com/Alma-field/twitcaspy.git ``` -Python 3.7 - 3.9 がサポートされています。 +## 例 +アプリケーションスコープでの実行例です。 +***@twitcasting_jp*** のアカウント名を取得します。 +```python +from twitcaspy import API, AppAuthHandler +auth = AppAuthHandler(client_id, client_secret) +api = API(auth) + +print(api.get_user_info(id='twitcasting_jp').user.name) +# > ツイキャス公式 +``` + +その他の例やコード全体は[examples](https://github.com/Alma-field/twitcaspy/tree/master/examples)内のコードをご覧ください。 +### 含まれている例 + - [Authorization](https://github.com/Alma-field/twitcaspy/tree/master/examples/auth) + - [AppAuthHandler](https://github.com/Alma-field/twitcaspy/tree/master/examples/auth/app.py) + - [GrantAuthHandler](https://github.com/Alma-field/twitcaspy/tree/master/examples/auth/grant.py) + - [ImplicitAuthHandler](https://github.com/Alma-field/twitcaspy/tree/master/examples/auth/implicit.py) + - [Realtime API](https://github.com/Alma-field/twitcaspy/blob/master/examples/realtime) + - [Webhook](https://github.com/Alma-field/twitcaspy/blob/master/examples/webhook) + - [Server](https://github.com/Alma-field/twitcaspy/blob/master/examples/webhook/server.py) + - [Client](https://github.com/Alma-field/twitcaspy/blob/master/examples/webhook/client.py) ## 出典 このライブラリは以下を参考にしています: diff --git a/docs/locale/ja/LC_MESSAGES/api.po b/docs/locale/ja/LC_MESSAGES/api.po index 69d5fbc..2898499 100644 --- a/docs/locale/ja/LC_MESSAGES/api.po +++ b/docs/locale/ja/LC_MESSAGES/api.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: twitcaspy 0.0.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-10-02 16:29+0900\n" +"POT-Creation-Date: 2021-10-05 14:12+0900\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: Alma-field\n" "Language-Team: LANGUAGE \n" @@ -93,10 +93,10 @@ msgstr "指定されたparserがParserインスタンスではない場合" #: twitcaspy.api.API.get_current_live:26 twitcaspy.api.API.get_gifts:16 #: twitcaspy.api.API.get_live_thumbnail_image:24 #: twitcaspy.api.API.get_movie_info:20 twitcaspy.api.API.get_movies_by_user:33 -#: twitcaspy.api.API.get_rtmp_url:16 twitcaspy.api.API.get_supporting_status:23 +#: twitcaspy.api.API.get_rtmp_url:16 twitcaspy.api.API.get_supporting_status:30 #: twitcaspy.api.API.get_user_info:22 twitcaspy.api.API.get_webhook_list:34 #: twitcaspy.api.API.get_webm_url:14 twitcaspy.api.API.incoming_webhook:27 -#: twitcaspy.api.API.post_comment:26 twitcaspy.api.API.register_webhook:31 +#: twitcaspy.api.API.post_comment:28 twitcaspy.api.API.register_webhook:31 #: twitcaspy.api.API.remove_webhook:31 twitcaspy.api.API.search_live_movies:37 #: twitcaspy.api.API.search_users:25 #: twitcaspy.api.API.set_current_live_hashtag:18 @@ -481,10 +481,10 @@ msgstr "戻り値の型" #: twitcaspy.api.API.get_comments:29 twitcaspy.api.API.get_current_live:21 #: twitcaspy.api.API.get_gifts:13 twitcaspy.api.API.get_movie_info:17 #: twitcaspy.api.API.get_movies_by_user:28 twitcaspy.api.API.get_rtmp_url:13 -#: twitcaspy.api.API.get_supporting_status:18 +#: twitcaspy.api.API.get_supporting_status:25 #: twitcaspy.api.API.get_user_info:17 twitcaspy.api.API.get_webhook_list:31 #: twitcaspy.api.API.get_webm_url:11 twitcaspy.api.API.incoming_webhook:22 -#: twitcaspy.api.API.post_comment:21 twitcaspy.api.API.register_webhook:25 +#: twitcaspy.api.API.post_comment:23 twitcaspy.api.API.register_webhook:25 #: twitcaspy.api.API.remove_webhook:25 twitcaspy.api.API.search_live_movies:29 #: twitcaspy.api.API.search_users:18 #: twitcaspy.api.API.set_current_live_hashtag:13 @@ -500,7 +500,7 @@ msgstr "" #: of twitcaspy.api.API.get_current_live:23 #: twitcaspy.api.API.get_live_thumbnail_image:21 #: twitcaspy.api.API.get_movies_by_user:30 -#: twitcaspy.api.API.get_supporting_status:20 +#: twitcaspy.api.API.get_supporting_status:27 #: twitcaspy.api.API.get_user_info:19 twitcaspy.api.API.supporting_list:26 msgid "If both id and screen_id are not specified" msgstr "idとscreen_idの両方が指定されていないとき" @@ -611,7 +611,7 @@ msgid "Returns information about the specified movie." msgstr "ライブ情報を取得します。" #: of twitcaspy.api.API.delete_comment:9 twitcaspy.api.API.get_comments:4 -#: twitcaspy.api.API.get_movie_info:3 +#: twitcaspy.api.API.get_movie_info:3 twitcaspy.api.API.post_comment:4 msgid "|movie_id|" msgstr "ライブのID" @@ -997,7 +997,7 @@ msgstr "コメントを投稿します。" msgid "It can be executed only on a user-by-user basis." msgstr "ユーザ単位でのみ実行可能です。" -#: of twitcaspy.api.API.post_comment:4 +#: of twitcaspy.api.API.post_comment:6 msgid "| Comment text to post. | Must be 1 to 140 characters." msgstr "" @@ -1009,7 +1009,7 @@ msgstr "投稿するコメント文章" msgid "Must be 1 to 140 characters." msgstr "1〜140文字である必要があります。" -#: of twitcaspy.api.API.post_comment:7 +#: of twitcaspy.api.API.post_comment:9 msgid "" "| Simultaneous posting to SNS. | (Valid only when the user is linked with" " Twitter or Facebook.) | 'reply' : Post in a format that replies to the " @@ -1036,7 +1036,7 @@ msgstr "'normal' : 通常の投稿" msgid "'none' : No SNS posts." msgstr "'none' : SNS投稿無し" -#: of twitcaspy.api.API.post_comment:14 +#: of twitcaspy.api.API.post_comment:16 msgid "" "| |attribute| | |latelimit| | **movie_id** : " ":class:`~twitcaspy.models.Raw` (:class:`str`) |movie_id| | " @@ -1048,11 +1048,11 @@ msgstr "" msgid "**comment** : :class:`~twitcaspy.models.Comment`" msgstr "" -#: of twitcaspy.api.API.post_comment:23 +#: of twitcaspy.api.API.post_comment:25 msgid "When comment is not 1-140 characters." msgstr "comment が 1-140 文字でないとき" -#: of twitcaspy.api.API.post_comment:27 +#: of twitcaspy.api.API.post_comment:29 msgid "https://apiv2-doc.twitcasting.tv/#post-comment" msgstr "" @@ -1169,27 +1169,43 @@ msgstr "対象ユーザの id または screen_id" msgid "target user id or screen_id" msgstr "対象ユーザの id または screen_id" -#: of twitcaspy.api.API.get_supporting_status:12 +#: of twitcaspy.api.API.get_supporting_status:14 +msgid "" +"Note that unlike :class:`~twitcaspy.models.Supporter`, there is no " +"supported_time attribute." +msgstr ":class:`~twitcaspy.models.Supporter` とは異なり、supported_time 属性がないことに注意してください。" + +#: of twitcaspy.api.API.get_supporting_status:17 msgid "" "| |attribute| | |latelimit| | **is_supporting** : " ":class:`~twitcaspy.models.Raw` (:class:`bool`) The status of whether " -"(id/screen_id) supported target_user_id. | **target_user** : " -":class:`~twitcaspy.models.User` Target user information" +"(id/screen_id) supported target_user_id. | **supported** : " +":class:`~twitcaspy.models.Raw` (:class:`int`) Unix time stamp of " +"supported datetime | **target_user** : :class:`~twitcaspy.models.User` " +"Target user information" msgstr "" #: of twitcaspy.api.API.get_supporting_status msgid "" -"**is_supporting** : :class:`~twitcaspy.models.Raw` (:class:`bool`) " -"The status of whether (id/screen_id) supported target_user_id." +"**is_supporting** : :class:`~twitcaspy.models.Raw` (:class:`bool`) The " +"status of whether (id/screen_id) supported target_user_id." msgstr "" "**is_supporting** : :class:`~twitcaspy.models.Raw` (:class:`bool`) " "(id/screen_id)がtarget_user_idをサポートしているかの状況を取得します。" +#: of twitcaspy.api.API.get_supporting_status +msgid "" +"**supported** : :class:`~twitcaspy.models.Raw` (:class:`int`) Unix time " +"stamp of supported datetime" +msgstr "" +"**supported** : :class:`~twitcaspy.models.Raw` (:class:`int`) " +"サポートした日時のunixタイムスタンプ" + #: of twitcaspy.api.API.get_supporting_status msgid "**target_user** : :class:`~twitcaspy.models.User` Target user information" msgstr "**target_user** : :class:`~twitcaspy.models.User` 対象ユーザ情報" -#: of twitcaspy.api.API.get_supporting_status:24 +#: of twitcaspy.api.API.get_supporting_status:31 msgid "https://apiv2-doc.twitcasting.tv/#get-supporting-status" msgstr "" diff --git a/docs/locale/ja/LC_MESSAGES/auth.po b/docs/locale/ja/LC_MESSAGES/auth.po index 8c6a67a..dd6eb0a 100644 --- a/docs/locale/ja/LC_MESSAGES/auth.po +++ b/docs/locale/ja/LC_MESSAGES/auth.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: twitcaspy 0.0.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-06-20 17:17+0900\n" +"POT-Creation-Date: 2021-10-04 15:58+0900\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -34,7 +34,9 @@ msgstr "" #: of twitcaspy.auth.app.AppAuthHandler twitcaspy.auth.auth.AuthHandler #: twitcaspy.auth.grant.GrantAuthHandler +#: twitcaspy.auth.grant.GrantAuthHandler.set_access_token #: twitcaspy.auth.implicit.ImplicitAuthHandler +#: twitcaspy.auth.implicit.ImplicitAuthHandler.set_access_token #: twitcaspy.auth.oauth.basic.OAuth2Basic #: twitcaspy.auth.oauth.bearer.OAuth2Bearer msgid "Parameters" @@ -107,6 +109,31 @@ msgstr "" msgid "Get the authorization URL to redirect the user" msgstr "ユーザー認証のためのリダイレクトURLを取得します" +#: of twitcaspy.auth.grant.GrantAuthHandler.set_access_token:1 +#: twitcaspy.auth.implicit.ImplicitAuthHandler.set_access_token:1 +msgid "Set bearer_token." +msgstr "Bearerトークンをセットします。" + +#: of twitcaspy.auth.grant.GrantAuthHandler.set_access_token:3 +#: twitcaspy.auth.implicit.ImplicitAuthHandler.set_access_token:3 +msgid "bearer_token to use" +msgstr "使用するBearerトークン" + +#: of twitcaspy.auth.grant.GrantAuthHandler.set_access_token +#: twitcaspy.auth.implicit.ImplicitAuthHandler.set_access_token +msgid "Returns" +msgstr "" + +#: of twitcaspy.auth.grant.GrantAuthHandler.set_access_token +#: twitcaspy.auth.implicit.ImplicitAuthHandler.set_access_token +msgid "Return type" +msgstr "" + +#: of twitcaspy.auth.grant.GrantAuthHandler.set_access_token:7 +#: twitcaspy.auth.implicit.ImplicitAuthHandler.set_access_token:7 +msgid ":class:`None`" +msgstr "" + #: ../../auth.rst:35 msgid "Implicit handler" msgstr "" diff --git a/docs/locale/ja/LC_MESSAGES/models.po b/docs/locale/ja/LC_MESSAGES/models.po index 44038ca..e08a136 100644 --- a/docs/locale/ja/LC_MESSAGES/models.po +++ b/docs/locale/ja/LC_MESSAGES/models.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: twitcaspy 0.0.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-06-24 00:19+0900\n" +"POT-Creation-Date: 2021-10-05 14:01+0900\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -54,8 +54,7 @@ msgstr "" #: twitcaspy.models.comment.Comment:1 twitcaspy.models.gift.Gift:1 #: twitcaspy.models.live.Live:1 twitcaspy.models.movie.Movie:1 #: twitcaspy.models.result.Result:1 twitcaspy.models.subcategory.SubCategory:1 -#: twitcaspy.models.supporter.Supporter:1 twitcaspy.models.user.User:1 -#: twitcaspy.models.webhook.WebHook:1 +#: twitcaspy.models.user.User:1 twitcaspy.models.webhook.WebHook:1 msgid "Bases: :class:`twitcaspy.models.model.Model`" msgstr "" @@ -147,18 +146,19 @@ msgstr "プロフィール文章" msgid "User level" msgstr "ユーザのレベル" -#: of twitcaspy.models.latelimit.LateLimit:7 +#: of twitcaspy.models.comment.Comment:31 +#: twitcaspy.models.latelimit.LateLimit:7 #: twitcaspy.models.latelimit.LateLimit:13 #: twitcaspy.models.latelimit.LateLimit:19 twitcaspy.models.movie.Movie:61 -#: twitcaspy.models.movie.Movie:85 twitcaspy.models.movie.Movie:110 -#: twitcaspy.models.movie.Movie:117 twitcaspy.models.movie.Movie:123 -#: twitcaspy.models.subcategory.SubCategory:19 +#: twitcaspy.models.movie.Movie:85 twitcaspy.models.movie.Movie:97 +#: twitcaspy.models.movie.Movie:116 twitcaspy.models.movie.Movie:123 +#: twitcaspy.models.movie.Movie:129 twitcaspy.models.subcategory.SubCategory:19 #: twitcaspy.models.supporter.Supporter:38 -#: twitcaspy.models.supporter.Supporter:58 -#: twitcaspy.models.supporter.Supporter:66 #: twitcaspy.models.supporter.Supporter:72 -#: twitcaspy.models.supporter.Supporter:78 -#: twitcaspy.models.supporter.Supporter:86 twitcaspy.models.user.User:38 +#: twitcaspy.models.supporter.Supporter:80 +#: twitcaspy.models.supporter.Supporter:86 +#: twitcaspy.models.supporter.Supporter:92 +#: twitcaspy.models.supporter.Supporter:100 twitcaspy.models.user.User:38 #: twitcaspy.models.user.User:59 twitcaspy.models.user.User:68 #: twitcaspy.models.user.User:77 msgid ":class:`int`" @@ -169,7 +169,7 @@ msgid "The last live ID by the user" msgstr "ユーザが最後に配信したライブのID" #: of twitcaspy.models.gift.Gift:28 twitcaspy.models.movie.Movie:31 -#: twitcaspy.models.movie.Movie:37 twitcaspy.models.movie.Movie:131 +#: twitcaspy.models.movie.Movie:37 twitcaspy.models.movie.Movie:137 #: twitcaspy.models.supporter.Supporter:44 twitcaspy.models.user.User:44 msgid ":class:`str` or :class:`None`" msgstr "" @@ -179,12 +179,12 @@ msgid "Whether it is currently live streamed" msgstr "現在ライブ配信中かどうか" #: of twitcaspy.models.movie.Movie:49 twitcaspy.models.movie.Movie:55 -#: twitcaspy.models.movie.Movie:97 twitcaspy.models.movie.Movie:103 +#: twitcaspy.models.movie.Movie:103 twitcaspy.models.movie.Movie:109 #: twitcaspy.models.supporter.Supporter:50 twitcaspy.models.user.User:50 msgid ":class:`bool`" msgstr "" -#: of twitcaspy.models.supporter.Supporter:54 twitcaspy.models.user.User:54 +#: of twitcaspy.models.supporter.Supporter:68 twitcaspy.models.user.User:54 msgid "Number of user supporters." msgstr "ユーザーのサポーターの数" @@ -196,25 +196,25 @@ msgstr "" "`2018-09-03 更新 " "`_" -#: of twitcaspy.models.supporter.Supporter:55 -#: twitcaspy.models.supporter.Supporter:63 -#: twitcaspy.models.supporter.Supporter:83 twitcaspy.models.user.User:56 +#: of twitcaspy.models.supporter.Supporter:69 +#: twitcaspy.models.supporter.Supporter:77 +#: twitcaspy.models.supporter.Supporter:97 twitcaspy.models.user.User:56 #: twitcaspy.models.user.User:65 twitcaspy.models.user.User:74 msgid "Returns a fixed value of 0." msgstr "固定値0を返します。" -#: of twitcaspy.models.supporter.Supporter:56 -#: twitcaspy.models.supporter.Supporter:64 -#: twitcaspy.models.supporter.Supporter:84 twitcaspy.models.user.User:57 +#: of twitcaspy.models.supporter.Supporter:70 +#: twitcaspy.models.supporter.Supporter:78 +#: twitcaspy.models.supporter.Supporter:98 twitcaspy.models.user.User:57 #: twitcaspy.models.user.User:66 twitcaspy.models.user.User:75 msgid "This parameter is deprecated." msgstr "このパラメータは非推奨です。" -#: of twitcaspy.models.supporter.Supporter:62 twitcaspy.models.user.User:63 +#: of twitcaspy.models.supporter.Supporter:76 twitcaspy.models.user.User:63 msgid "Number supported user by the user." msgstr "ユーザーがサポートしている数" -#: of twitcaspy.models.supporter.Supporter:82 twitcaspy.models.user.User:72 +#: of twitcaspy.models.supporter.Supporter:96 twitcaspy.models.user.User:72 msgid "Date and time when this account was created." msgstr "このアカウントの作成日時" @@ -227,10 +227,10 @@ msgstr "" "`_" #: of twitcaspy.models.app.App:22 twitcaspy.models.category.Category:22 -#: twitcaspy.models.comment.Comment:28 twitcaspy.models.gift.Gift:73 -#: twitcaspy.models.latelimit.LateLimit:28 twitcaspy.models.movie.Movie:134 +#: twitcaspy.models.comment.Comment:34 twitcaspy.models.gift.Gift:73 +#: twitcaspy.models.latelimit.LateLimit:28 twitcaspy.models.movie.Movie:140 #: twitcaspy.models.subcategory.SubCategory:22 -#: twitcaspy.models.supporter.Supporter:89 twitcaspy.models.user.User:80 +#: twitcaspy.models.supporter.Supporter:103 twitcaspy.models.user.User:80 #: twitcaspy.models.webhook.WebHook:19 msgid "References" msgstr "" @@ -343,50 +343,54 @@ msgstr "配信地域(国コード)" msgid "stream time (seconds)" msgstr "配信時間(秒)" -#: of twitcaspy.models.movie.Movie:89 -msgid "" -"Converted Unix time stamp of stream start date and time to " -":class:`datetime.datetime` type" -msgstr "配信開始日時のunixタイムスタンプを :class:`datetime.datetime` 型へ変換したもの" +#: of twitcaspy.models.comment.Comment:23 twitcaspy.models.movie.Movie:89 +msgid "Converted created_time to :class:`datetime.datetime` type" +msgstr "created_timeを :class:`datetime.datetime` 型へ変換したもの" #: of twitcaspy.models.comment.Comment:25 #: twitcaspy.models.latelimit.LateLimit:25 twitcaspy.models.movie.Movie:91 +#: twitcaspy.models.supporter.Supporter:58 +#: twitcaspy.models.supporter.Supporter:64 msgid ":class:`datetime.datetime`" msgstr ":class:`datetime.datetime`" #: of twitcaspy.models.movie.Movie:95 +msgid "Unix time stamp of stream start datetime" +msgstr "配信開始日時のunixタイムスタンプ" + +#: of twitcaspy.models.movie.Movie:101 msgid "Whether it is a collaboration stream" msgstr "コラボ配信かどうか" -#: of twitcaspy.models.movie.Movie:101 +#: of twitcaspy.models.movie.Movie:107 msgid "Whether to need the secret word" msgstr "合言葉配信かどうか" -#: of twitcaspy.models.movie.Movie:107 +#: of twitcaspy.models.movie.Movie:113 msgid "Maximum number of simultaneous viewers" msgstr "最大同時視聴数" -#: of twitcaspy.models.movie.Movie:108 +#: of twitcaspy.models.movie.Movie:114 msgid "(0 if streaming now.)" msgstr "(配信中の場合0)" -#: of twitcaspy.models.movie.Movie:114 +#: of twitcaspy.models.movie.Movie:120 msgid "Current number of simultaneous viewers" msgstr "現在の同時視聴者数" -#: of twitcaspy.models.movie.Movie:115 +#: of twitcaspy.models.movie.Movie:121 msgid "(0 if not streaming now.)" msgstr "(配信中ではない場合0)" -#: of twitcaspy.models.movie.Movie:121 +#: of twitcaspy.models.movie.Movie:127 msgid "Total number of viewers" msgstr "総視聴者数" -#: of twitcaspy.models.movie.Movie:127 +#: of twitcaspy.models.movie.Movie:133 msgid "URL for HTTP Live Streaming playback" msgstr "HTTP Live Streaming再生用のURL" -#: of twitcaspy.models.movie.Movie:128 +#: of twitcaspy.models.movie.Movie:134 msgid "" "`2019-04-17 update " "`_" @@ -394,13 +398,13 @@ msgstr "" "`2019-04-17 更新 " "`_" -#: of twitcaspy.models.movie.Movie:129 +#: of twitcaspy.models.movie.Movie:135 msgid "" "Changed the URL of the hls_url parameter from `http` to `https` " "|google_translate_ja_en|" msgstr "hls_url パラメータの URL を http から https に変更しました。" -#: of twitcaspy.models.movie.Movie:135 +#: of twitcaspy.models.movie.Movie:141 msgid "https://apiv2-doc.twitcasting.tv/#movie-object" msgstr "" @@ -424,13 +428,11 @@ msgstr "コメント本文" msgid "Comment contributor information" msgstr "コメント投稿者の情報" -#: of twitcaspy.models.comment.Comment:23 -msgid "" -"Converted Unix time stamp of comment posting date and time to " -":class:`datetime.datetime` type" -msgstr "コメント投稿日時のunixタイムスタンプを :class:`datetime.datetime` 型へ変換したもの" - #: of twitcaspy.models.comment.Comment:29 +msgid "Unix time stamp of comment posting datetime" +msgstr "コメント投稿日時のunixタイムスタンプ" + +#: of twitcaspy.models.comment.Comment:35 msgid "https://apiv2-doc.twitcasting.tv/#comment-object" msgstr "" @@ -486,19 +488,45 @@ msgstr "" msgid "Supporter class" msgstr "" +#: of twitcaspy.models.supporter.Supporter:1 +msgid "Bases: :class:`twitcaspy.models.user.User`" +msgstr "ベースクラス: :class:`~twitcaspy.models.User`" + #: of twitcaspy.models.supporter.Supporter:1 msgid "Supporter Object" msgstr "" -#: of twitcaspy.models.supporter.Supporter:70 +#: of twitcaspy.models.supporter.Supporter:54 +msgid "Unix time stamp of supported datetime" +msgstr "サポートした日時のunixタイムスタンプ" + +#: of twitcaspy.models.supporter.Supporter:55 +msgid "" +"`2021-09-29 update " +"`_" +msgstr "" +"`2021-09-29 更新 " +"`_" + +#: of twitcaspy.models.supporter.Supporter:56 +msgid "" +"Added 'unix time stamp of supported datetime' to " +"SupporterUser object of response |google_translate_ja_en|" +msgstr "レスポンスの SupporterUser object にサポートした日時のunixタイムスタンプ supported を追加しました" + +#: of twitcaspy.models.supporter.Supporter:62 +msgid "Converted supported to :class:`datetime.datetime` type" +msgstr "supportedを :class:`datetime.datetime` 型へ変換したもの" + +#: of twitcaspy.models.supporter.Supporter:84 msgid "Item score" msgstr "" -#: of twitcaspy.models.supporter.Supporter:76 +#: of twitcaspy.models.supporter.Supporter:90 msgid "Cumulative score" msgstr "" -#: of twitcaspy.models.supporter.Supporter:90 +#: of twitcaspy.models.supporter.Supporter:104 msgid "https://apiv2-doc.twitcasting.tv/#supporteruser-object" msgstr "" @@ -621,9 +649,3 @@ msgstr "パーサーがモデルのインスタンスを作成するために使 #: of twitcaspy.models.factory.ModelFactory:2 msgid "You may subclass this factory to add your own extended models." msgstr "独自のモデルを追加する場合は、このクラスを継承してください。" - -#~ msgid "..autoclass:: twitcaspy.models.Comment" -#~ msgstr "" - -#~ msgid "show-inheritance" -#~ msgstr "" diff --git a/examples/app/app.py b/examples/auth/app.py similarity index 100% rename from examples/app/app.py rename to examples/auth/app.py diff --git a/examples/auth/grant.py b/examples/auth/grant.py new file mode 100644 index 0000000..6ef3e91 --- /dev/null +++ b/examples/auth/grant.py @@ -0,0 +1,47 @@ +# Twitcaspy +# Copyright 2021 Alma-field +# See LICENSE for details. + +from twitcaspy import API, GrantAuthHandler + +# The client id and/or secret can be found on your application's Details page +# located at select app in https://twitcasting.tv/developer.php +# (in "details" tab) +CLIENT_ID = '' +CLIENT_SECRET = '' +CALLBACK_URL = '' + +auth = GrantAuthHandler(CLIENT_ID, CLIENT_SECRET, CALLBACK_URL) + +# Open webbrowser +print(f'URL: {auth.get_authorization_url()}') +webbrowser.open(auth.get_authorization_url()) +redirect_uri = input('input redirect_uri > ') +auth.fetch_token(redirect_uri) +api = API(auth) + +# Get Verify credentials +credential = api.verify_credentials() +# If you uncomment it, the Response body is displayed. +# (コメントアウトを外すとレスポンス本体が表示されます。) +#print(credential._json) + +# If you uncomment it, +# the name of the application you are using will be displayed. +# (コメントアウトを外すと使用しているアプリケーションの名前が表示されます。) +#print(credential.app.name) + +# If the authentication was successful, +# you should see the name of the account print out +# (認証に成功している場合、アカウント名が表示されます。) +print(credential.user.name) + +# Target User ID and screen ID +user_id = '182224938' +screen_id = 'twitcasting_jp' + +user_info = api.get_user_info(id=user_id) +# If the authentication was successful, you should +# see the name of the account print out +# (認証に成功している場合、アカウント名が表示されます。) +print(user_info.user.name) diff --git a/examples/auth/implicit.py b/examples/auth/implicit.py new file mode 100644 index 0000000..d283343 --- /dev/null +++ b/examples/auth/implicit.py @@ -0,0 +1,48 @@ +# Twitcaspy +# Copyright 2021 Alma-field +# See LICENSE for details. + +import webbrowser +from twitcaspy import API, ImplicitAuthHandler + +# The client id and/or secret can be found on your application's Details page +# located at select app in https://twitcasting.tv/developer.php +# (in "details" tab) +CLIENT_ID = '' +CLIENT_SECRET = '' +CALLBACK_URL = '' + +auth = ImplicitAuthHandler(CLIENT_ID, CLIENT_SECRET, CALLBACK_URL) + +# Open webbrowser +print(f'URL: {auth.get_authorization_url()}') +webbrowser.open(auth.get_authorization_url()) +redirect_uri = input('input redirect_uri > ') +auth.fetch_token(redirect_uri) +api = API(auth) + +# Get Verify credentials +credential = api.verify_credentials() +# If you uncomment it, the Response body is displayed. +# (コメントアウトを外すとレスポンス本体が表示されます。) +#print(credential._json) + +# If you uncomment it, +# the name of the application you are using will be displayed. +# (コメントアウトを外すと使用しているアプリケーションの名前が表示されます。) +#print(credential.app.name) + +# If the authentication was successful, +# you should see the name of the account print out +# (認証に成功している場合、アカウント名が表示されます。) +print(credential.user.name) + +# Target User ID and screen ID +user_id = '182224938' +screen_id = 'twitcasting_jp' + +user_info = api.get_user_info(id=user_id) +# If the authentication was successful, you should +# see the name of the account print out +# (認証に成功している場合、アカウント名が表示されます。) +print(user_info.user.name) diff --git a/examples/realtime/lives.py b/examples/realtime/lives.py new file mode 100644 index 0000000..721b408 --- /dev/null +++ b/examples/realtime/lives.py @@ -0,0 +1,62 @@ +# Twitcaspy +# Copyright 2021 Alma-field +# See LICENSE for details. + +# Before running this code, run the following command: +# このコードを実行する前に、以下のコマンドを実行してください。 +# pip install twitcaspy[realtime] + +from base64 import b64encode +# The client id and/or secret can be found on your application's Details page +# located at select app in https://twitcasting.tv/developer.php +# (in "details" tab) +CLIENT_ID = '' +CLIENT_SECRET = '' +# generate basic token +BASIC_TOKEN = b64encode(f'{CLIENT_ID}:{CLIENT_SECRET}'.encode('utf-8')).decode('utf-8') +# create Authorization header +HEADERS = {'Authorization': f'Basic {BASIC_TOKEN}'} +# create socket url +SOCKET_URL = f'wss://{CLIENT_ID}:{CLIENT_SECRET}@realtime.twitcasting.tv/lives' + +from twitcaspy.parsers import ModelParser +# set parse keywords +parser_kwargs = {'movies': ['live', True]} +parser = ModelParser() + +import json + +def on_message(ws, message): + try: + # try parse from json text + data = json.loads(message) + except: + print(type(message)) + print(message) + return + if 'hello' in data: + # first message + print(f'hello: {data["hello"]}') + else: + # parse object + lives = parser.parse(payload=data, payload_type=parser_kwargs) + flag = True + for live in lives.movies: + if flag: + flag = False + else: + print('-'*25) + # shoe user name and screen name + print(f' name: {live.broadcaster.name}({live.broadcaster.screen_id})') + # show live title and subtitle + print(f'title: {live.movie.title}({live.movie.subtitle})') + print('-'*50) + +if __name__ == "__main__": + import websocket + #websocket.enableTrace(True) + # create websocket instance + ws = websocket.WebSocketApp( + SOCKET_URL, header=HEADERS, on_message=on_message) + # run websocket + ws.run_forever() diff --git a/examples/webhook/sender.py b/examples/webhook/client.py similarity index 68% rename from examples/webhook/sender.py rename to examples/webhook/client.py index 7dd0b2d..60c93a4 100644 --- a/examples/webhook/sender.py +++ b/examples/webhook/client.py @@ -2,11 +2,17 @@ # Copyright 2021 Alma-field # See LICENSE for details. +# If you actually want to use webhooks, +# you don't need to write this program. +# (実際にWebhookを使用する場合は、 +# このプログラムを作成する必要はありません。) + import requests import json def main(): cassettes_file = '../../cassettes/testincomingwebhook.json' + # load test webhook data with open(cassettes_file, "r", encoding='utf-8')as file: data = json.load(file) response = requests.post( diff --git a/examples/webhook/server.py b/examples/webhook/server.py index eb086aa..cf9c138 100644 --- a/examples/webhook/server.py +++ b/examples/webhook/server.py @@ -2,6 +2,10 @@ # Copyright 2021 Alma-field # See LICENSE for details. +# Before running this code, run the following command: +# このコードを実行する前に、以下のコマンドを実行してください。 +# pip install twitcaspy[webhook] + from flask import Flask, request, make_response, jsonify, abort app = Flask(__name__) @@ -10,20 +14,19 @@ @app.route('/', methods=['GET', 'POST']) def main(): if request.method == 'POST': - try: - webhook = api.incoming_webhook(request.json) - #Show Parse Result - print(f'signature : {webhook.signature}') - print(f'user_id : {webhook.broadcaster.id}') - print(f'title : {webhook.movie.title}') - except TwitcaspyException: - abort(404) + webhook = api.incoming_webhook(request.json) + #Show Parse Result + print(f'signature : {webhook.signature}') + print(f'user_id : {webhook.broadcaster.id}') + print(f'title : {webhook.movie.title}') return make_response(jsonify({'message':'OK'})) if __name__ == '__main__': import json cassettes_file = '../../cassettes/testincomingwebhook.json' + # load test webhook data with open(cassettes_file, "r", encoding='utf-8')as file: data = json.load(file) + # set signature to api instance api.signature = data['signature'] app.run(debug=True) diff --git a/setup.py b/setup.py index 2cff0ca..8207288 100644 --- a/setup.py +++ b/setup.py @@ -1,17 +1,17 @@ +# Twitcaspy +# Copyright 2021 Alma-field +# See LICENSE for details. + import re from setuptools import find_packages, setup -with open("README.md") as file: +with open("README.md", encoding='utf-8') as file: long_description = file.read() tests_require = [ "nose>=1.3.7,<2", "vcrpy>=4.1.1,<5", - "python-dotenv>=0.17.1,<1", -] - -examples_require = [ - "flask>=2.0.1,<3" + "python-dotenv>=0.19.0,<1", ] setup( @@ -21,15 +21,16 @@ "Issue Tracker": "https://github.com/Alma-field/twitcaspy/issues", "Source Code": "https://github.com/Alma-field/twitcaspy", }, - packages=find_packages(exclude=["tests"]), + packages=find_packages(exclude=["tests", "webhook", "realtime"]), install_requires=[ - "requests>=2.25.1,<3", + "requests>=2.26.0,<3", "requests_oauthlib>=1.3.0,<2", ], tests_require=tests_require, extras_require={ "test": tests_require, - "example": examples_require, + "webhook": ["flask>=2.0.1,<3"], + "realtime": ["websocket-client>=1.2.1,<2"] }, test_suite="nose.collector", keywords="twitcasting library", diff --git a/tests/config.py b/tests/config.py index 51bc106..8290d08 100644 --- a/tests/config.py +++ b/tests/config.py @@ -1,3 +1,10 @@ +# Twitcaspy +# Copyright 2021 Alma-field +# See LICENSE for details. +# +# based on tweepy(https://github.com/tweepy/tweepy) +# Copyright (c) 2009-2021 Joshua Roesslein + from os import environ from unittest import TestCase diff --git a/tests/test_api.py b/tests/test_api.py index 3cfd114..b432751 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -1,3 +1,10 @@ +# Twitcaspy +# Copyright 2021 Alma-field +# See LICENSE for details. +# +# based on tweepy(https://github.com/tweepy/tweepy) +# Copyright (c) 2009-2021 Joshua Roesslein + from nose.tools import ok_, eq_, raises from twitcaspy import API @@ -104,6 +111,7 @@ def testgetsupportingstatus(self): data = self.api.get_supporting_status( target_user_id=target_user_id, id=user_id) ok_(hasattr(data, 'is_supporting')) + ok_(hasattr(data, 'supported')) ok_(hasattr(data, 'target_user')) ok_(isinstance(data.target_user, User)) eq_(data.target_user.screen_id, target_user_id) diff --git a/tests/test_auth.py b/tests/test_auth.py index c59ade5..0aa120a 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -1,3 +1,10 @@ +# Twitcaspy +# Copyright 2021 Alma-field +# See LICENSE for details. +# +# based on tweepy(https://github.com/tweepy/tweepy) +# Copyright (c) 2009-2021 Joshua Roesslein + from unittest import TestCase from nose.tools import ok_ diff --git a/twitcaspy/__init__.py b/twitcaspy/__init__.py index afd0584..2ffc458 100644 --- a/twitcaspy/__init__.py +++ b/twitcaspy/__init__.py @@ -5,7 +5,7 @@ """ Twitcaspy : Twitcasting API library """ -__version__ = '1.0.2' +__version__ = '1.1.0' __author__ = 'Alma-field' __license__ = 'MIT' diff --git a/twitcaspy/api.py b/twitcaspy/api.py index 4bad47d..341d3fe 100644 --- a/twitcaspy/api.py +++ b/twitcaspy/api.py @@ -1,3 +1,10 @@ +# Twitcaspy +# Copyright 2021 Alma-field +# See LICENSE for details. +# +# based on tweepy(https://github.com/tweepy/tweepy) +# Copyright (c) 2009-2021 Joshua Roesslein + import functools import logging import json @@ -703,7 +710,10 @@ def get_gifts(self, **kwargs): 'GET', '/gifts', endpoint_parameters=('slice_id'), **kwargs) - @payload(is_supporting=['raw', False], target_user=['user', False]) + @payload( + is_supporting=['raw', False], + supported=['raw', False], + target_user=['user', False]) def get_supporting_status( self, target_user_id, *, id=None, screen_id=None, **kwargs): """get_supporting_status(target_user_id, *, id=None, screen_id=None) @@ -721,6 +731,11 @@ def get_supporting_status( target_user_id: :class:`str` | target user id or screen_id + Warnings + -------- + Note that unlike :class:`~twitcaspy.models.Supporter`, + there is no supported_time attribute. + Returns ------- :class:`~twitcaspy.models.Result` @@ -728,6 +743,8 @@ def get_supporting_status( | |latelimit| | **is_supporting** : :class:`~twitcaspy.models.Raw` (:class:`bool`) The status of whether (id/screen_id) supported target_user_id. + | **supported** : :class:`~twitcaspy.models.Raw` (:class:`int`) + Unix time stamp of supported datetime | **target_user** : :class:`~twitcaspy.models.User` Target user information diff --git a/twitcaspy/auth/app.py b/twitcaspy/auth/app.py index d366b5d..b28b3da 100644 --- a/twitcaspy/auth/app.py +++ b/twitcaspy/auth/app.py @@ -1,6 +1,9 @@ # Twitcaspy # Copyright 2021 Alma-field # See LICENSE for details. +# +# based on tweepy(https://github.com/tweepy/tweepy) +# Copyright (c) 2009-2021 Joshua Roesslein from .auth import AuthHandler diff --git a/twitcaspy/auth/auth.py b/twitcaspy/auth/auth.py index 2989ea2..51ababf 100644 --- a/twitcaspy/auth/auth.py +++ b/twitcaspy/auth/auth.py @@ -1,6 +1,9 @@ # Twitcaspy # Copyright 2021 Alma-field # See LICENSE for details. +# +# based on tweepy(https://github.com/tweepy/tweepy) +# Copyright (c) 2009-2021 Joshua Roesslein class AuthHandler: """AuthHandler Base Class diff --git a/twitcaspy/auth/grant.py b/twitcaspy/auth/grant.py index 122aec2..aaf5dfd 100644 --- a/twitcaspy/auth/grant.py +++ b/twitcaspy/auth/grant.py @@ -1,6 +1,9 @@ # Twitcaspy # Copyright 2021 Alma-field # See LICENSE for details. +# +# based on tweepy(https://github.com/tweepy/tweepy) +# Copyright (c) 2009-2021 Joshua Roesslein from requests_oauthlib import OAuth2Session @@ -62,3 +65,19 @@ def fetch_token(self, authorization_response): self.auth = OAuth2Bearer(self.oauth.token['access_token']) except Exception as e: raise TwitcaspyException(e) + + def set_access_token(self, bearer_token): + """set_access_token(bearer_token) + + | Set bearer_token. + + Parameters + ---------- + bearer_token: :class:`str` + bearer_token to use + + Returns + ------- + :class:`None` + """ + self.auth = OAuth2Bearer(bearer_token) diff --git a/twitcaspy/auth/implicit.py b/twitcaspy/auth/implicit.py index a78ccf8..cfe6b69 100644 --- a/twitcaspy/auth/implicit.py +++ b/twitcaspy/auth/implicit.py @@ -1,6 +1,9 @@ # Twitcaspy # Copyright 2021 Alma-field # See LICENSE for details. +# +# based on tweepy(https://github.com/tweepy/tweepy) +# Copyright (c) 2009-2021 Joshua Roesslein from requests_oauthlib import OAuth2Session from oauthlib.oauth2 import MobileApplicationClient @@ -58,3 +61,19 @@ def fetch_token(self, authorization_response): self.auth = OAuth2Bearer(self.oauth.token['access_token']) except Exception as e: raise TwitcaspyException(e) + + def set_access_token(self, bearer_token): + """set_access_token(bearer_token) + + | Set bearer_token. + + Parameters + ---------- + bearer_token: :class:`str` + bearer_token to use + + Returns + ------- + :class:`None` + """ + self.auth = OAuth2Bearer(bearer_token) diff --git a/twitcaspy/auth/oauth/basic.py b/twitcaspy/auth/oauth/basic.py index 18e3903..d0283ca 100644 --- a/twitcaspy/auth/oauth/basic.py +++ b/twitcaspy/auth/oauth/basic.py @@ -1,6 +1,9 @@ # Twitcaspy # Copyright 2021 Alma-field # See LICENSE for details. +# +# based on tweepy(https://github.com/tweepy/tweepy) +# Copyright (c) 2009-2021 Joshua Roesslein from base64 import b64encode diff --git a/twitcaspy/auth/oauth/bearer.py b/twitcaspy/auth/oauth/bearer.py index 2c2cf64..adeeab2 100644 --- a/twitcaspy/auth/oauth/bearer.py +++ b/twitcaspy/auth/oauth/bearer.py @@ -1,6 +1,9 @@ # Twitcaspy # Copyright 2021 Alma-field # See LICENSE for details. +# +# based on tweepy(https://github.com/tweepy/tweepy) +# Copyright (c) 2009-2021 Joshua Roesslein from requests.auth import AuthBase diff --git a/twitcaspy/errors.py b/twitcaspy/errors.py index 761d987..d4889b9 100644 --- a/twitcaspy/errors.py +++ b/twitcaspy/errors.py @@ -1,6 +1,9 @@ # Twitcaspy # Copyright 2021 Alma-field # See LICENSE for details. +# +# based on tweepy(https://github.com/tweepy/tweepy) +# Copyright (c) 2009-2021 Joshua Roesslein import json diff --git a/twitcaspy/models/comment.py b/twitcaspy/models/comment.py index 3aae975..b4d6eb9 100644 --- a/twitcaspy/models/comment.py +++ b/twitcaspy/models/comment.py @@ -20,7 +20,9 @@ class Comment(Model): from_user: :class:`~twitcaspy.models.User` | Comment contributor information created: :class:`datetime.datetime` - | Converted Unix time stamp of comment posting date and time to :class:`datetime.datetime` type + | Converted created_time to :class:`datetime.datetime` type + created_time: :class:`int` + | Unix time stamp of comment posting datetime References ---------- @@ -34,6 +36,7 @@ def parse(cls, api, json): for k, v in json.items(): if k == 'created': setattr(comment, k, fromtimestamp(v)) + setattr(comment, f'{k}_time', v) elif k == 'from_user': setattr(comment, k, User.parse(api, v)) else: diff --git a/twitcaspy/models/movie.py b/twitcaspy/models/movie.py index 1021cd9..5c2970d 100644 --- a/twitcaspy/models/movie.py +++ b/twitcaspy/models/movie.py @@ -40,7 +40,9 @@ class Movie(Model): duration: :class:`int` | stream time (seconds) created: :class:`datetime.datetime` - | Converted Unix time stamp of stream start date and time to :class:`datetime.datetime` type + | Converted created_time to :class:`datetime.datetime` type + created_time: :class:`int` + | Unix time stamp of stream start datetime is_collabo: :class:`bool` | Whether it is a collaboration stream is_protected: :class:`bool` @@ -70,6 +72,7 @@ def parse(cls, api, json): for k, v in json.items(): if k == 'created': setattr(movie, k, fromtimestamp(v)) + setattr(movie, f'{k}_time', v) else: setattr(movie, k, v) return movie diff --git a/twitcaspy/models/supporter.py b/twitcaspy/models/supporter.py index c935f09..685dab6 100644 --- a/twitcaspy/models/supporter.py +++ b/twitcaspy/models/supporter.py @@ -2,9 +2,11 @@ # Copyright 2021 Alma-field # See LICENSE for details. -from .model import Model +from ..utils import fromtimestamp -class Supporter(Model): +from .user import User + +class Supporter(User): """Supporter Object Attributes @@ -26,6 +28,12 @@ class Supporter(Model): | The last live ID by the user is_live: :class:`bool` | Whether it is currently live streamed + supported: :class:`int` + | Unix time stamp of supported datetime + | `2021-09-29 update `_ + | Added 'unix time stamp of supported datetime' to SupporterUser object of response |google_translate_ja_en| + supported_time: :class:`datetime.datetime` + | Converted supported to :class:`datetime.datetime` type supporter_count(deprecated): :class:`int` | Number of user supporters. | Returns a fixed value of 0. @@ -53,5 +61,9 @@ def parse(cls, api, json): supporter = cls(api) setattr(supporter, '_json', json) for k, v in json.items(): - setattr(supporter, k, v) + if k == 'supported': + setattr(supporter, k, v) + setattr(supporter, f'{k}_time', fromtimestamp(v)) + else: + setattr(supporter, k, v) return supporter diff --git a/twitcaspy/parsers/modelparser.py b/twitcaspy/parsers/modelparser.py index 6f25be1..3586930 100644 --- a/twitcaspy/parsers/modelparser.py +++ b/twitcaspy/parsers/modelparser.py @@ -1,6 +1,9 @@ # Twitcaspy # Copyright 2021 Alma-field # See LICENSE for details. +# +# based on tweepy(https://github.com/tweepy/tweepy) +# Copyright (c) 2009-2021 Joshua Roesslein from ..errors import TwitcaspyException diff --git a/twitcaspy/parsers/rawparser.py b/twitcaspy/parsers/rawparser.py index 979d6c4..a173c36 100644 --- a/twitcaspy/parsers/rawparser.py +++ b/twitcaspy/parsers/rawparser.py @@ -1,6 +1,9 @@ # Twitcaspy # Copyright 2021 Alma-field # See LICENSE for details. +# +# based on tweepy(https://github.com/tweepy/tweepy) +# Copyright (c) 2009-2021 Joshua Roesslein from .parser import Parser diff --git a/twitcaspy/utils.py b/twitcaspy/utils.py index 994d092..ee8dad6 100644 --- a/twitcaspy/utils.py +++ b/twitcaspy/utils.py @@ -5,4 +5,6 @@ from datetime import datetime def fromtimestamp(unix_timestamp): + if unix_timestamp is None: + return None return datetime.fromtimestamp(unix_timestamp)