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. ?

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

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

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

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

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

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