| Conditions | 9 |
| Total Lines | 55 |
| Lines | 0 |
| Ratio | 0 % |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | from github import Github |
||
| 9 | ] |
||
| 10 | |||
| 11 | BASE_URL = 'https://github.com' |
||
| 12 | |||
| 13 | |||
| 14 | class BaseGithubAction(Action): |
||
| 15 | def __init__(self, config): |
||
| 16 | super(BaseGithubAction, self).__init__(config=config) |
||
| 17 | token = self.config.get('token', None) |
||
| 18 | token = token or None |
||
| 19 | self._client = Github(token) |
||
| 20 | |||
| 21 | def _web_session(self): |
||
| 22 | '''Returns a requests session to scrape off the web''' |
||
| 23 | login_url = BASE_URL + '/login' |
||
| 24 | session = requests.Session() |
||
| 25 | request = session.get(login_url).text |
||
| 26 | html = BeautifulSoup(request) |
||
| 27 | token = html.find('input', {'name': 'authenticity_token'}).attrs['value'] |
||
| 28 | commit_value = html.find('input', {'name': 'commit'}).attrs['value'] |
||
| 29 | session_path = html.find('form', {'method': 'post'}).attrs['action'] |
||
| 30 | |||
| 31 | login_data = { |
||
| 32 | 'login': self.config['user'], |
||
| 33 | 'password': self.config['password'], |
||
| 34 | 'commit': commit_value, |
||
| 35 | 'authenticity_token': token |
||
| 36 | } |
||
| 37 | |||
| 38 | session_url = BASE_URL + session_path |
||
| 39 | session.post(session_url, data=login_data) |
||
| 40 | return session |
||
| 41 | |||
| 42 | def _get_analytics(self, category, repo): |
||
| 43 | url = 'https://github.com/' + repo + '/graphs/' + category + '.json' |
||
| 44 | s = self._web_session() |
||
| 45 | response = s.get(url) |
||
| 46 | return response.json() |
||
| 47 |