def __init__(self, url): self.tournaments_data, self.return_code = json.dumps(unirest.get(url, headers={"Accept":"application/json"}).body), \ unirest.get(url).code checkCode(self.return_code) self.parsed_data = json.loads(self.tournaments_data) self.past = {} self.setTournamentsAttributes(self.parsed_data)
def __init__(self, name, url): self.name = name self.player_data, self.return_code = json.dumps(unirest.get('http://' + url, header={"Accept":"application/json"}).body), \ unirest.get('http://' + url).code checkCode(self.return_code) parsed_data = json.loads(self.player_data) self.dict_name='' self.setPlayerAttributes(parsed_data)
def getAuth(self, email, password): """Enter your email and password for oc.tc. If you don't feel comfortable doing this, follow the instructions in AUTHTUTORIAL.md to get your auth token.""" self.return_code = unirest.post(join('http://', self.url, 'players', 'auth'), headers={"Content-Type":"application/json", "Authorization":"Basic","Accept":"application/json"}, params=json.dumps({"email":"{0}".format(email),"password":"******".format(password)})).code checkCode(self.return_code) return str(unirest.post(join('http://', self.url, 'players', 'auth'), headers={"Content-Type":"application/json", "Authorization":"Basic","Accept":"application/json"}, params=json.dumps({"email":"{0}".format(email),"password":"******".format(password)})).body['token'])
def __init__(self, urls): stats_data, self.return_code = unirest.get(urls[0], headers={"Accept":"application/json"}).body['data'], \ unirest.get(urls[0]).code checkCode(self.return_code) for url in urls: self.return_code = unirest.get(url).code checkCode(self.return_code) if urls.index(url) == 0: continue stats_data += unirest.get(url, headers={"Accept":"application/json"}).body['data'] self.setStats(stats_data) self.stats = stats_data print 'Retreived information for ' + str(len(stats_data)) + ' players.'
def __init__(self, urls): print urls self.teams_data, self.return_code = json.dumps(unirest.get(urls[0], headers={'Accept':'application/json'}).body), unirest.get(urls[0]).code checkCode(self.return_code) self.parsed_data = json.loads(self.teams_data) for url in urls: if urls.index(url) == 0: pass else: self.parsed_data['data'] += json.loads(json.dumps(unirest.get(url, headers={'Accept':'application/json'}).body))['data'] self.return_code = unirest.get(url).code checkCode(self.return_code) self.teams = {} self.team_list = [] self.setTeamList(self.parsed_data)
def __init__(self, urls, server): self.server = server url = urls[0] self.category_data, self.return_code = \ unirest.get(urls[0], headers={"Accept":"application/json"}).body, \ unirest.get(urls[0]).code checkCode(self.return_code) self.setCategoryAttributes(self.category_data) if len(urls) > 1: for url in urls: if urls.index(url) == 0: pass self.return_code = unirest.get(url).code checkCode(self.return_code) self.category_data['data'] += unirest.get(url, headers={"Accept":"application/json"}).body['data'] self.category_topics = self.category_data['data'] self.setCategoryAttributes(self.category_data)
def __init__(self, urls, url): self.url = url self.topic_data, self.return_code = ( unirest.get(urls[0], headers={"Accept": "application/json"}).body, unirest.get(urls[0]).code, ) checkCode(self.return_code) self.setTopicAttributes(self.topic_data) if len(urls) > 1: for url in urls: if urls.index(url) == 0: pass self.return_code = unirest.get(url).code checkCode(self.return_code) self.topic_data["data"]["posts"] += unirest.get(url, headers={"Accept": "application/json"}).body[ "data" ]["posts"] self.setTopicAttributes(self.topic_data)
def parsePages(list, form, *page_nums): page_nums = page_nums[0] if len(page_nums) == 1: if isinstance(page_nums[0], int): list.append(form.format(page_nums[0])) elif isinstance(page_nums[0], str): if page_nums[0].count('-') == 1: page_range = page_nums[0].split('-') for item in page_range: if not item.isdigit(): raise ValueError('Invalid page numbers.') return ind=page_range.index(item) page_range[ind]=int(item) page_range.sort() for i in range(page_range[0], page_range[1]+1): list.append(form.format(i)) elif page_nums[0].isdigit(): list.append(form.format(page_nums[0])) elif page_nums[0] == 'all': num_of_pages, return_code = unirest.get(form.format('')).body['links']['pagination']['last'], \ unirest.get(form.format('')).code sunshineexceptions.checkCode(return_code) for i in range(num_of_pages): list.append(form.format(i)) else: raise ValueError('Invalid page number.') elif len(page_nums) > 1: for item in page_nums: if isinstance(item, str): if not item.isdigit(): raise ValueError('Invalid page numbers.') return if not isinstance(item, int): raise ValueError('Invalid page numbers.') return list.append(form.format(str(item))) return list
def getAlerts(self, auth_token): """Pass in your auth token, and it will return your alerts.""" self.return_code = unirest.get(join('http://', self.url, 'alerts'),headers={"Authorization":"Bearer {0}".format(auth_token)}).code checkCode(self.return_code) return unirest.get(join('http://', self.url, 'alerts'), headers={"Authorization":"Bearer {0}".format(auth_token)}).body['data']
def __init__(self, url): self.url = url self.parsed_data, self.return_code = unirest.get(self.url).body['data'], unirest.get(self.url).code checkCode(self.return_code) self.setTeamAttributes(self.parsed_data)