{"id":25011356,"url":"https://github.com/spirita1204/leetcode","last_synced_at":"2025-03-30T02:43:57.797Z","repository":{"id":274428285,"uuid":"922839903","full_name":"spirita1204/Leetcode","owner":"spirita1204","description":"🎯Record my Leetcode daily challenge📚Automatically package the LeetCode problems written daily into an .MD file through Notion using a Zapier workflow + Webhooks and upload it to the github.","archived":false,"fork":false,"pushed_at":"2025-03-28T00:54:58.000Z","size":1328,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-28T01:44:38.763Z","etag":null,"topics":["github-api","leetcode","notion","workflow","zapier"],"latest_commit_sha":null,"homepage":"https://leetcode.com/u/spirita1204/","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spirita1204.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-27T07:04:51.000Z","updated_at":"2025-03-28T00:55:01.000Z","dependencies_parsed_at":"2025-02-27T01:35:24.190Z","dependency_job_id":"c74a5940-10eb-40a2-ab74-73954eb6ca5d","html_url":"https://github.com/spirita1204/Leetcode","commit_stats":null,"previous_names":["spirita1204/leetcode"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spirita1204%2FLeetcode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spirita1204%2FLeetcode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spirita1204%2FLeetcode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spirita1204%2FLeetcode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spirita1204","download_url":"https://codeload.github.com/spirita1204/Leetcode/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246269911,"owners_count":20750319,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["github-api","leetcode","notion","workflow","zapier"],"created_at":"2025-02-05T05:24:19.783Z","updated_at":"2025-03-30T02:43:57.790Z","avatar_url":"https://github.com/spirita1204.png","language":null,"readme":"![LeetCode Total](https://img.shields.io/badge/LeetCode%20Solved-897-red) ![Easy](https://img.shields.io/badge/Easy-287-green) ![Medium](https://img.shields.io/badge/Medium-536-yellow) ![Hard](https://img.shields.io/badge/Hard-74-blue) ![Acceptance Rate](https://img.shields.io/badge/Acceptance%20Rate-63.16%25-lightgrey) ![Ranking](https://img.shields.io/badge/Ranking-28227-purple)\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n## LeetCode Statistics\n\u003cimg src=\"https://leetcard.jacoblin.cool/spirita1204\" alt=\"My LeetCode statistics\" /\u003e\n\nAutomatically package the LeetCode problems written daily into an .md file through Notion using a **Zapier workflow + Webhooks** and upload it to the github.\n\n\u003ch3 align=\"left\"\u003eTools:\u003c/h3\u003e\n\u003cp align=\"left\"\u003e \n  \u003ca href=\"https://www.notion.com/zh-tw\" target=\"_blank\" rel=\"noreferrer\"\u003e \u003cimg src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/e/e9/Notion-logo.svg/1200px-Notion-logo.svg.png\" alt=\"notion\" width=\"40\" height=\"40\"/\u003e \u003c/a\u003e\n  \u003ca href=\"https://zapier.com/l/home?utm_source=google\u0026utm_medium=cpc\u0026utm_campaign=gaw-gbl-nua-search-brand-remarketing\u0026utm_term=zapier\u0026utm_content=21098\u0026utm_ads_campaign_id=17613359682\u0026utm_ads_adset_id=136156400777\u0026utm_ads_ad_id=607316261972\u0026gad_source=1\u0026gclid=CjwKCAiAneK8BhAVEiwAoy2HYR5IH5IRV3K59qshBJuy2OkkjfCwb1R8IvfBZOOB6XihnrbiIINeyBoClSMQAvD_BwE\" target=\"_blank\" rel=\"noreferrer\"\u003e \u003cimg src=\"https://banner2.cleanpng.com/20180805/gpt/kisspng-zapier-logo-world-wide-web-product-mobile-app-zapier-integration-verticalresponse-5b669ba2609b29.1196434715334511703957.jpg\" alt=\"zapier\" width=\"40\" height=\"40\"/\u003e \u003c/a\u003e\n  \u003ca href=\"https://docs.github.com/en/rest\" target=\"_blank\" rel=\"noreferrer\"\u003e \u003cimg src=\"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRw8AHWfvfU99X7gPZDKalDYZWcC_ROQc4Fag\u0026s\" alt=\"github_api\" width=\"40\" height=\"40\"/\u003e \u003c/a\u003e \n\u003c/p\u003e\n\u003cimg src=\"https://i.ibb.co/tpCQ8Yb/2025-01-28-165335.png\" width=\"60%\"\u003e\n\u003cimg src=\"https://i.ibb.co/M1qMhrS/2025-01-28-164652.png\" width=\"60%\"\u003e\n\n```jsx\n-------------------------------\n1.Run Javascript 取代標題底線\n-------------------------------\n\n// this is wrapped in an `async` function\n// you can use await throughout the function\nconst content = inputData.content;\nconst replacedContent = content\n  .replace(/\\s+/g, '-') // 將所有空白替換為 '-'\n  .replace(/\\./g, '')   // 移除 '.'\n  .replace(/\\//g, '-'); // 將 '/' 替換為 '-'\n\nreturn { result: replacedContent };\n\n-------------------------------\n2.Run Javascript 將內容 Base64 進行傳輸\n-------------------------------\n\nconst content = inputData.content;\nconst methods = inputData.methods;\nconst dataStructure = inputData.dataStructure;\nconst diff = inputData.diff;\nconst similar = inputData.similar;\n// Information to prepend\nlet combinedContent = \"\";\ncombinedContent += \"# \" + inputData.title + \"  \\n\\n  \";// 標題\nif(methods)\n    combinedContent += \"Methods: \" + methods + \" \u003c/br\u003e \";\nif(dataStructure)\n    combinedContent += \"Data Structure: \" + dataStructure + \" \u003c/br\u003e \";\nif(diff)\n    combinedContent += \"Difficulty: \" + diff + \" \u003c/br\u003e \";\nif(similar)\n    combinedContent += \"Similar: \" + similar + \" \u003c/br\u003e \";\ncombinedContent += (\"\u003c/br\u003e\" + content);\n// Base64 encode the combined content\nconst encodedContent = Buffer.from(combinedContent).toString('base64');\n\nreturn { encoded: encodedContent };\n\n-------------------------------\n3.Run Python 透過Github API 自動創建/更新文件\n-------------------------------\n\nimport requests\nimport base64\n\n# Define the inputData with necessary details (make sure to pass the actual data)\ninputData = {\n    'title': inputData['title'] ,  # Replace with the actual file title\n    'encoded': inputData['encoded']  # Replace with the actual base64-encoded content\n}\n\n# URL and data placeholders\nurl = f\"https://api.github.com/repos/spirita1204/Leetcode/contents/{inputData['title']}.md\"\n\n# Data for the request\ndata = {\n    \"message\": f\"Add {inputData['title']}.md file\",\n    \"content\": inputData['encoded'],  # Base64-encoded content\n    \"branch\": \"main\"\n}\n\n# Authorization and headers\nheaders = {\n    \"Content-Type\": \"application/json\",\n    \"Authorization\": \"Bearer #YOUR_AUTHORIZATION_TOKEN#\",\n    \"X-GitHub-Api-Version\": \"2022-11-28\"\n}\n\n# Make the PUT request to GitHub API\nresponse = requests.put(url, json=data, headers=headers)\n\n# Check the response\nif response.status_code == 201:\n    print(\"File created successfully!\")\nelse:\n    print(f\"Error: {response.status_code}, {response.text}\")\n    if(response.status_code == 422): #如果是文件已存在的錯誤碼，則嘗試覆蓋文件\n        # 獲取文件sha\n        response = requests.get(url, headers=headers)\n        if response.status_code == 200:\n            sha = response.json()['sha']\n            print(\"sha: \", sha)\n            dataAddSha = {\n                \"message\": f\"Update {inputData['title']}.md file\",\n                \"content\": inputData['encoded'],  # Base64-encoded content\n                \"sha\": sha\n            }\n            # 更新文件\n            response = requests.put(url, json=dataAddSha, headers=headers)\n            print(\"File updated successfully!\")\n        else:\n            print(f\"Error: {response.status_code}, {response.text}\")\n# Returning the result (for Zapier or further use in your code)\n\nreturn {'success': 'success'}\n\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspirita1204%2Fleetcode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspirita1204%2Fleetcode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspirita1204%2Fleetcode/lists"}