27 lines
1.0 KiB
Python
Executable File
27 lines
1.0 KiB
Python
Executable File
import requests
|
|
|
|
import var
|
|
from beloved_logger import logger
|
|
|
|
|
|
async def get_newest_count():
|
|
# logger.info("Getting newest post count")
|
|
while True:
|
|
headers = {
|
|
"Accept": "application/json, */*"
|
|
}
|
|
|
|
response = requests.get(f"https://{var.site}/json/posts", headers=headers)
|
|
|
|
if response.status_code == 200:
|
|
if response.json():
|
|
if response.json()['data']['posts'][0]['id']:
|
|
# logger.info(f"Newest post count of {response.json()['data']['posts'][0]['id']}")
|
|
return response.json()['data']['posts'][0]['id']
|
|
else:
|
|
while response.status_code != 200:
|
|
logger.info(f"Error getting newest post count with reason {response.status_code}, retrying")
|
|
response = requests.get(f"https://{var.site}/json/posts", headers=headers)
|
|
# logger.info(f"Newest post count of {response.json()['data']['posts'][0]['id']}")
|
|
return response.json()['data']['posts'][0]['id']
|