Skip to content

Commit

Permalink
Merge pull request #39 from ihabunek/curses-resize
Browse files Browse the repository at this point in the history
Improvements to the curses app
  • Loading branch information
ihabunek authored Jan 14, 2018
2 parents b444b06 + d8fd8d0 commit d3d6950
Show file tree
Hide file tree
Showing 8 changed files with 459 additions and 266 deletions.
33 changes: 25 additions & 8 deletions toot/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,38 @@ def timeline_home(app, user):
return http.get(app, user, '/api/v1/timelines/home').json()


def _get_next_path(headers):
def get_next_path(headers):
"""Given timeline response headers, returns the path to the next batch"""
links = headers.get('Link', '')
matches = re.match('<([^>]+)>; rel="next"', links)
if matches:
url = matches.group(1)
return urlparse(url).path
parsed = urlparse(matches.group(1))
return "?".join([parsed.path, parsed.query])


def timeline_generator(app, user):
next_path = '/api/v1/timelines/home'
def _timeline_generator(app, user, path, limit=20):
while path:
response = http.get(app, user, path)
yield response.json()
path = get_next_path(response.headers)


while next_path:
response = http.get(app, user, next_path)
def _anon_timeline_generator(instance, path, limit=20):
while path:
url = "https://{}{}".format(instance, path)
response = http.anon_get(url, path)
yield response.json()
next_path = _get_next_path(response.headers)
path = get_next_path(response.headers)


def home_timeline_generator(app, user, limit=20):
path = '/api/v1/timelines/home?limit={}'.format(limit)
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 upload_media(app, user, file):
Expand Down
254 changes: 0 additions & 254 deletions toot/app.py

This file was deleted.

13 changes: 11 additions & 2 deletions toot/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,17 @@ def timeline(app, user, args):


def curses(app, user, args):
from toot.app import TimelineApp
generator = api.timeline_generator(app, user)
from toot.ui.app import TimelineApp

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)
else:
generator = api.home_timeline_generator(app, user)

TimelineApp(generator).run()


Expand Down
14 changes: 12 additions & 2 deletions toot/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,18 @@ def visibility(value):
Command(
name="curses",
description="An experimental timeline app (doesn't work on Windows)",
arguments=[],
require_auth=True,
arguments=[
(["-p", "--public"], {
"action": 'store_true',
"default": False,
"help": "Resolve non-local accounts",
}),
(["-i", "--instance"], {
"type": str,
"help": 'instance from which to read (for public timeline only)',
})
],
require_auth=False,
),
]

Expand Down
Empty file added toot/ui/__init__.py
Empty file.
Loading

0 comments on commit d3d6950

Please sign in to comment.