<s> from github import Github <EOL> import requests <EOL> from bs4 import BeautifulSoup <EOL> from st2actions . runners . pythonrunner import Action <EOL> __all__ = [ <EOL> '<STR_LIT>' <EOL> ] <EOL> DEFAULT_WEB_URL = '<STR_LIT>' <EOL> DEFAULT_API_URL = '<STR_LIT>' <EOL> class BaseGithubAction ( Action ) : <EOL> def __init__ ( self , config ) : <EOL> super ( BaseGithubAction , self ) . __init__ ( config = config ) <EOL> token = self . config . get ( '<STR_LIT>' , None ) <EOL> token = token or None <EOL> base_url = self . config . get ( '<STR_LIT>' , DEFAULT_API_URL ) <EOL> self . _client = Github ( token , base_url = base_url ) <EOL> def _web_session ( self ) : <EOL> '''<STR_LIT>''' <EOL> login_url = DEFAULT_WEB_URL + '<STR_LIT>' <EOL> session = requests . Session ( ) <EOL> request = session . get ( login_url ) . text <EOL> html = BeautifulSoup ( request ) <EOL> token = html . find ( '<STR_LIT:input>' , { '<STR_LIT:name>' : '<STR_LIT>' } ) . attrs [ '<STR_LIT:value>' ] <EOL> commit_value = html . find ( '<STR_LIT:input>' , { '<STR_LIT:name>' : '<STR_LIT>' } ) . attrs [ '<STR_LIT:value>' ] <EOL> session_path = html . find ( '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } ) . attrs [ '<STR_LIT:action>' ] <EOL> login_data = { <EOL> '<STR_LIT>' : self . config [ '<STR_LIT:user>' ] , <EOL> '<STR_LIT:password>' : self . config [ '<STR_LIT:password>' ] , <EOL> '<STR_LIT>' : commit_value , <EOL> '<STR_LIT>' : token <EOL> } <EOL> session_url = DEFAULT_WEB_URL + session_path <EOL> session . post ( session_url , data = login_data ) <EOL> return session <EOL> def _get_analytics ( self , category , repo ) : <EOL> url = DEFAULT_WEB_URL + repo + '<STR_LIT>' + category + '<STR_LIT>' <EOL> s = self . _web_session ( ) <EOL> response = s . get ( url ) <EOL> return response . json ( ) </s>
