Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The Elephant and the Serpent (PyLatam 2019)

The Elephant and the Serpent (PyLatam 2019)

Philip James

August 30, 2019
Tweet

More Decks by Philip James

Other Decks in Technology

Transcript

  1. The Elephant
    and the Serpent
    Philip James, @phildini, #PyConLatam19

    View full-size slide

  2. Who's this guy?

    View full-size slide

  3. Misaligned Incentives

    View full-size slide

  4. What else can we do?

    View full-size slide

  5. Toot Compose View
    • Settings link
    • Search bar
    • Compose view
    • 500 characters!
    • Emoji!
    • Polls!
    • Visibility
    • Content warnings!

    View full-size slide

  6. https://xkcd.com/2106/

    View full-size slide

  7. Home View
    • All the toots from the
    people you follow
    • Replies!
    • Retoots!
    • Liking!

    View full-size slide

  8. Local timeline
    • All the public, non-reply
    toots from people on
    your server

    View full-size slide

  9. Federated timeline
    • All the public, non-reply
    toots from people on
    your server

    View full-size slide

  10. Inbox
    Outbox
    Internet

    View full-size slide

  11. Inbox
    Outbox
    GET
    https://mastodon.social
    POST
    @[email protected]

    View full-size slide

  12. https://mastodon.social
    @[email protected]
    @[email protected]
    POST
    POST
    GET
    Inbox Outbox
    Inbox Outbox

    View full-size slide

  13. https://mastodon.social
    @[email protected]
    @[email protected]
    POST
    POST
    GET
    https://other.server
    Inbox Outbox
    Inbox Outbox

    View full-size slide

  14. Magical communities
    require norms

    View full-size slide

  15. https://mastodon.social
    @[email protected]
    @[email protected]
    https://other.server
    Inbox Outbox
    Inbox Outbox
    POST "follow alice"
    bob
    POST to followers

    View full-size slide

  16. ✨ActivityPub✨
    https://activitypub.rocks/
    https://www.w3.org/TR/activitypub/

    View full-size slide

  17. API-Friendly
    https://docs.joinmastodon.org/

    View full-size slide

  18. Let's build a bot!
    • ZenBot!
    • toot lines from the Zen of Python
    • Living on botsin.space

    View full-size slide

  19. OAuth + Scopes

    View full-size slide

  20. Using requests

    View full-size slide

  21. Using requests
    Python 3.6.4 (default, Feb 10 2018, 09:39:10)
    [GCC 4.2.1 Compatible Apple LLVM 8.0.0
    (clang-800.0.42.1)] on darwin
    Type "help", "copyright", "credits" or "license"
    for more information.
    >>> import requests

    View full-size slide

  22. Using requests
    >>> response = requests.post(
    "https://botsin.space/api/v1/statuses",
    headers={
    "Authorization": "Bearer
    558cce8660cfc733bbaf7904e54c9aece5221797a7e6f494a
    c2e8276bdcec726"
    },
    data={"status": "This is a test"})
    >>> response.ok
    True

    View full-size slide

  23. Using requests

    View full-size slide

  24. Mastodon.py
    https://github.com/halcy/Mastodon.py

    View full-size slide

  25. Why use a client lib? Why not?
    •Why use Mastodon.py?
    • Tests
    • Abstractions
    • Updates
    •Why not?
    • Special functionality
    • Update lag

    View full-size slide

  26. zenbot.py
    import this
    import os
    from mastodon import Mastodon
    def toot_zen():
    zen = "".join(
    [this.d.get(c, c) for c in this.s]
    ).split("\n")
    instance = Mastodon(
    access_token=os.getenv('ACCESS_TOKEN'),
    api_base_url='https://botsin.space',
    )
    toot = instance.toot(
    f'The Zen of Python says:\n\n{random.choice(zen)}',
    )
    if __name__ == '__main__':
    toot_zen()

    View full-size slide

  27. Where to host?
    • Your laptop + cron
    • A server you own + cron
    • Heroku + heroku scheduler

    View full-size slide

  28. How do I choose a server?
    • joinmastodon.org
    • Do you like the feel of community?
    • Do you like the Code of Conduct?
    • Do you like the admins?
    You can move around, try different servers, and have multiple identities!

    View full-size slide

  29. What next?
    •Find a server
    •Join the community
    •Build a bot
    •Help make magic!
    [email protected]
    @[email protected]

    View full-size slide