當前位置: 首頁>>代碼示例>>Python>>正文


Python mastodon.Mastodon方法代碼示例

本文整理匯總了Python中mastodon.Mastodon方法的典型用法代碼示例。如果您正苦於以下問題:Python mastodon.Mastodon方法的具體用法?Python mastodon.Mastodon怎麽用?Python mastodon.Mastodon使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mastodon的用法示例。


在下文中一共展示了mastodon.Mastodon方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_extra_keys_ignored

# 需要導入模塊: import mastodon [as 別名]
# 或者: from mastodon import Mastodon [as 別名]
def test_extra_keys_ignored():
    """
    https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format
    defines 'id' and 'retry' keys which the Mastodon streaming API doesn't use,
    and alleges that "All other field names are ignored".
    """
    listener = Listener()
    listener.handle_stream_([
        'event: update',
        'data: {"foo": "bar"}',
        'id: 123',
        'retry: 456',
        'ignoreme: blah blah blah',
        '',
    ])
    assert listener.updates == [{"foo": "bar"}] 
開發者ID:halcy,項目名稱:Mastodon.py,代碼行數:18,代碼來源:test_streaming.py

示例2: test_multiline_payload

# 需要導入模塊: import mastodon [as 別名]
# 或者: from mastodon import Mastodon [as 別名]
def test_multiline_payload():
    """
    https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Data-only_messages
    says that newlines in the 'data' field can be encoded by sending the field
    twice! This would be really pathological for Mastodon because the payload
    is JSON, but technically literal newlines are permissible (outside strings)
    so let's handle this case.
    """
    listener = Listener()
    listener.handle_stream_([
        'event: update',
        'data: {"foo":',
        'data: "bar"',
        'data: }',
        '',
    ])
    assert listener.updates == [{"foo": "bar"}] 
開發者ID:halcy,項目名稱:Mastodon.py,代碼行數:19,代碼來源:test_streaming.py

示例3: test_url_errors

# 需要導入模塊: import mastodon [as 別名]
# 或者: from mastodon import Mastodon [as 別名]
def test_url_errors(tmpdir):
    clientid_good = tmpdir.join("clientid")
    token_good = tmpdir.join("token")
    clientid_bad = tmpdir.join("clientid_bad")
    token_bad = tmpdir.join("token_bad")
    
    clientid_good.write_text("foo\nbar\nhttps://zombo.com\n", "UTF-8")
    token_good.write_text("foo\nhttps://zombo.com\n", "UTF-8")
    clientid_bad.write_text("foo\nbar\nhttps://evil.org\n", "UTF-8")
    token_bad.write_text("foo\nhttps://evil.org\n", "UTF-8")  
    
    api = Mastodon(client_id = clientid_good, access_token = token_good)
    assert api
    assert api.api_base_url == "https://zombo.com"
    assert Mastodon(client_id = clientid_good, access_token = token_good, api_base_url = "zombo.com")
    
    with pytest.raises(MastodonIllegalArgumentError):
        Mastodon(client_id = clientid_good, access_token = token_bad, api_base_url = "zombo.com")
        
    with pytest.raises(MastodonIllegalArgumentError):
        Mastodon(client_id = clientid_bad, access_token = token_good, api_base_url = "zombo.com")
        
    with pytest.raises(MastodonIllegalArgumentError):
        Mastodon(client_id = clientid_bad, access_token = token_bad, api_base_url = "zombo.com") 
開發者ID:halcy,項目名稱:Mastodon.py,代碼行數:26,代碼來源:test_auth.py

示例4: get_mastodon_caption

# 需要導入模塊: import mastodon [as 別名]
# 或者: from mastodon import Mastodon [as 別名]
def get_mastodon_caption(submission):
    # Create string of hashtags
    hashtag_string = ''
    if HASHTAGS:
        for x in HASHTAGS:
            # Add hashtag to string, followed by a space for the next one
            hashtag_string += '#' + x + ' '
    # Set the Mastodon max title length for 500, minus the length of the shortlink and hashtags, minus one for the space between title and shortlink
    mastodon_max_title_length = 500 - len(submission.shortlink) - len(hashtag_string) - 1
    # Create contents of the Mastodon post
    if len(submission.title) < mastodon_max_title_length:
        mastodon_caption = submission.title + ' ' + hashtag_string + submission.shortlink
    else:
        mastodon_caption = submission.title[:mastodon_max_title_length] + '... ' + hashtag_string + submission.shortlink
    return mastodon_caption 
開發者ID:corbindavenport,項目名稱:tootbot,代碼行數:17,代碼來源:tootbot-heroku.py

示例5: _api

# 需要導入模塊: import mastodon [as 別名]
# 或者: from mastodon import Mastodon [as 別名]
def _api(access_token='__MASTODON_PY_TEST_ACCESS_TOKEN', version="3.1.1", version_check_mode="created"):
    import mastodon
    return mastodon.Mastodon(
            api_base_url='http://localhost:3000',
            client_id='__MASTODON_PY_TEST_CLIENT_ID',
            client_secret='__MASTODON_PY_TEST_CLIENT_SECRET',
            access_token=access_token,
            mastodon_version=version,
            version_check_mode=version_check_mode) 
開發者ID:halcy,項目名稱:Mastodon.py,代碼行數:11,代碼來源:conftest.py

示例6: error

# 需要導入模塊: import mastodon [as 別名]
# 或者: from mastodon import Mastodon [as 別名]
def error(message, err_info):
	acct, post_id, visibility = err_info
	print("error: {}".format(message))
	temp_client = Mastodon(
		client_id=cfg['client']['id'],
		client_secret=cfg['client']['secret'],
		access_token=cfg['secret'],
		api_base_url=cfg['site'])
	temp_client.status_post(_("{}\n{}\nContact the admin ({}) for assistance.\nFor further information, check https://github.com/Lynnesbian/OCRbot/blob/master/README.md#Errors ").format(acct, message, cfg['admin']), post_id, visibility = visibility, spoiler_text = "Error") 
