· 6 years ago · Dec 14, 2019, 05:52 AM
1from jsonrpcclient import request, Response
2from jsonrpcclient.clients.http_client import HTTPClient
3import os, json, jsonschema
4
5# also go into the top right corner, hit your user name, hit edit profile, then go to API and extract your API key and
6api_key = ‘Insert API Key Here’
7
8class NonValidatingClient(HTTPClient):
9 # A custom HTTPClient that grabs and parses the response string before it gets validated
10 def __init__(self, *args, **kwargs) -> None:
11 super().__init__(*args, **kwargs)
12
13 def send_message(
14 self, request: str, response_expected: bool, **kwargs
15 ) -> Response:
16 "“”
17 Transport the message to the server and return the response.
18 Args:
19 request: The JSON-RPC request string.
20 response_expected: Whether the request expects a response.
21 Returns:
22 A Response object.
23 "“”
24 response = self.session.post(self.endpoint, data=request.encode(), **kwargs)
25 with open('List_of_snatched.txt’, 'w’) as List_of_snatched:
26 resJSON = json.JSONDecoder().decode(response.text)
27 resJSON[“jsonrpc”] = 2.0
28 List_of_snatched.write(json.JSONEncoder().encode(resJSON[“result”]))
29 return Response(json.JSONEncoder().encode(resJSON)) # @TODO: Actually fix this response to make it valid
30
31client = NonValidatingClient(“https://api.broadcasthe.net/”)
32try:
33 response = client.request(“getUserSnatchlist”, key=api_key, results=4000)
34except jsonschema.exceptions.ValidationError:
35 # Just discard this error as we already handle it in the NonValidatingClient
36 pass
37#python