You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
1.6 KiB
Python
80 lines
1.6 KiB
Python
import requests
|
|
import json
|
|
|
|
r = requests.get("http://127.0.0.1:1234/api/getcontent")
|
|
data = r.json()
|
|
|
|
def getcategory(category):
|
|
counter = 0
|
|
output=[]
|
|
for post in data:
|
|
if data[post]["category"] == category:
|
|
output.append(data[post]["title"])
|
|
counter+=1
|
|
|
|
if counter == 0:
|
|
print("Nothing found")
|
|
|
|
return output
|
|
|
|
def getimages(category, number):
|
|
counter = 1
|
|
output=[]
|
|
for post in data:
|
|
if data[post]["category"] == category:
|
|
if counter == number:
|
|
images = data[post]["images"]
|
|
for image in images:
|
|
output.append("http://127.0.0.1:1234"+image["url"])
|
|
counter+=1
|
|
return output
|
|
|
|
def getlinks(category, number):
|
|
counter = 1
|
|
output=[]
|
|
for post in data:
|
|
if data[post]["category"] == category:
|
|
if counter == number:
|
|
links = data[post]["removedLinks"]
|
|
for link in links:
|
|
item = data.get(link)
|
|
output.append(item['title'])
|
|
output.append(item['content'])
|
|
counter+=1
|
|
return output
|
|
|
|
def get(category, number):
|
|
counter = 1
|
|
output = []
|
|
for post in data:
|
|
if data[post]["category"] == category:
|
|
if counter == number:
|
|
output.append(data[post]["title"])
|
|
output.append(data[post]["content"])
|
|
counter+=1
|
|
return output
|
|
|
|
def gettitle(category, number):
|
|
counter = 1
|
|
output = []
|
|
for post in data:
|
|
if data[post]["category"] == category:
|
|
if counter == number:
|
|
output.append(data[post]["title"])
|
|
counter+=1
|
|
return output
|
|
|
|
def getcontent(category, number):
|
|
counter = 1
|
|
output = []
|
|
for post in data:
|
|
if data[post]["category"] == category:
|
|
if counter == number:
|
|
output.append(data[post]["content"])
|
|
counter+=1
|
|
return output
|
|
|
|
|
|
#getcategory("thesis")
|
|
#get("thesis", 2) #thesis, exercise or term
|