From 90813c959d626cde0bc9ddabedccf5c123ad107e Mon Sep 17 00:00:00 2001 From: Kacper Ziubryniewicz Date: Sat, 15 Sep 2018 11:21:35 +0200 Subject: [PATCH] Added `get_url_parameters` util method --- fbchat/utils.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/fbchat/utils.py b/fbchat/utils.py index 92e8a9d..fd1d1ac 100644 --- a/fbchat/utils.py +++ b/fbchat/utils.py @@ -14,10 +14,10 @@ import requests from .models import * try: - from urllib.parse import urlencode + from urllib.parse import urlencode, parse_qs, urlparse basestring = (str, bytes) except ImportError: - from urllib import urlencode + from urllib import urlencode, parse_qs, urlparse basestring = basestring # Python 2's `input` executes the input, whereas `raw_input` just returns the input @@ -297,3 +297,10 @@ def get_files_from_paths(filenames): yield files for fn, fp, ft in files: fp.close() + +def get_url_parameters(url, *args): + params = parse_qs(urlparse(url).query) + return [params[arg][0] for arg in args if params.get(arg)] + +def get_url_parameter(url, param): + return get_url_parameters(url, param)[0]