parent
9359f1dd91
commit
1d5951aa21
@ -1,5 +1,30 @@
|
||||
from fastapi import FastAPI, Request
|
||||
import uvicorn
|
||||
import redis
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
# Set up Redis connection
|
||||
r = redis.Redis(host='localhost', port=6379, db=0)
|
||||
|
||||
@app.post("/i/")
|
||||
async def i(request: Request):
|
||||
message = await request.json()
|
||||
message = to_lmc(message)
|
||||
r.lpush("to_main", message)
|
||||
|
||||
client_host = request.client.host # Get the client's IP address
|
||||
|
||||
message = f"""
|
||||
|
||||
Another interpreter sent this message to you: {message}
|
||||
To respond, send a POST request to {client_host}/i/.
|
||||
|
||||
""".strip()
|
||||
|
||||
r.lpush("to_main", {
|
||||
"role": "computer",
|
||||
"type": "message",
|
||||
"content": message
|
||||
})
|
||||
|
||||
if __name__ == "__main__":
|
||||
uvicorn.run(app, host="0.0.0.0", port=8000)
|
@ -1,11 +1,48 @@
|
||||
import time
|
||||
import redis
|
||||
|
||||
# Set up Redis connection
|
||||
r = redis.Redis(host='localhost', port=6379, db=0)
|
||||
|
||||
def get_dmesg(after):
|
||||
"""
|
||||
Is this the way to do this?
|
||||
"""
|
||||
messages = []
|
||||
with open('/var/log/dmesg', 'r') as file:
|
||||
lines = file.readlines()
|
||||
for line in lines:
|
||||
timestamp = float(line.split(' ')[0].strip('[]'))
|
||||
if timestamp > after:
|
||||
messages.append(line)
|
||||
return messages
|
||||
|
||||
def custom_filter(message):
|
||||
# Check for {TO_INTERPRETER{ message here }TO_INTERPRETER} pattern
|
||||
if '{TO_INTERPRETER{' in message and '}TO_INTERPRETER}' in message:
|
||||
start = message.find('{TO_INTERPRETER{') + len('{TO_INTERPRETER{')
|
||||
end = message.find('}TO_INTERPRETER}', start)
|
||||
return message[start:end]
|
||||
# Check for USB mention
|
||||
elif 'USB' in message:
|
||||
return message
|
||||
# Check for network related keywords
|
||||
elif any(keyword in message for keyword in ['network', 'IP', 'internet', 'LAN', 'WAN', 'router', 'switch']):
|
||||
return message
|
||||
else:
|
||||
return None
|
||||
|
||||
last_timestamp = time.time()
|
||||
|
||||
while True:
|
||||
messages = get_dmesg(after=last_timestamp)
|
||||
last_timestamp = time.time()
|
||||
|
||||
messages_for_core = []
|
||||
for message in messages:
|
||||
if passes_filter(message)
|
||||
send_to_main(to_lmc(message))
|
||||
if custom_filter(message):
|
||||
messages_for_core.append(message)
|
||||
if messages_for_core != []:
|
||||
r.rpush('to_core', "\n".join(messages_for_core))
|
||||
|
||||
time.sleep(1)
|
||||
time.sleep(5)
|
Loading…
Reference in new issue