log processor
This commit is contained in:
36
crypto/sol/modules/log_processor.py
Normal file
36
crypto/sol/modules/log_processor.py
Normal file
@ -0,0 +1,36 @@
|
||||
import os
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
from .storage import store_transaction
|
||||
|
||||
LOG_DIRECTORY = "path/to/log/directory"
|
||||
FILE_MASK = "*.log"
|
||||
|
||||
async def process_log_file(file_path):
|
||||
# Read the file and extract transaction data
|
||||
with open(file_path, 'r') as file:
|
||||
data = file.read()
|
||||
# Assume data is parsed into these variables
|
||||
wallet_id = "extracted_wallet_id"
|
||||
transaction_type = "extracted_transaction_type"
|
||||
sell_currency = "extracted_sell_currency"
|
||||
sell_amount = 0.0
|
||||
sell_value = 0.0
|
||||
buy_currency = "extracted_buy_currency"
|
||||
buy_amount = 0.0
|
||||
buy_value = 0.0
|
||||
solana_signature = "extracted_solana_signature"
|
||||
details = {}
|
||||
|
||||
# Store the transaction
|
||||
await store_transaction(wallet_id, transaction_type, sell_currency, sell_amount, sell_value, buy_currency, buy_amount, buy_value, solana_signature, details)
|
||||
|
||||
# Rename the file to append '_saved'
|
||||
new_file_path = file_path.with_name(file_path.stem + "_saved" + file_path.suffix)
|
||||
os.rename(file_path, new_file_path)
|
||||
|
||||
async def watch_for_new_logs():
|
||||
while True:
|
||||
for file_path in Path(LOG_DIRECTORY).glob(FILE_MASK):
|
||||
await process_log_file(file_path)
|
||||
await asyncio.sleep(10) # Check every 10 seconds
|
Reference in New Issue
Block a user