diff --git a/.github/workflows/update_from_dune.yml b/.github/workflows/update_from_dune.yml new file mode 100644 index 0000000..bc571b5 --- /dev/null +++ b/.github/workflows/update_from_dune.yml @@ -0,0 +1,33 @@ +name: Python CI + +on: + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - uses: actions/setup-python@v4 + with: + python-version: '3.9' + + - name: Log directory structure + run: | + pwd + ls -R + + - name: pip requirements + run: pip install -r requirements.txt + + - name: Update all queries from Dune + env: + DUNE_API_KEY: ${{ secrets.DUNE_API_KEY }} + run: python -u github_workflows/update_to_dune.py + + - name: Print name + run: echo "Hello ${{ secrets.ENV_TEST }}" + + \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/update_to_dune.yml similarity index 84% rename from .github/workflows/main.yml rename to .github/workflows/update_to_dune.yml index 5263fcd..505aafc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/update_to_dune.yml @@ -24,10 +24,10 @@ jobs: - name: pip requirements run: pip install -r requirements.txt - - name: Run test script + - name: Update all queries from Dune env: DUNE_API_KEY: ${{ secrets.DUNE_API_KEY }} - run: python -u github_workflows/action.py + run: python -u github_workflows/update_to_dune.py - name: Print name run: echo "Hello ${{ secrets.ENV_TEST }}" diff --git a/github_workflows/action.py b/github_workflows/update_from_dune.py similarity index 100% rename from github_workflows/action.py rename to github_workflows/update_from_dune.py diff --git a/github_workflows/update_to_dune copy.py b/github_workflows/update_to_dune copy.py new file mode 100644 index 0000000..d6bd663 --- /dev/null +++ b/github_workflows/update_to_dune copy.py @@ -0,0 +1,42 @@ +import os +import yaml +from dune_client.client import DuneClient +from dotenv import load_dotenv +import sys +import codecs + +# Set the default encoding to UTF-8 +sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach()) + +dotenv_path = os.path.join(os.path.dirname(__file__), '..', '.env') +load_dotenv(dotenv_path) + +dune = DuneClient.from_env() + +# Read the queries.yml file +with open('queries.yml', 'r', encoding='utf-8') as file: + data = yaml.safe_load(file) + +# Extract the query_ids from the data +query_ids = [id for id in data['query_ids']] + +for id in query_ids: + query = dune.get_query(id) + print('updating query {}, {}'.format(query.base.query_id, query.base.name)) + + # Check if file exists + file_path = os.path.join(os.path.dirname(__file__), '..', 'queries', f'query_{query.base.query_id}.sql') + if os.path.exists(file_path): + # Read the content of the file + with open(file_path, 'r', encoding='utf-8') as file: + text = file.read() + + # Update existing file + dune.update_query( + query_id, + # All parameters below are optional + query_sql=text, + ) + + else: + print('file not found, {}'.format(query_{query.base.query_id}.sql)) diff --git a/queries/query_3237721.sql b/queries/query_3237721.sql index f2fb92e..42866ac 100644 --- a/queries/query_3237721.sql +++ b/queries/query_3237721.sql @@ -1,6 +1,7 @@ -- DEX by volume 🏦 -- https://dune.com/queries/3237721 +--andrew is testing actions WITH seven_day_volume AS (