Skip to content

Commit

Permalink
修改热力图
Browse files Browse the repository at this point in the history
  • Loading branch information
malinkang committed Jan 13, 2024
1 parent 27a5873 commit 82bcbf5
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
17 changes: 14 additions & 3 deletions .github/workflows/read_time.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
DAY_DATABASE_NAME: ${{ vars.DAY_DATABASE_NAME }}
REF: ${{ github.ref }}
REPOSITORY: ${{ github.repository }}
YEAR: ${{ vars.YEAR }}
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -38,17 +39,27 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Remove folder
run: rm -rf ./OUT_FOLDER
- name: Set default year if not provided
run: echo "YEAR=$(date +"%Y")" >> $GITHUB_ENV
if: env.YEAR == ''
- name: weread heatmap
run: |
github_heatmap weread --weread_cookie "${{secrets.WEREAD_COOKIE}}" --year $(date +"%Y") --me "${{secrets.NAME}}" --with-animation --background-color=#ffffff --track-color=#ACE7AE --special-color1=#69C16E --special-color2=#549F57 --dom-color=#EBEDF0 --text-color=#000000
github_heatmap weread --weread_cookie "${{secrets.WEREAD_COOKIE}}" --year $YEAR --me "${{secrets.NAME}}" --with-animation --background-color=${{ vars.background_color||'#FFFFFF'}} --track-color=${{ vars.track_color||'#ACE7AE'}} --special-color1=${{ vars.special_color||'#69C16E'}} --special-color2=${{ vars.special_color2||'#549F57'}} --dom-color=${{ vars.dom_color||'#EBEDF0'}} --text-color=${{ vars.text_color||'#000000'}}
- name: Rename weread.svg to a random name
run: |
RANDOM_FILENAME=$(uuidgen).svg
mv ./OUT_FOLDER/weread.svg ./OUT_FOLDER/$RANDOM_FILENAME
echo "Renamed file to $RANDOM_FILENAME"
- name: push
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add .
git commit -m 'add new cover' || echo "nothing to commit"
git commit -m '生成热力图' || echo "nothing to commit"
git push || echo "nothing to push"
- name: read time sync
run: |
python -u scripts/read_time.py
Binary file modified scripts/__pycache__/notion_helper.cpython-311.pyc
Binary file not shown.
Binary file modified scripts/__pycache__/utils.cpython-311.pyc
Binary file not shown.
Binary file modified scripts/__pycache__/weread_api.cpython-311.pyc
Binary file not shown.
21 changes: 19 additions & 2 deletions scripts/read_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from datetime import datetime
from datetime import timedelta
import os
import time

import pendulum

Expand Down Expand Up @@ -39,16 +40,32 @@ def insert_to_notion(page_id,timestamp,duration):
notion_helper.client.pages.create(parent=parent,icon = get_icon("https://www.notion.so/icons/target_red.svg"),properties=properties)


def get_file():
# 设置文件夹路径
folder_path = './OUT_FOLDER'

# 检查文件夹是否存在
if os.path.exists(folder_path) and os.path.isdir(folder_path):
entries = os.listdir(folder_path)

file_name = entries[0] if entries else None
return file_name
else:
print("OUT_FOLDER does not exist.")
return None

if __name__ == "__main__":
weread_cookie = os.getenv("WEREAD_COOKIE")
notion_helper = NotionHelper()
weread_api = WeReadApi()
if(os.path.isfile("./OUT_FOLDER/weread.svg")):
old_image_file = "./OUT_FOLDER/weread.svg"
image_file = get_file()
if image_file:
image_url = notion_helper.image_dict.get("url")
block_id = notion_helper.image_dict.get("id")
branch = os.getenv("REF").split("/")[-1]
repository = os.getenv("REPOSITORY")
new_image_url = f"https://raw.githubusercontent.com/{repository}/{branch}/OUT_FOLDER/weread.svg"
new_image_url = f"https://raw.githubusercontent.com/{repository}/{branch}/OUT_FOLDER/{image_file}"
if(image_url and block_id):
notion_helper.update_image_block_link(block_id,new_image_url)
api_data = weread_api.get_api_data()
Expand Down

0 comments on commit 82bcbf5

Please sign in to comment.