Skip to content

Commit

Permalink
Merge branch 'CherryLover-main'
Browse files Browse the repository at this point in the history
  • Loading branch information
malinkang committed Mar 21, 2024
2 parents 50dc365 + a57fee5 commit 4048263
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/weread.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
pip install -r requirements.txt
- name: weread sync
run: |
python scripts/weread.py "${{secrets.WEREAD_COOKIE}}" "${{secrets.NOTION_TOKEN}}" "${{secrets.NOTION_DATABASE_ID}}" "${{ github.ref }}" "${{ github.repository }}" --styles 0 1 2 --colors 0 1 2 3 4 5
python scripts/weread.py "${{secrets.WEREAD_COOKIE}}" "${{secrets.NOTION_TOKEN}}" "${{secrets.NOTION_DATABASE_ID}}" "${{ github.ref }}" "${{ github.repository }}" --styles 0 1 2 --colors 0 1 2 3 4 5 --cc_url "${{ secrets.CC_URL }}" --cc_id "${{ secrets.CC_ID }}" --cc_secret "${{ secrets.CC_PASSWORD }}"
- name: Set default year if not provided
run: echo "YEAR=$(date +"%Y")" >> $GITHUB_ENV
if: env.YEAR == ''
Expand All @@ -37,4 +37,4 @@ jobs:
git config --local user.name "GitHub Action"
git add .
git commit -m 'add new cover' || echo "nothing to commit"
git push || echo "nothing to push"
git push || echo "nothing to push"
2 changes: 1 addition & 1 deletion OUT_FOLDER/weread.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions scripts/weread.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,24 @@ def download_image(url, save_dir="cover"):
return save_path


def try_get_cloud_cookie(cc_url, cc_id, cc_secret):
if cc_url == "" or cc_id == "" or cc_secret == "":
return ""
req_url = cc_url + "/get/" + cc_id
result = ""
data = {"password": cc_secret}
response = requests.post(req_url, data=data)
if response.status_code == 200:
data = response.json()
cookie_data = data.get("cookie_data")
if cookie_data and "weread.qq.com" in cookie_data:
cookies = cookie_data["weread.qq.com"]
cookie_str = "; ".join([f"{cookie['name']}={cookie['value']}" for cookie in cookies])
result = cookie_str
return result



if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("weread_cookie")
Expand All @@ -353,10 +371,22 @@ def download_image(url, save_dir="cover"):
parser.add_argument("repository")
parser.add_argument("--styles", nargs="+", type=int, help="划线样式")
parser.add_argument("--colors", nargs="+", type=int, help="划线颜色")
parser.add_argument("--cc_url", nargs="+", type=str, help="CookieCloud url")
parser.add_argument("--cc_id", nargs="+", type=str, help="CookieCloud id")
parser.add_argument("--cc_secret", nargs="+", type=str, help="CookieCloud secret")
options = parser.parse_args()
weread_cookie = options.weread_cookie
database_id = options.database_id
notion_token = options.notion_token
# 如果 cc 相关的配置全部不为空,则启用 cc,重新获取 weread_cookie
if options.cc_url and options.cc_id and options.cc_secret:
cc_cookie = try_get_cloud_cookie(options.cc_url[0], options.cc_id[0], options.cc_secret[0])
if cc_cookie != "":
print("use cloud cookie")
weread_cookie = cc_cookie
else:
print("use local cookie")

ref = options.ref
branch = ref.split("/")[-1]
repository = options.repository
Expand Down
Empty file added weread.py
Empty file.

0 comments on commit 4048263

Please sign in to comment.