The Elephant and the Serpent (PyLatam 2019)

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →

The Elephant and the Serpent (PyLatam 2019)

Philip James

August 30, 2019

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

45 slides
  1. ?

  2. ✨

  3. Toot Compose View • Settings link • Search bar •

    Compose view • 500 characters! • Emoji! • Polls! • Visibility • Content warnings!
  4. Home View • All the toots from the people you

    follow • Replies! • Retoots! • Liking!
  5. Let's build a bot! • ZenBot! • toot lines from

    the Zen of Python • Living on botsin.space
  6. 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
  7. 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
  8. Why use a client lib? Why not? •Why use Mastodon.py?

    • Tests • Abstractions • Updates •Why not? • Special functionality • Update lag
  9. 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()
  10. Where to host? • Your laptop + cron • A

    server you own + cron • Heroku + heroku scheduler
  11. 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!

More Decks by Philip James

Other Decks in Technology