use .env to specify Mastodon instance

This commit is contained in:
Matt Behrens 2018-01-24 21:07:51 -05:00
parent a41a5eb26c
commit 600a0b8e1f
3 changed files with 14 additions and 9 deletions

1
.env Normal file
View file

@ -0,0 +1 @@
FEDIPLAY_API_BASE_URL=https://cybre.space

View file

@ -6,7 +6,7 @@ A Mastodon client that automatically plays your friends' music as they toot link
You'll need `ffplay` from [FFmpeg](https://ffmpeg.org/) to actually play music. On macOS, `ffplay` is part of the Homebrew ffmpeg package, but you need to build it with `brew install ffmpeg --with-sdl2`. You'll need `ffplay` from [FFmpeg](https://ffmpeg.org/) to actually play music. On macOS, `ffplay` is part of the Homebrew ffmpeg package, but you need to build it with `brew install ffmpeg --with-sdl2`.
Edit `API_BASE_URL` at the top of `fediplay.py` so it points to your Mastodon instance. Edit `.env` and set `FEDIPLAY_API_BASE_URL` to your Mastodon instance.
Use `pipenv install` from [Pipenv](https://docs.pipenv.org/) to install the Python dependencies. Use `pipenv install` from [Pipenv](https://docs.pipenv.org/) to install the Python dependencies.

View file

@ -1,5 +1,3 @@
API_BASE_URL = 'https://cybre.space'
from subprocess import run from subprocess import run
from threading import Thread, Lock from threading import Thread, Lock
@ -94,20 +92,26 @@ def extract_links(toot):
return [link.attrib['href'] for link in all_links if not has_external_link_class(link.attrib.get('class', ''))] return [link.attrib['href'] for link in all_links if not has_external_link_class(link.attrib.get('class', ''))]
def main(): def main():
import os
from getpass import getpass from getpass import getpass
from os import environ, path
from sys import exit
if not os.path.exists('clientcred.secret'): api_base_url = environ.get('FEDIPLAY_API_BASE_URL')
if not api_base_url:
print('FEDIPLAY_API_BASE_URL environment variable not set')
exit(1)
if not path.exists('clientcred.secret'):
print('==> No clientcred.secret; registering application') print('==> No clientcred.secret; registering application')
register(API_BASE_URL) register(api_base_url)
if not os.path.exists('usercred.secret'): if not path.exists('usercred.secret'):
print('==> No usercred.secret; logging in') print('==> No usercred.secret; logging in')
email = input('Email: ') email = input('Email: ')
password = getpass('Password: ') password = getpass('Password: ')
login(API_BASE_URL, email, password) login(api_base_url, email, password)
stream(API_BASE_URL) stream(api_base_url)
if __name__ == '__main__': if __name__ == '__main__':
main() main()