-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
67 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: sync | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- main | ||
|
||
permissions: | ||
contents: read | ||
pages: write | ||
id-token: write | ||
|
||
jobs: | ||
release: | ||
name: Release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.10' | ||
cache: pip | ||
|
||
- name: Install dependencies | ||
run: pip install -r scripts/requirements.txt | ||
|
||
- name: Sync | ||
run: python scripts/summon.py | ||
|
||
# - name: deploy | ||
# run: | | ||
# cd output | ||
# [ -f 404.html ] || ln -s index.html 404.html | ||
|
||
- name: Setup Pages | ||
uses: actions/configure-pages@v4 | ||
|
||
- name: Upload artifact | ||
uses: actions/upload-pages-artifact@v3 | ||
with: | ||
# Upload entire repository | ||
path: './output' | ||
|
||
- name: Deploy to GitHub Pages | ||
id: deployment | ||
uses: actions/deploy-pages@v4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
output/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
aiohttp | ||
requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,25 @@ | ||
import json | ||
import os | ||
import yaml | ||
import aiohttp | ||
import asyncio | ||
from pathlib import Path | ||
from typing import Dict, List, Optional, TypedDict | ||
|
||
import requests | ||
|
||
BASE_API_URL = os.getenv("BASE_API_URL", "https://example.com/api") | ||
MEMBERS_API_URL = f"{BASE_API_URL}/members" | ||
|
||
|
||
async def fetch(s: aiohttp.ClientSession, url: str) -> dict: | ||
try: | ||
async with s.get(url) as response: | ||
return await response.json() | ||
except aiohttp.ClientError as e: | ||
print(e) | ||
return await fetch(s, url) | ||
|
||
class Member(TypedDict): | ||
uuid: str | ||
name: str | ||
introduction: Optional[str] | ||
|
||
async def main(): | ||
|
||
async with aiohttp.ClientSession() as s: | ||
print(yaml.safe_load("")) | ||
# url = "https://api.coinmarketcap.com/v1/ticker/" | ||
# data = await fetch(s, url) | ||
# print(json.dumps(data, indent=4)) | ||
# { [group: str]: Member[] } | ||
def get_members() -> Dict[str, List[Member]]: | ||
return requests.get(MEMBERS_API_URL).json() | ||
|
||
|
||
asyncio.run(main()) | ||
OUTPUT_DIR = Path("output") | ||
OUTPUT_DIR.mkdir(parents=True, exist_ok=True) | ||
(OUTPUT_DIR / "member.json").write_text(json.dumps(get_members(), separators=(",", ":"))) |