<commit_before>import web
import requests
import httplib, base64
urls = (
    '/(.*)', 'index'
)

render = web.template.render('templates/')

class index:
    def GET(self, user_id):
        pass

class twitter:
    def __init__(self):
        self.bearer = self.__get_bearer()
    #@staticmethod
    def __get_bearer(self):

        encode_string = "{!s}:{!s}".format("2nTaA2Uny9mZIOWrtNnO9Q","dqzpWUxiFjfNvrI2hNSNlKnPMSG8cMVU0e2yw9SDAM")
        encoded_string = base64.b64encode(encode_string)
        headers = {"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
        "Authorization": "Basic {!s}".format(encoded_string)}
        body = "grant_type=client_credentials"

        r = requests.post("https://api.twitter.com/oauth2/token", data=body, headers=headers,verify=False)
        return r.json()['access_token']

    def get_friends(self, screen_name):
        """
        Returns: A list of ids that are this person's friends
        include an Authorization header with the value of Bearer <base64 bearer token value from step 2>
        """
        headers = {"Authorization": "Bearer {!s}".format(self.bearer)}
        parameters = {"screen_name": screen_name}
        r = requests.get("https://api.twitter.com/1.1/friends/ids.json", params=parameters,headers=headers,verify=False)
        if r.status_code != requests.codes.ok:
            raise Exception('Error in API call. Twitter returned:' + r.text)
        return r.json()['ids']

if __name__ == "__main__":
    #app = web.application(urls, globals())
    #app.run()
    twit = twitter()
    print twit.get_friends('himerzi')<commit_msg>added some kind of exception handling<commit_after>import web
import requests
import httplib, base64
urls = (
    '/(.*)', 'index'
)

render = web.template.render('templates/')

class index:
    def GET(self, user_id):
        pass

class twitter:
    def __init__(self):
        self.bearer = self.__get_bearer()
    #@staticmethod
    def __get_bearer(self):

        encode_string = "{!s}:{!s}".format("2nTaA2Uny9mZIOWrtNnO9Q","dqzpWUxiFjfNvrI2hNSNlKnPMSG8cMVU0e2yw9SDAM")
        encoded_string = base64.b64encode(encode_string)
        headers = {"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
        "Authorization": "Basic {!s}".format(encoded_string)}
        body = "grant_type=client_credentials"

        r = requests.post("https://api.twitter.com/oauth2/token", data=body, headers=headers,verify=False)
        return r.json()['access_token']

    def get_friends(self, screen_name='', user_id=None):
        """
        Returns: A list of ids that are this person's friends
        include an Authorization header with the value of Bearer <base64 bearer token value from step 2>
        """
        headers = {"Authorization": "Bearer {!s}".format(self.bearer)}
        parameters = {"screen_name": screen_name} if not user_id else {"user_id": user_id}
        r = requests.get("https://api.twitter.com/1.1/friends/ids.json", params=parameters,headers=headers,verify=False)
        if r.status_code != requests.codes.ok:
            raise Exception('Error in API call. Twitter returned:' + r.text)
        return r.json()['ids']

if __name__ == "__main__":
    #app = web.application(urls, globals())
    #app.run()
    twit = twitter()
    print twit.get_friends('himerzi')
{'fraction_non_alphanumeric': 0.13917216556688664, 'fraction_numerical': 0.013197360527894421, 'mean_word_length': 3.3709043250327655, 'pattern_counts': {'":': 11, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2693952', 'n_tokens_mistral': 1130, 'n_tokens_neox': 1097, 'n_words': 225}