1+ #!/usr/bin/env python3
2+ # -*- coding: utf-8 -*-
3+ import json
4+ import os
5+ import random
6+ import requests
7+ import subprocess
8+
9+ def get_cid (fil ):
10+ cid = input ("请输入CID(直接回车导入本地文件):" )
11+ if cid == "" :
12+ file_path = input ("请输入文件绝对路径:" )
13+ while os .path .exists (file_path ) == False :
14+ print ("该路径文件不存在,请重新输入" )
15+ else :
16+ if os .path .isfile (file_path ):
17+ ipfs_add_cmd = """ipfs add %s""" % file_path
18+ ipfs_cli_output = str (subprocess .check_output (ipfs_add_cmd .split ()), "utf-8" )
19+ cid = ipfs_cli_output .split ()[- 2 ]
20+ elif os .path .isdir (file_path ):
21+ ipfs_add_cmd = """ipfs add -r %s""" % file_path
22+ ipfs_cli_output = str (subprocess .check_output (ipfs_add_cmd .split ()), "utf-8" )
23+ cid = ipfs_cli_output .split ()[- 2 ]
24+ else :
25+ pass
26+ else :
27+ pass
28+ print ("已获取到CID:%s" % cid )
29+ return cid
30+
31+ def get_vshare_nodeid ():
32+ minerid_list = json .loads (requests .get ('https://fil-api.ipns.tech/filtools/miner_list.php' ).text )
33+ minerid_list = minerid_list ["data" ]
34+ minerid = random .choice (minerid_list )
35+ print ("已选取到节点:%s" % minerid )
36+ return minerid
37+
38+
39+ def ipfs_gc (cid ):
40+ print ("开始垃圾清理" )
41+ subprocess .run ("ipfs pin rm %s" % cid , shell = True )
42+ print ("垃圾清理已完成" )
43+ pass
44+
45+ #Main
46+ mode = input (" 1.托管数据至VshareCloud\n 2.托管数据到自定义FileCoin节点\n 3.托管数据到全球FileCoin节点(性价比最高,但是交易成功率与数据可靠性未知)\n 请选择交易类型(输入纯数字):" )
47+ deal_duration = input ("请输入交易天数(纯数字,最低180天):" )
48+ cid = get_cid ()
49+ if mode == "1" :
50+ minerid = get_vshare_nodeid ()
51+ cmd = "expect /opt/vsharecloud-tools/scripts/single_deal.sh %s %s %s" % (cid , deal_duration , minerid )
52+ subprocess .run (cmd , shell = True )
53+ print ("交易已发起,请通过命令 lotus client list-deals 查询交易状态" )
54+ if_gc = input ("是否清理刚刚导入的文件缓存?(y/n)" )
55+ if if_gc == "y" :
56+ ipfs_gc (cid )
57+ else :
58+ print ("程序退出" )
59+ exit ()
60+ elif mode == "2" :
61+ minerid = input ("请输入FileCoin节点ID(格式:f0xxxxx):" )
62+ cmd = "expect /opt/vsharecloud-tools/scripts/single_deal.sh %s %s %s" % (cid , deal_duration , minerid )
63+ subprocess .run (cmd , shell = True )
64+ print ("交易已发起,请通过命令 lotus client list-deals 查询交易状态" )
65+ if_gc = input ("是否清理刚刚导入的文件缓存?(y/n)" )
66+ if if_gc == "y" :
67+ ipfs_gc (cid )
68+ else :
69+ print ("程序退出" )
70+ exit ()
71+ elif mode == "3" :
72+ deal_times = input ("请输入本次发起的交易次数(纯数字):" )
73+ max_budget = input ("请输入最大的价格预算(纯数字)" )
74+ cmd = "expect /opt/vsharecloud-tools/scripts/global_deal.sh %s %s %s %s" % (cid , deal_duration , max_budget , deal_times )
75+ subprocess .run (cmd , shell = True )
76+ print ("交易已发起,请通过命令 lotus client list-deals 查询交易状态" )
77+ if_gc = input ("是否清理刚刚导入的文件缓存?(y/n)" )
78+ if if_gc == "y" :
79+ ipfs_gc (cid )
80+ else :
81+ print ("程序退出" )
82+ exit ()
83+ else :
84+ print ("输入无效,退出程序" )
85+ exit ()
0 commit comments