Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proxy option to config and prepare the requests with it #47

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions toot/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,12 @@ def post_status(app, user, status, visibility='public', media_ids=None):
}).json()


def timeline_home(app, user):
return http.get(app, user, '/api/v1/timelines/home').json()
def timeline_home(app, user, args):
if args.tag:
timeline = "tag/%s" % args.tag
else:
timeline = "home"
return http.get(app, user, '/api/v1/timelines/%s' % timeline).json()


def get_next_path(headers):
Expand Down
2 changes: 1 addition & 1 deletion toot/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _parse_timeline(item):


def timeline(app, user, args):
items = api.timeline_home(app, user)
items = api.timeline_home(app, user, args)
parsed_items = [_parse_timeline(t) for t in items]

print_out("─" * 31 + "┬" + "─" * 88)
Expand Down
18 changes: 18 additions & 0 deletions toot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def make_config(path):
"apps": apps,
"users": users,
"active_user": active_user,
"proxy" : {},
}

print_out("Creating config file at <blue>{}</blue>".format(path))
Expand Down Expand Up @@ -174,3 +175,20 @@ def activate_user(config, user):
config['active_user'] = user_id(user)

return config

@modify_config
def set_proxy(config, proxy):
config['proxy'] = proxy

return config

@modify_config
def delete_proxy(config):
config['proxy'] = None

return config

def get_proxy():
config = load_config()

return config['proxy']
7 changes: 6 additions & 1 deletion toot/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,12 @@ def visibility(value):
Command(
name="timeline",
description="Show recent items in your public timeline",
arguments=[],
arguments=[
(["tag"], {
"help" : "Search for a tag",
"nargs" : "?",
}),
],
require_auth=True,
),
Command(
Expand Down
3 changes: 2 additions & 1 deletion toot/http.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from requests import Request, Session
from toot.exceptions import NotFoundError, ApiError
from toot.logging import log_request, log_response

from toot import config

def send_request(request, allow_redirects=True):
log_request(request)

with Session() as session:
session.proxies.update(config.get_proxy())
prepared = session.prepare_request(request)
response = session.send(prepared, allow_redirects=allow_redirects)

Expand Down