-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathszuruAPI.py
31 lines (26 loc) · 1.34 KB
/
szuruAPI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import requests
import json
config = json.load(open("config.json"))
# Returns a search result resource as a python dict
def getPosts(query = "", count = 100, offset = 0, fields = ""):
if(count <= 0):
count = "1"
url = config["url"] + "/api/posts/?offset=" + str(offset) + "&limit=" + str(count) + "&query=" + query
if(fields):
url += "&fields=" + fields
posts = requests.get(url, headers = {"Accept": "application/json"}, auth=requests.auth.HTTPBasicAuth(config["user"], config["password"]))
return posts.json()
# Takes in the post id as a number and the post update object as a dict
# Returns the status given
def updatePost(id, post):
url = config["url"] + "/api/post/" + str(id)
header = {"Accept": "application/json", "Content-Type": "application/json"}
return requests.put(url, headers = header, data = json.dumps(post), auth=requests.auth.HTTPBasicAuth(config["user"], config["password"]))
def createComment(id, text):
url = config["url"] + "/api/comments/"
header = {"Accept": "application/json", "Content-Type": "application/json"}
return requests.post(url, headers = header, data = json.dumps({ "postId": id, "text": text }), auth=requests.auth.HTTPBasicAuth(config["user"], config["password"]))
# Takes a post resource and returns the response
def getThumbnail(post):
url = config["url"] + "/" + post["thumbnailUrl"]
return requests.get(url)