start playing from the most recent toot in timeline

This commit is contained in:
bbonf 2018-08-13 18:59:19 +02:00
parent 1f1829551f
commit 44c587358f

View file

@ -12,6 +12,8 @@ from fediplay.queue import Queue
Mastodon = mastodon.Mastodon Mastodon = mastodon.Mastodon
LISTEN_TO_HASHTAG = 'fediplay'
def api_base_url(instance): def api_base_url(instance):
'''Create an API base url from an instance name.''' '''Create an API base url from an instance name.'''
@ -26,7 +28,7 @@ class StreamListener(mastodon.StreamListener):
def on_update(self, status): def on_update(self, status):
tags = extract_tags(status) tags = extract_tags(status)
if 'fediplay' in tags: if LISTEN_TO_HASHTAG in tags:
links = extract_links(status) links = extract_links(status)
for link in links: for link in links:
try: try:
@ -67,6 +69,8 @@ def stream(instance, client_id, client_secret, access_token, cache_dir='.'):
client = build_client(instance, client_id, client_secret, access_token) client = build_client(instance, client_id, client_secret, access_token)
listener = StreamListener(Queue(cache_dir)) listener = StreamListener(Queue(cache_dir))
click.echo('==> Streaming from {}'.format(instance)) click.echo('==> Streaming from {}'.format(instance))
for t in client.timeline_hashtag(LISTEN_TO_HASHTAG, limit=1):
listener.on_update(t)
client.stream_user(listener) client.stream_user(listener)
def extract_tags(toot): def extract_tags(toot):