8000 Add search params to search_{repos,users} · dahlia/github3.py@901b226 · GitHub
[go: up one dir, main page]

Skip to content

Commit 901b226

Browse files
committed
Add search params to search_{repos,users}
Also remove PySO8601! GitHub fixed their timestamps on the legacy search results so we no longer need it!
1 parent 100b1e3 commit 901b226

File tree

12 files changed

+44
-399
lines changed

12 files changed

+44
-399
lines changed

github3/github.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -860,32 +860,41 @@ def search_issues(self, owner, repo, state, keyword, start_page=0):
860860
issues = json.get('issues', [])
861861
return [LegacyIssue(l, self) for l in issues]
862862

863-
def search_repos(self, keyword, language='', start_page=0):
863+
def search_repos(self, keyword, language=None, start_page=None,
864+
sort=None):
864865
"""Search all repositories by keyword.
865866
866867
:param str keyword: (required)
867868
:param str language: (optional), language to filter by
868869
:param int start_page: (optional), page to get (results come 100/page)
870+
:param str sort: (optional), how to sort the results; accepted values:
871+
('stars', 'forks', 'updated')
869872
:returns: list of :class:`LegacyRepo <github3.legacy.LegacyRepo>`\ s
870873
"""
871874
url = self._build_url('legacy', 'repos', 'search', keyword)
872-
params = {}
873-
if language:
874-
params['language'] = language
875-
if start_page > 0:
876-
params['start_page'] = start_page
875+
params = {'language': language, 'start_page': start_page}
876+
if sort in ('stars', 'forks', 'updated'):
877+
params['sort'] = sort
877878
json = self._json(self._get(url, params=params), 200)
878879
repos = json.get('repositories', [])
879880
return [LegacyRepo(r, self) for r in repos]
880881

881-
def search_users(self, keyword, start_page=0):
882+
def search_users(self, keyword, start_page=0, sort=None, order=None):
882883
"""Search all users by keyword.
883884
884885
:param str keyword: (required)
885886
:param int start_page: (optional), page to get (results come 100/page)
887+
:param str sort: (optional), how to sort the results; accepted values:
888+
('followers', 'joined', 'repositories')
889+
:param str order: (optional), sort order if ``sort`` isn't provided,
890+
accepted values: ('asc', 'desc')
886891
:returns: list of :class:`LegacyUser <github3.legacy.LegacyUser>`\ s
887892
"""
888893
params = {'start_page': int(start_page)} if int(start_page) > 0 else {}
894+
if sort in ('followers', 'joined', 'repositories'):
895+
params['sort'] = sort
896+
if order in ('asc', 'desc') and not sort:
897+
params['order'] = order
889898
url = self._build_url('legacy', 'user', 'search', str(keyword))
890899
json = self._json(self._get(url, params=params), 200)
891900
users = json.get('users', [])

github3/models.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
from requests import session
1111
from requests.compat import urlparse
1212
from github3.decorators import requires_auth
13-
from github3.packages.PySO8601 import parse
13+
from datetime import datetime
1414
from github3 import __version__
1515

1616
__url_cache__ = {}
17+
__timeformat__ = '%Y-%m-%dT%H:%M:%SZ'
1718

1819

1920
class GitHubObject(object):
@@ -33,7 +34,9 @@ def to_json(self):
3334

3435
def _strptime(self, time_str):
3536
"""Converts an ISO 8601 formatted string into a datetime object."""
36-
return parse(time_str) if time_str else None
37+
if time_str:
38+
return datetime.strptime(time_str, __timeformat__)
39+
return None
3740

3841
@classmethod
3942
def from_json(cls, json):

github3/packages/PySO8601/__init__.py

Lines changed: 0 additions & 33 deletions
This file was deleted.

github3/packages/PySO8601/__version__.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

github3/packages/PySO8601/datetimestamps.py

Lines changed: 0 additions & 69 deletions
This file was deleted.

github3/packages/PySO8601/durations.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

github3/packages/PySO8601/intervals.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)
0