Keron commited on
Commit
330a897
·
verified ·
1 Parent(s): 0f243af

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -0
app.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+
3
+ def send_file_to_telegram(bot_token, chat_id, file_path, caption=None):
4
+ url = f"https://api.telegram.org/bot{bot_token}/sendDocument"
5
+ with open(file_path, "rb") as f:
6
+ files = {"document": f}
7
+ data = {"chat_id": chat_id}
8
+ if caption:
9
+ data["caption"] = caption
10
+ response = requests.post(url, data=data, files=files)
11
+ return response.json()
12
+ if __name__ == '__main__':
13
+ TXT_SAVE_PATH = "output.txt"
14
+ result_txt = 'test'
15
+
16
+ with open(TXT_SAVE_PATH, "w", encoding="utf-8") as f:
17
+ f.write(result_txt)
18
+ tg_result = send_file_to_telegram("5149834858:AAEnQcjS4fH9iUPLGUI3LvFqHo0oWDA6XCU", "1759334982", TXT_SAVE_PATH, caption="自动上传的txt文件")
19
+