開發者ID:Lynnesbian,項目名稱:OCRbot,代碼行數:11,代碼來源:service.py

示例7: cli

# 需要導入模塊: import mastodon [as 別名]
# 或者: from mastodon import Mastodon [as 別名]
def cli(debug):
    '''A program to play music your friends post on Mastodon.'''

    options['debug'] = debug

    ensure_dirs() 
開發者ID:zigg,項目名稱:fediplay,代碼行數:8,代碼來源:cli.py

示例8: register

# 需要導入模塊: import mastodon [as 別名]
# 或者: from mastodon import Mastodon [as 別名]
def register(instance):
    '''Register fediplay on your Mastodon instance.'''

    mastodon.register(instance) 
開發者ID:zigg,項目名稱:fediplay,代碼行數:6,代碼來源:cli.py

示例9: login

# 需要導入模塊: import mastodon [as 別名]
# 或者: from mastodon import Mastodon [as 別名]
def login(instance):
    '''Log in to your Mastodon instance.'''

    client_id, client_secret = get_client_credentials(instance)

    click.echo('Open this page in your browser and follow the instructions.')
    click.echo('Paste the code here.')
    click.echo('')
    click.echo(mastodon.get_auth_request_url(instance, client_id, client_secret))
    click.echo('')

    grant_code = input('Code: ')
    mastodon.login(instance, client_id, client_secret, grant_code) 
開發者ID:zigg,項目名稱:fediplay,代碼行數:15,代碼來源:cli.py

示例10: register

# 需要導入模塊: import mastodon [as 別名]
# 或者: from mastodon import Mastodon [as 別名]
def register(instance):
    '''Register fediplay to a Mastodon server and save the client credentials.'''

    client_id, client_secret = Mastodon.create_app('fediplay', scopes=['read'], api_base_url=api_base_url(instance))
    keyring.set_credential(instance, keyring.CREDENTIAL_CLIENT_ID, client_id)
    keyring.set_credential(instance, keyring.CREDENTIAL_CLIENT_SECRET, client_secret) 
開發者ID:zigg,項目名稱:fediplay,代碼行數:8,代碼來源:mastodon.py

示例11: build_client

# 需要導入模塊: import mastodon [as 別名]
# 或者: from mastodon import Mastodon [as 別名]
def build_client(instance, client_id, client_secret, access_token=None):
    '''Builds a Mastodon client.'''

    return Mastodon(api_base_url=api_base_url(instance),
                    client_id=client_id, client_secret=client_secret, access_token=access_token) 
開發者ID:zigg,項目名稱:fediplay,代碼行數:7,代碼來源:mastodon.py

示例12: login

# 需要導入模塊: import mastodon [as 別名]
# 或者: from mastodon import Mastodon [as 別名]
def login(instance, client_id, client_secret, grant_code):
    '''Log in to a Mastodon server and save the user credentials.'''

    client = build_client(instance, client_id, client_secret)
    access_token = client.log_in(code=grant_code, scopes=['read'])
    keyring.set_credential(instance, keyring.CREDENTIAL_ACCESS_TOKEN, access_token) 
開發者ID:zigg,項目名稱:fediplay,代碼行數:8,代碼來源:mastodon.py

示例13: link_is_internal

# 需要導入模塊: import mastodon [as 別名]
# 或者: from mastodon import Mastodon [as 別名]
def link_is_internal(link):
    '''Determines if a link is internal to the Mastodon instance.'''

    classes = link.attrib.get('class', '').split(' ')

    if options['debug']:
        print('href: {!r}, classes: {!r}'.format(link.attrib['href'], classes))

    if classes:
        return 'mention' in classes

    return False 
開發者ID:zigg,項目名稱:fediplay,代碼行數:14,代碼來源:mastodon.py

示例14: setup_streaming

# 需要導入模塊: import mastodon [as 別名]
# 或者: from mastodon import Mastodon [as 別名]
def setup_streaming(self, reloading=False):
        config = await self.__config()
        setup = (
            reloading
            and self.mastodon_client is None
            and config.spouse_handle is None
        )
        if config.access_token is None:
            self.close_streaming()
        else:
            if config.access_token != self.current_access_token:
                self.close_streaming()
            if self.mastodon_client is None:
                try:
                    self.mastodon_client = Mastodon(
                        client_id=config.client_id,
                        client_secret=config.client_secret,
                        access_token=config.access_token,
                        api_base_url="https://" + config.instance,
                    )
                    self.current_access_token = config.access_token
                    if setup:
                        await self.play_message("setup", config.spouse_handle)
                except MastodonUnauthorizedError:
                    self.current_access_token = None
                    config.access_token = None
                    await config.save_async()
                except MastodonError as e:
                    print(f"Unexpected mastodon error: {e}")
                    await asyncio.sleep(NabMastodond.RETRY_DELAY)
                    await self.setup_streaming()
            if (
                self.mastodon_client is not None
                and self.mastodon_stream_handle is None
            ):
                self.mastodon_stream_handle = self.mastodon_client.stream_user(
                    self, run_async=True, reconnect_async=True
                )
            if self.mastodon_client is not None:
                conversations = self.mastodon_client.conversations(
                    since_id=config.last_processed_status_id
                )
                await self.process_conversations(
                    self.mastodon_client, conversations
                ) 
開發者ID:nabaztag2018,項目名稱:pynab,代碼行數:47,代碼來源:nabmastodond.py


注:本文中的mastodon.Mastodon方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。