Skip to content

Commit

Permalink
Merge pull request #85 from ksunden/localtag
Browse files Browse the repository at this point in the history
Add local and tag timelines to curses
  • Loading branch information
ihabunek committed Jan 24, 2019
2 parents 131a809 + 4df0c78 commit c7c42b8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
21 changes: 14 additions & 7 deletions toot/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,17 @@ def get_next_path(headers):
return "?".join([parsed.path, parsed.query])


def _timeline_generator(app, user, path, limit=20):
def _timeline_generator(app, user, path, params=None):
while path:
response = http.get(app, user, path)
response = http.get(app, user, path, params)
yield response.json()
path = get_next_path(response.headers)


def _anon_timeline_generator(instance, path, limit=20):
def _anon_timeline_generator(instance, path, params=None):
while path:
url = "https://{}{}".format(instance, path)
response = http.anon_get(url, path)
response = http.anon_get(url, params)
yield response.json()
path = get_next_path(response.headers)

Expand All @@ -199,9 +199,16 @@ def home_timeline_generator(app, user, limit=20):
return _timeline_generator(app, user, path)


def public_timeline_generator(instance, limit=20):
path = '/api/v1/timelines/public?limit={}'.format(limit)
return _anon_timeline_generator(instance, path)
def public_timeline_generator(instance, local=False, limit=20):
path = '/api/v1/timelines/public'
params = {'local': 'true' if local else 'false', 'limit': limit}
return _anon_timeline_generator(instance, path, params)


def tag_timeline_generator(app, user, hashtag, local=False, limit=20):
path = '/api/v1/timelines/tag/{}'.format(hashtag)
params = {'local': 'true' if local else 'false', 'limit': limit}
return _timeline_generator(app, user, path, params)


def upload_media(app, user, file):
Expand Down
11 changes: 10 additions & 1 deletion toot/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,21 @@ def thread(app, user, args):
def curses(app, user, args):
from toot.ui.app import TimelineApp

# Make sure tag, list and public are not used simultaneously
if len([arg for arg in [args.tag, args.public] if arg]) > 1:
raise ConsoleError("Only one of --public or --tag can be used at one time.")

if args.local and not (args.public or args.tag):
raise ConsoleError("The --local option is only valid alongside --public or --tag.")

if not args.public and (not app or not user):
raise ConsoleError("You must be logged in to view the home timeline.")

if args.public:
instance = args.instance or app.instance
generator = api.public_timeline_generator(instance)
generator = api.public_timeline_generator(instance, local=args.local)
elif args.tag:
generator = api.tag_timeline_generator(app, user, args.tag, local=args.local)
else:
generator = api.home_timeline_generator(app, user)

Expand Down
11 changes: 10 additions & 1 deletion toot/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,19 @@ def visibility(value):
"default": False,
"help": "Resolve non-local accounts",
}),
(["-t", "--tag"], {
"type": str,
"help": "Show timeline for given hashtag.",
}),
(["-l", "--local"], {
"action": "store_true",
"default": False,
"help": "Show only statuses from local instance (public and tag timelines only).",
}),
(["-i", "--instance"], {
"type": str,
"help": 'instance from which to read (for public timeline only)',
})
}),
],
require_auth=False,
),
Expand Down

0 comments on commit c7c42b8

Please sign in to comment.