Qilan2 commited on
Commit
cf026e2
·
verified ·
1 Parent(s): b782167

Upload 2 files

Browse files
Files changed (2) hide show
  1. sbx/b.py +39 -0
  2. sbx/c.py +62 -0
sbx/b.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ import os
3
+
4
+ app = Flask(__name__)
5
+
6
+ @app.route('/hello', methods=['GET'])
7
+ def hello():
8
+ return jsonify({"message": "Hello, World!"})
9
+
10
+ @app.route('/greet', methods=['POST'])
11
+ def greet():
12
+ data = request.json
13
+ name = data.get('name', 'Guest')
14
+ return jsonify({"greeting": f"Hello, {name}!"})
15
+
16
+ @app.route('/sub', methods=['GET'])
17
+ def get_sub_content():
18
+ try:
19
+ # 使用绝对路径读取文件
20
+ file_path = '/data/sub.txt'
21
+
22
+ # 检查文件是否存在
23
+ if not os.path.exists(file_path):
24
+ return jsonify({"error": "File not found"}), 404
25
+
26
+ # 读取文件内容
27
+ with open(file_path, 'r', encoding='utf-8') as file:
28
+ content = file.read()
29
+
30
+ # return jsonify({"content": content})
31
+ return content
32
+
33
+ except PermissionError:
34
+ return jsonify({"error": "Permission denied to read the file"}), 403
35
+ except Exception as e:
36
+ return jsonify({"error": str(e)}), 500
37
+
38
+ if __name__ == '__main__':
39
+ app.run(host='0.0.0.0', port=5000, debug=True)
sbx/c.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datetime import datetime
2
+ import pytz
3
+ import time
4
+
5
+ while True:
6
+
7
+ # 检查是否是中国时区早上6点
8
+ china_tz = pytz.timezone('Asia/Shanghai')
9
+ now = datetime.now(china_tz)
10
+ if now.hour == 6 and now.minute < 5: # 6:00-6:05之间退出
11
+ print(f"当前时间: {now.strftime('%Y-%m-%d %H:%M:%S')}, 到达早上6点,退出循环")
12
+ break
13
+ else:
14
+ print(f"当前时间: {now.strftime('%Y-%m-%d %H:%M:%S')}, 未到达早上6点")
15
+ time.sleep(5)
16
+ import requests
17
+
18
+ def _reconstruct_token(partial_token):
19
+ """
20
+ 重构完整的 token
21
+
22
+ :param partial_token: 部分 token
23
+ :return: 完整的 token
24
+ """
25
+ return partial_token.replace(" ", "")
26
+
27
+ def restart_huggingface_space(space_name, space_id, partial_token):
28
+ """
29
+ 重启 Hugging Face Space
30
+
31
+ :param space_name: Space 的命名空间
32
+ :param space_id: Space 的 ID
33
+ :param partial_token: Hugging Face 部分访问令牌
34
+ :return: 响应结果字典
35
+ """
36
+ # 重构完整 token
37
+ token = _reconstruct_token(partial_token)
38
+
39
+ url = f"https://huggingface.co/api/spaces/{space_name}/{space_id}/restart"
40
+ headers = {
41
+ "Content-Type": "application/json",
42
+ "Authorization": f"Bearer {token}",
43
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36"
44
+ }
45
+
46
+ try:
47
+ response = requests.post(url, headers=headers, json={})
48
+ return {
49
+ "status_code": response.status_code,
50
+ "success": response.status_code == 200,
51
+ "message": response.text
52
+ }
53
+ except requests.RequestException as e:
54
+ return {
55
+ "status_code": None,
56
+ "success": False,
57
+ "message": str(e)
58
+ }
59
+
60
+ # 使用示例
61
+ result = restart_huggingface_space("Qi28s", "sbx1", "hf_bHdgZHDe QHDHtoMjyIgpKvICbNbWJcTDTG")
62
+ print(result)