Skip to content

Instantly share code, notes, and snippets.

View aparrish's full-sized avatar

Allison Parrish aparrish

View GitHub Profile
@aparrish
aparrish / tracery-with-data.ipynb
Last active July 18, 2023 20:00
Tracery and Python. Code examples released under CC0 https://creativecommons.org/choose/zero/, other text released under CC BY 4.0 https://creativecommons.org/licenses/by/4.0/
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@aparrish
aparrish / csv-intro.ipynb
Last active July 18, 2023 20:00
Quick intro to CSVs. Code examples released under CC0 https://creativecommons.org/choose/zero/, other text released under CC BY 4.0 https://creativecommons.org/licenses/by/4.0/
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@aparrish
aparrish / index.md
Last active May 6, 2023 14:29
Getting credentials for the Mastodon API with Mastodon.py. Code examples released under CC0 https://creativecommons.org/choose/zero/, other text released under CC BY 4.0 https://creativecommons.org/licenses/by/4.0/

Getting credentials for the Mastodon API with Mastodon.py, step by step

Making a bot? Making a bot in Python? Making a bot in Python that uses the Mastodon API? If so, chances are you need to get some credentials. Here's how I did it!

(The following tutorial uses Python 2.7, but if you're using Python 3+ everything should work substantially the same.)

Mastodon.py authentication

I just started using it, but it looks like Mastodon.py is a pretty great library for working with the Mastodon API! However, all of the authentication examples use static files to store credentials, which I don't like—I'm afraid I'll accidentally push them to Github. I like to keep my authentication as close to the actual command that runs the program as possible, so usually I pass them on the command line to the script running my bot. To do this, I need to get the appropriate credentials on their own, as separate strings that I can cut and paste.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@aparrish
aparrish / twitter_request_example.py
Created December 13, 2012 16:42
Here's how to make an OAuth1-signed request to the Twitter API with the requests library.
# Run on the command line like so:
# $ python your_consumer_key your_consumer_secret your_access_token your_token_secret
import requests
from requests.auth import OAuth1
import sys
consumer_key, consumer_secret, access_token, token_secret = \
[unicode(x) for x in sys.argv[1:]]
@aparrish
aparrish / mdprev.py
Created August 21, 2011 20:15
preview your markdown with a web server
#!/usr/bin/env python
# run like so:
# $ python mdprev.py --port=8000 --input=your_markdown_file.md
# then open your browser to http://localhost:8000/
# requires tornado and markdown2 https://github.com/trentm/python-markdown2
import os.path
import tornado.httpserver
import tornado.ioloop
import tornado.options
@aparrish
aparrish / extracting-conversations-from-project-gutenberg.ipynb
Created July 18, 2018 22:26
Extracting conversations from Project Gutenberg. Code examples released under CC0 https://creativecommons.org/choose/zero/, other text released under CC BY 4.0 https://creativecommons.org/licenses/by/4.0/
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@aparrish
aparrish / index.md
Last active November 6, 2022 09:02
Don't Tweet, Toot: Understanding Mastodon and the Federated Social Network
@aparrish
aparrish / a-reasonable-introduction.ipynb
Last active September 7, 2022 08:59
Workshop notebook. Code examples released under CC0 https://creativecommons.org/choose/zero/, other text released under CC BY 4.0 https://creativecommons.org/licenses/by/4.0/
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.