Skip to content

Commit

Permalink
fix: handle invalid html in github responses
Browse files Browse the repository at this point in the history
  • Loading branch information
user2589 committed Feb 17, 2019
1 parent e6b2623 commit c729f90
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion stgithub.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,14 @@ def user_daily_contrib_num(self, user, year):
url = "/users/%s/contributions?from=%d-12-01&to=%d-12-31&full_graph=1" \
% (user, year, year)
year = str(year)
tree = ElementTree.fromstring(self._request(url).text)
start_token = '<svg'
stop_token = '/svg>'
response_text = self._request(url).text
# cut out first <svg> element,
# since HTML outside of it is sometimes malformed
response_text = start_token + response_text.split(
start_token, 1)[-1].split(stop_token, 1)[0] + stop_token
tree = ElementTree.fromstring(response_text)

return {rect.attrib['data-date']: _int(rect.attrib.get('data-count'))
for rect in tree.iter('rect')
Expand Down Expand Up @@ -524,6 +531,11 @@ def full_user_activity_timeline(self, user, start=None, to=None):
# type: (str, str, str) -> Generator[Tuple[str, Dict]]
""" Get a list of public user contributions, by month by repository.
.. note: User timeline sometimes does not include all contributions.
E.g., this issue is not reflected in the reporter timeline:
https://github.com/GoogleCloudPlatform/webapp2/issues/104
Maybe, it
Args:
user (str): GitHub login of the user to get activity for.
start (str): date to start with, e.g. '2017-01' or '2017-01-01'.
Expand Down

0 comments on commit c729f90

Please sign in to comment.