soiz1 commited on
Commit
5af60be
·
verified ·
1 Parent(s): 54d6299

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -67
app.py CHANGED
@@ -1,67 +1,42 @@
1
- import os
2
- import shutil
3
- import zipfile
4
- import requests
5
- from flask import Flask, send_file
6
- from threading import Thread
7
-
8
- # === 設定 ===
9
- repo_owner = "eaglerforge"
10
- repo_name = "EaglerForgeInjector"
11
- branch = "main"
12
- directory = "examplemods"
13
-
14
- api_url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/contents/{directory}?ref={branch}"
15
- headers = {"Accept": "application/vnd.github.v3+json"}
16
- temp_dir = "temp_examplemods"
17
- zip_name = "examplemods.zip"
18
-
19
- app = Flask(__name__)
20
-
21
- def download_directory():
22
- os.makedirs(temp_dir, exist_ok=True)
23
- response = requests.get(api_url, headers=headers)
24
- if response.status_code != 200:
25
- raise Exception(f"GitHub API error: {response.status_code} - {response.text}")
26
- for file in response.json():
27
- if file["type"] == "file":
28
- download_url = file["download_url"]
29
- local_path = os.path.join(temp_dir, file["name"])
30
- print(f"Downloading {file['name']}...")
31
- r = requests.get(download_url)
32
- with open(local_path, "wb") as f:
33
- f.write(r.content)
34
-
35
- def zip_directory():
36
- with zipfile.ZipFile(zip_name, "w", zipfile.ZIP_DEFLATED) as zipf:
37
- for root, _, files in os.walk(temp_dir):
38
- for file in files:
39
- file_path = os.path.join(root, file)
40
- zipf.write(file_path, os.path.relpath(file_path, temp_dir))
41
- print(f"{zip_name} created!")
42
-
43
- @app.route("/")
44
- def index():
45
- return f'''
46
- <h2>ZIPファイルをダウンロード</h2>
47
- <a href="/download">examplemods.zip をダウンロード</a>
48
- '''
49
-
50
- @app.route("/download")
51
- def download_file():
52
- return send_file(zip_name, as_attachment=True)
53
-
54
- def start_flask():
55
- app.run(host="0.0.0.0", port=7860)
56
-
57
- if __name__ == "__main__":
58
- try:
59
- download_directory()
60
- zip_directory()
61
- finally:
62
- shutil.rmtree(temp_dir)
63
-
64
- print("ローカルサーバーを起動中... http://localhost:8000/")
65
- Thread(target=start_flask).start()
66
-
67
- input("Enterで終了します。")
 
1
+ from huggingface_hub import HfApi
2
+
3
+ # スペースのリポジトリ情報
4
+ repo_id = "soiz1/s4s-editor"
5
+ repo_type = "space" # "model" や "dataset" ではなく "space" を指定
6
+
7
+ # 除外したい最初のコミットSHA
8
+ exclude = {
9
+ "d597f12958d455343f3e615926b940275157dd6a",
10
+ "6bcb42f9f3a292e3ee572372ca4dd19054e51b3f"
11
+ }
12
+
13
+ api = HfApi()
14
+
15
+ # コミット履歴の取得
16
+ commits = api.list_repo_commits(repo_id=repo_id, repo_type=repo_type)
17
+
18
+ # 除外コミット以外の変更されたファイルを格納
19
+ files = set()
20
+ for commit in commits:
21
+ sha = commit.sha
22
+ if sha in exclude:
23
+ continue
24
+ diff = api.get_commit_diff(
25
+ repo_id=repo_id,
26
+ repo_type=repo_type,
27
+ revision=sha
28
+ )
29
+ # diff は "diff --git a/path/to/file b/path/to/file" のような形式
30
+ for line in diff.splitlines():
31
+ if line.startswith("diff --git"):
32
+ parts = line.split()
33
+ # a/… と b/… からファイルパスを抽出
34
+ a = parts[2][2:]
35
+ b = parts[3][2:]
36
+ # 同じなら片方だけ使う
37
+ files.add(a if a == b else a)
38
+
39
+ # 結果の表示
40
+ print("修正されたファイル一覧(重複除外、指定コミットは除く):")
41
+ for f in sorted(files):
42
+ print(f)