Skip to content

Commit

Permalink
feat sync script
Browse files Browse the repository at this point in the history
  • Loading branch information
a3510377 committed Apr 23, 2024
1 parent cca6ddc commit cfd8ab5
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/releaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:
- README.md
- .github/**
- '!.github/workflows/**'
paths:
- server/**

env:
# Use docker.io for Docker Hub if empty
Expand Down
48 changes: 48 additions & 0 deletions .github/workflows/sync.yaml
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
output/
2 changes: 1 addition & 1 deletion scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
aiohttp
requests
33 changes: 15 additions & 18 deletions scripts/summon.py
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=(",", ":")))

0 comments on commit cfd8ab5

Please sign in to comment.