add apscheduler with default midnight utc

This commit is contained in:
Alexander 2024-07-19 20:51:40 -04:00
parent 8f34fc8a4a
commit 6f534bdae3
3 changed files with 24 additions and 5 deletions

23
main.py
View file

@ -4,10 +4,13 @@ import sys
import time import time
import logging import logging
from logging.handlers import TimedRotatingFileHandler from logging.handlers import TimedRotatingFileHandler
from datetime import datetime, UTC
from dotenv import load_dotenv from dotenv import load_dotenv
from web3 import Web3 from web3 import Web3
from web3_multi_provider import FallbackProvider from web3_multi_provider import FallbackProvider
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.triggers.cron import CronTrigger
load_dotenv() load_dotenv()
secret = os.getenv('SECRET') secret = os.getenv('SECRET')
@ -31,6 +34,7 @@ logging.basicConfig(
logging.StreamHandler(sys.stdout) logging.StreamHandler(sys.stdout)
] ]
) )
logging.getLogger('apscheduler').setLevel(logging.ERROR)
os.makedirs("data/wallets", exist_ok=True) os.makedirs("data/wallets", exist_ok=True)
wallet_keystore = "./data/wallets/{}/keystore".format(wallet_address) wallet_keystore = "./data/wallets/{}/keystore".format(wallet_address)
if not os.path.isfile(wallet_keystore): if not os.path.isfile(wallet_keystore):
@ -156,7 +160,7 @@ def main():
# skip if no intention to send/burn lp tokens # skip if no intention to send/burn lp tokens
if wallet_address == burn_address or not burn_address: if wallet_address == burn_address or not burn_address:
continue continue
# transfer lp tokens to burn address # transfer lp tokens to burn address
for log in tx_receipt['logs']: for log in tx_receipt['logs']:
if log['topics'][0].hex() != '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef': if log['topics'][0].hex() != '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef':
@ -196,5 +200,18 @@ if __name__ == '__main__':
print("-" * 50) print("-" * 50)
print("Frens LP and Burn") print("Frens LP and Burn")
print("-" * 50) print("-" * 50)
main() # setup scheduler to run at midnight every day
print("-" * 50) scheduler = BackgroundScheduler()
scheduler.start()
cron = CronTrigger(day="*", hour="0", minute="0", second="0")
scheduler.add_job(main, trigger=cron)
# display the next schedule run time and how many hours until it triggers
next_run = cron.get_next_fire_time(datetime.now(UTC), datetime.now(UTC))
next_time = next_run.timestamp()
current_time = datetime.now().timestamp()
print("Next scheduled run: {} (in {} hours)".format(next_run.strftime('%Y-%m-%d %H:%M:%S'), round((next_time - current_time) / 60 / 60, 2)))
try:
while True:
time.sleep(5)
except KeyboardInterrupt:
print("-" * 50)

View file

@ -1,3 +1,4 @@
web3 web3
web3-multi-provider web3-multi-provider
python-dotenv python-dotenv
apscheduler

View file

@ -1,3 +1,4 @@
SECRET=changeme SECRET=changeme
WALLET_ADDRESS= WALLET_ADDRESS=
BURN_ADDRESS= BURN_ADDRESS=
TZ=Etc/UTC