Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Clean-up cron action - new Defilytica branch without PR #96

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
pip3 install -r requirements.txt
python3 main.py

- name: Create PR
- name: Create PR (to depricate after moving defilytica)
id: cpr
uses: peter-evans/create-pull-request@v5
with:
Expand All @@ -43,3 +43,12 @@ jobs:
branch: gha-fees-report
delete-branch: true
labels: "Fees-Report"

- name: Update current fees branch
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git checkout -b gha-current-fees
git add .
git commit -m "Automatic update of current epoch data"
git push -f origin gha-current-fees
29 changes: 25 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import argparse
import json
import os
from datetime import datetime
from datetime import datetime, timedelta
import pytz

from dotenv import load_dotenv
from munch import Munch
Expand All @@ -15,11 +16,31 @@
from fee_allocator.helpers import fetch_all_pools_info
from fee_allocator.tx_builder.tx_builder import generate_payload

def get_last_thursday_odd_week():
# Get the current UTC date and time
current_datetime = datetime.utcnow().replace(tzinfo=pytz.utc)

# Calculate the difference between the current weekday and Thursday (where Monday is 0 and Sunday is 6)
days_until_thursday = (current_datetime.weekday() - 3) % 7

# Check if the current week is odd
is_odd_week = current_datetime.isocalendar()[1] % 2 == 1

# Calculate the final timedelta to go back to the last Thursday on an odd week
weeks_until_next_odd_week = 0 if is_odd_week else 1
timedelta_to_last_thursday = timedelta(days=days_until_thursday + 7 * weeks_until_next_odd_week)

# Calculate the timestamp of the last Thursday at 00:00 UTC
last_thursday_odd_utc = (current_datetime - timedelta_to_last_thursday).replace(hour=0, minute=0, second=0, microsecond=0)

return last_thursday_odd_utc

now = datetime.utcnow()
DELTA = 1000
# TS_NOW = 1704326400
# TS_2_WEEKS_AGO = 1703116800
TS_NOW = int(datetime.now().timestamp()) - DELTA
TS_2_WEEKS_AGO = 1706745600
TS_NOW = int(now.timestamp()) - DELTA
TS_2_WEEKS_AGO = int(get_last_thursday_odd_week().timestamp())

parser = argparse.ArgumentParser()
parser.add_argument("--ts_now", help="Current timestamp", type=int, required=False)
Expand All @@ -42,7 +63,7 @@ def main() -> None:
# Get from input params or use default
ts_now = parser.parse_args().ts_now or TS_NOW
ts_in_the_past = parser.parse_args().ts_in_the_past or TS_2_WEEKS_AGO
print(f"\n\nRunning from timestamps {ts_in_the_past} to {ts_now}")
print(f"\n\n\n------\nRunning from timestamps {ts_in_the_past} to {ts_now}\n------\n\n\n")
output_file_name = parser.parse_args().output_file_name or "current_fees.csv"
fees_file_name = parser.parse_args().fees_file_name or "current_fees_collected.json"
fees_path = os.path.join(ROOT, "fee_allocator", "fees_collected", fees_file_name)
Expand Down