当前位置: 首页>>代码示例>>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;未经允许,请勿转载。