added proxy settings for upload script
This commit is contained in:
parent
7d474af899
commit
26b7d47996
@ -1,11 +1,30 @@
|
||||
|
||||
import sys, subprocess, getpass, pycurl, urllib.parse
|
||||
import sys, os, subprocess, getpass, pycurl, urllib.parse
|
||||
if __name__ == "__main__":
|
||||
def get_proxy():
|
||||
proxy = ""
|
||||
if "http_proxy" in os.environ:
|
||||
proxy = os.environ["http_proxy"]
|
||||
elif "https_proxy" in os.environ:
|
||||
proxy = os.environ["https_proxy"]
|
||||
host = proxy[proxy.rfind('/') + 1: proxy.rfind(':')]
|
||||
port = proxy[proxy.rfind(':') + 1:]
|
||||
foo = proxy.find("socks://") >= 0 or proxy.find("socks5h://")
|
||||
return host, int(port), foo
|
||||
|
||||
def api_upload(endpoint, dest_fmt = "/microblog/%s"):
|
||||
pages = []
|
||||
with open("updatedfiles.txt") as f:
|
||||
pages = f.readlines()
|
||||
c = pycurl.Curl()
|
||||
|
||||
if "http_proxy" in os.environ or "https_proxy" in os.environ:
|
||||
hostname, port_no, is_socks = get_proxy()
|
||||
c.setopt(pycurl.PROXY, hostname)
|
||||
c.setopt(pycurl.PROXYPORT, port_no)
|
||||
if is_socks:
|
||||
c.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5_HOSTNAME)
|
||||
|
||||
c.setopt(c.URL, endpoint)
|
||||
c.setopt(c.POST, 1)
|
||||
for page in pages:
|
||||
|
Loading…
x
Reference in New Issue
Block a user