mirror of
https://github.com/nova-r/fediplug.git
synced 2025-03-10 15:49:00 +01:00
commiting clean_up_files , delete_files and a flag to be able to delete files on exit.
This commit is contained in:
parent
b0f1857c9e
commit
717a21e658
1 changed files with 19 additions and 2 deletions
|
@ -8,13 +8,13 @@ import sys
|
|||
|
||||
import appdirs
|
||||
import click
|
||||
import atexit
|
||||
from mastodon import Mastodon
|
||||
|
||||
from fediplay.dirs import DIRS
|
||||
import fediplay.mastodon as mastodon
|
||||
import fediplay.keyring as keyring
|
||||
|
||||
|
||||
def ensure_dirs():
|
||||
'''Make sure the application directories exist.'''
|
||||
|
||||
|
@ -85,10 +85,27 @@ def login(instance):
|
|||
@cli.command()
|
||||
@click.argument('instance')
|
||||
@click.argument('users', nargs=-1)
|
||||
def stream(instance, users):
|
||||
@click.option('--clean-up-files', is_flag=True)
|
||||
def stream(instance, users, clean_up_files):
|
||||
'''Stream music from your timeline.'''
|
||||
if ( clean_up_files ):
|
||||
atexit.register(delete_files)
|
||||
|
||||
client_id, client_secret = get_client_credentials(instance)
|
||||
access_token = get_access_token(instance)
|
||||
|
||||
mastodon.stream(instance, users, client_id, client_secret, access_token, cache_dir=DIRS.user_cache_dir)
|
||||
|
||||
def delete_files():
|
||||
cache_dir = DIRS.user_cache_dir
|
||||
for the_file in os.listdir(cache_dir):
|
||||
file_path = os.path.join(cache_dir, the_file)
|
||||
if os.path.isfile(file_path):
|
||||
os.remove(file_path)
|
||||
print('deleted ' + the_file)
|
||||
|
||||
@cli.command()
|
||||
def clean_up_files():
|
||||
delete_files()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue