Skip to content

Commit

Permalink
add verified asa icons to json files too
Browse files Browse the repository at this point in the history
  • Loading branch information
gokselcoban committed Nov 14, 2023
1 parent 4a163a8 commit fb5d05d
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 5 deletions.
30 changes: 26 additions & 4 deletions .github/workflows/upload-to-s3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ name: upload-to-s3

on:
push:
branches:
- main
# branches:
# - main
schedule:
# Schedule to run at midnight UTC
- cron: '0 0 * * *'

permissions:
id-token: write # This is required for requesting the JWT
Expand All @@ -22,11 +25,26 @@ jobs:
with:
node-version: 18.13.0

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

# - name: Configure AWS Credentials
# uses: aws-actions/configure-aws-credentials@v1
# with:
# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
# aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# aws-region: eu-central-1

- name: Install dependencies
run: npm ci

- name: Prepare build folder
run: INDEXER_TOKEN=${{ secrets.INDEXER_TOKEN }} npm run build

- name: Fetch verified asset icons (verified by Pera)
run: python fetch_verified_asa_icons.py

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
Expand All @@ -35,5 +53,9 @@ jobs:
role-session-name: tinyman-asa-list--github-oidc
aws-region: eu-central-1

- name: Upload to S3 bucket
run: aws s3 sync ./build/ s3://asa-icons --acl=public-read
# - name: Upload to S3 bucket
# run: aws s3 sync ./build/ s3://asa-icons --acl=public-read

- uses: actions/upload-artifact@v3
with:
path: ./build/*.json
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_STORE
build/
node_modules
node_modules
*idea
57 changes: 57 additions & 0 deletions fetch_verified_asa_icons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import json
from pathlib import Path

import requests

current_dir = Path(__file__).parent
build_directory = current_dir / "build"
assets_file_path = build_directory / "assets.json"
icons_file_path = build_directory / "icons.json"

with open(assets_file_path) as file:
assets_data = json.load(file)

with open(icons_file_path) as file:
icons_data = json.load(file)


def process_assets(assets):
for asset in assets:
asset_id = str(asset["asset_id"])
if asset_id not in assets_data and asset["logo"]:
logo_url = asset["logo"] + "?format=png&height=256&width=256"

icons_data[asset_id] = logo_url

assets_data[asset_id] = {
"id": asset_id,
"name": asset["name"],
"unit_name": asset["unit_name"],
"url": "",
"decimals": asset["fraction_decimals"],
"total_amount": asset["total"],
"deleted": asset["is_deleted"],
"logo": {
"png": logo_url,
"svg": "",
},
}


response = requests.get("https://api.perawallet.app/v1/assets/?status=verified").json()
# Check and process the first page
if "results" in response:
process_assets(response["results"])

# Iterate over the next pages
while "next" in response and response["next"]:
response = requests.get(response["next"]).json()
if "results" in response:
process_assets(response["results"])


with open(assets_file_path, 'w') as file:
json.dump(assets_data, file)

with open(icons_file_path, 'w') as file:
json.dump(icons_data, file)

0 comments on commit fb5d05d

Please sign in to comment.