def _handlePlanStatusRequests(self, type, endpoint, isPostRequest=False, data=None): # Checks if it is a post request if isPostRequest: response = requests.post(endpoint, headers=self.headers, data=json.dumps(data)) else: response = requests.get(endpoint, headers=self.headers) # Checks if it can be parsed to json try: responseJson = response.json() except: raise ServerError({"error": True, "errMsg": response.text}) # Checks if it returns a 2xx code if response.ok: return {"error": False, "returnedData": responseJson} else: raise PlanStatusError(type, { "error": True, "returnedData": responseJson })
def _handleCardStatusRequests(self, type, endpoint, isPostRequest=False, data=None): #check if resposnse is a post response if isPostRequest: response = requests.post(endpoint, headers=self.headers, data=json.dumps(data)) else: response = requests.get(endpoint, headers=self.headers) #check if it can be parsed to JSON try: responseJson = response.json() except: raise ServerError({"error": True, "errMsg": response.text}) if response.ok: return {"error": False, "returnedData": responseJson} else: raise RecepientStatusError(type, { "error": True, "returnedData": responseJson })
def _handleTransferStatusRequests(self, endpoint, isPostRequest=False, data=None): # Request headers headers = { 'content-type': 'application/json', } # Checks if it is a post request if isPostRequest: response = requests.post(endpoint, headers=headers, data=json.dumps(data)) else: response = requests.get(endpoint, headers=headers) # Checks if it can be parsed to json try: responseJson = response.json() except: raise ServerError({"error": True, "errMsg": response.text}) # Checks if it returns a 2xx code if response.ok: return {"error": False, "returnedData": responseJson} else: raise TransferFetchError({ "error": True, "returnedData": responseJson })
async def ourteam(ctx): x = 'https://ctftime.org/api/v1/teams/87448/' r = curlreqs.get(x) data = json.loads(r.content) a = data['rating'] c = data['aliases'] d = "" for x in c: d = d + x d = d + ',' h = (d[:-1]) e = "Team:" + '\t\t\t' + data["name"] + '\n' + "Country:" + '\t\t' + data[ "country"] + '\n' + "Academic:" + '\t\t' + str( data["academic"]) + '\n' + "ID:" + '\t\t\t' + str( data["id"]) + "\nAliases:\t\t" + str(h) i = "" l = 0 k = [] for x in a: for y in x.keys(): k.append(y) for x in a: for y in x.values(): i = i + "\n\n\nYear:\t\t" + str( k[l]) + "\norganizer_points:\t\t" + str( y['organizer_points']) + "\nrating_points:\t\t" + str( y['rating_points']) + "\nrating_place:\t\t" + str( y['rating_place']) l = l + 1 await ctx.send(e + i)
def test_user_auth(http_server): class Auth(auth.AuthBase): """User-defined auth""" def __call__(self, r): r.headers['Authorization'] = 'Basic dXNlcjpwYXNz' return r resp = requests.get(http_server.base_url + '/auth', auth=Auth()) assert resp.status_code == 200 assert resp.text == 'Authorization: Basic dXNlcjpwYXNz\n'
def spotify(): playlist_id = '5zaqtQk3NGJwstUuyAR8SW' url = 'https://api.spotify.com/v1/playlists/' + playlist_id + '/tracks' data = {'fields': ['total'], 'market': 'from_token'} header_value = "Bearer " + access_token response = requests.get(url, params=data, headers={"Authorization": header_value}) response_data = json.loads(response.text) print(response) try: return response_data['total'] except Exception as e: return "Can't get total: " + str(e)
def start_requests(): with open("instaLinks.opml", "r+") as instalink: # time.sleep(60) urls = instalink.readlines() random.shuffle(urls) for url in urls: try: rl = url.split("/")[3] except: continue # url = "https://www.instastalker2.com/user/%s" % rl url = "https://www.pixwox.com/id/profile/%s/" % rl print("currently opening the url =" + url) resp = requests.get(url.rstrip("\n"), headers=headers) response = HtmlResponse(url=url.rstrip("\n"), body=resp.text, encoding='utf-8') profileStalker(response)
def _handleVerifyStatusRequests(self, endpoint, isPostRequest=False, data=None): self.headers = {'content-type': 'application/json'} #check if resposnse is a post response if isPostRequest: response = requests.post(endpoint, headers=self.headers, data=json.dumps(data)) else: response = requests.get(endpoint, headers=self.headers) #check if it can be parsed to JSON try: responseJson = response.json() except: raise ServerError({"error": True, "errMsg": response.text}) if response.ok: return {"error": False, "returnedData": responseJson} else: raise BVNFetchError({"error": True, "returnedData": responseJson})
def profileStalker(response): print("Starting profile stalking %s" % response.url) postLinks = response.css('a[href*=post]::attr(href)').extract() # import pdb;pdb.set_trace() postIds = [ re.sub('\/#\d+', '', x).strip('/').split("/")[-1] for x in postLinks ] profileId = response.url.strip("/").split("/")[-1] profileId = profileId.rstrip('\n') print(response.url, ' total posts found on this page ', len(postLinks)) if delay: t.time.sleep(random.randint(0, 60)) completedPicIds = getCompletedId(profileId) for links, post in zip(postLinks, postIds): if post not in completedPicIds: # import pdb;pdb.set_trace() meta = {'pid': profileId, 'postId': post} url = urljoin(response.url, links) resp = requests.get(url.rstrip("\n"), headers=headers) response = HtmlResponse(url=url, body=resp.text, encoding='utf-8') PostStalker(response, profileId, post) completedPicIds = post + "\n" + completedPicIds setCompletedId(profileId, completedPicIds)
def test_basic_auth(http_server): resp = requests.get(http_server.base_url + '/auth', auth=auth.HTTPBasicAuth('user', 'pass')) assert resp.status_code == 200 assert resp.text == 'Authorization: Basic dXNlcjpwYXNz\n'