At /packets, return 10 records by default and add n=x to return x packets.
This commit is contained in:
parent
5793e57aa9
commit
1cffde2903
|
@ -17,8 +17,9 @@ You can use screen to detach the session.
|
||||||
3. Access the API from whatever other system you want.
|
3. Access the API from whatever other system you want.
|
||||||
|
|
||||||
## Endpoints:
|
## Endpoints:
|
||||||
-`/packets` - gives the most recent packets, with the fields from the Dire Wolf
|
-`/packets` - gives the most recent packets, sorted descending by time received.
|
||||||
User Guide.
|
- argument `n` will return a specific number of packets, default 10. E.g.,
|
||||||
|
`https://digi.w1cdn.net/aprs_api/packets?n=1` returns one packet.
|
||||||
|
|
||||||
Example of an object packet sent by W1CDN-1 and digipeated by K0UND-2:
|
Example of an object packet sent by W1CDN-1 and digipeated by K0UND-2:
|
||||||
```
|
```
|
||||||
|
|
10
api_app.py
10
api_app.py
|
@ -1,4 +1,4 @@
|
||||||
from flask import Flask
|
from flask import Flask, request
|
||||||
from flask_restful import Resource, Api, reqparse
|
from flask_restful import Resource, Api, reqparse
|
||||||
from datetime import date, timedelta
|
from datetime import date, timedelta
|
||||||
import configparser
|
import configparser
|
||||||
|
@ -67,9 +67,13 @@ def select_all_frames(conn):
|
||||||
|
|
||||||
class Packets(Resource):
|
class Packets(Resource):
|
||||||
def get(self):
|
def get(self):
|
||||||
#data = read_logs(log_folder)
|
try:
|
||||||
|
n = int(request.args.get('n'))
|
||||||
|
except:
|
||||||
|
n = 10
|
||||||
|
print(n)
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
data = select_all_frames(conn)
|
data = select_all_frames(conn)[-n:]
|
||||||
# Sort by created date, descending (https://stackoverflow.com/a/45266808)
|
# Sort by created date, descending (https://stackoverflow.com/a/45266808)
|
||||||
data.sort(key=operator.itemgetter('created'), reverse=True)
|
data.sort(key=operator.itemgetter('created'), reverse=True)
|
||||||
#data.sort(key=created, reverse=True)
|
#data.sort(key=created, reverse=True)
|
||||||
|
|
|
@ -82,7 +82,7 @@ def main():
|
||||||
path=["WIDE1-1"],
|
path=["WIDE1-1"],
|
||||||
info=b">Hello World!",
|
info=b">Hello World!",
|
||||||
)
|
)
|
||||||
ki.write(frame)
|
#ki.write(frame)
|
||||||
|
|
||||||
# Watch for new packets to come in
|
# Watch for new packets to come in
|
||||||
while True:
|
while True:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user