mirror of
https://github.com/OPSnet/PostOffice.git
synced 2026-01-16 23:05:38 -05:00
34 lines
802 B
Python
34 lines
802 B
Python
#!/usr/bin/env python3
|
|
|
|
import json
|
|
import os
|
|
import falcon
|
|
|
|
|
|
DATA_PATH = 'messages'
|
|
|
|
|
|
class Resource(object):
|
|
# noinspection PyMethodMayBeStatic
|
|
def on_get(self, _, resp):
|
|
response = []
|
|
count = 0
|
|
for entry in os.scandir(DATA_PATH):
|
|
if entry.name == '.gitkeep':
|
|
continue
|
|
with open(entry.path) as open_file:
|
|
try:
|
|
response.append(json.load(open_file))
|
|
except json.decoder.JSONDecodeError:
|
|
pass
|
|
os.remove(entry.path)
|
|
count += 1
|
|
if count == 50:
|
|
break
|
|
resp.body = str.encode(json.dumps(response))
|
|
resp.status = falcon.HTTP_200
|
|
|
|
|
|
application = falcon.API()
|
|
application.add_route('/', Resource())
|