You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.3 KiB

import os
from obs import ObsClient
from datetime import datetime
# yum install epel-release -y
# yum search python3
# yum install python36 -y
# pip3 install esdk-obs-python
# 探测IP地址
cmd = 'curl cip.cc'
res = ''
with os.popen(cmd) as fp:
bf = fp._stream.buffer.read()
try:
res = bf.decode().strip()
except UnicodeDecodeError:
res = bf.decode('gbk').strip()
res = res.split(":")[1].split("\n")[0]
res=res.strip()
start = datetime.now() # 用来计时
with open("ip.txt", 'w', encoding='utf-8') as f:
f.write(res+'\n')
f.write("\n")
f.write("last update time:" + str(start))
print(res)
# 创建ObsClient实例
obsClient = ObsClient(
access_key_id='WAFBGJACKDOQZDH1MKZ1', # 刚刚下载csv文件里面的Access Key Id
secret_access_key='dlWTUbqgCICaYJG3n0Rot4jXaen2HnfFtMVxiPEo', # 刚刚下载csv文件里面的Secret Access Key
server='https://obs.cn-north-1.myhuaweicloud.com' # 这里的访问域名就是我们在桶的基本信息那里记下的东西
)
# 使用访问OBS
# 调用putFile接口上传对象到桶内
resp = obsClient.putFile('dsideal', 'HuangHai/ip.txt', file_path='ip.txt')
# 关闭obsClient
obsClient.close()
print("https://dsideal.obs.cn-north-1.myhuaweicloud.com/HuangHai/ip.txt")