这是我的V.Python 3.5.0脚本 导入请求 导入子流程 导入json 导入系统 导入线程 进口时间 从队列导入队列 import urllib3 import urllib3.contrib.pyopenssl
urllib3.contrib.pyopenssl.inject_into_urllib3()
#urllib3.disable_warnings() unverified HTTPS requests
numberOfViewers = int(sys.argv[1])
builderThreads = int(sys.argv[2])
startTime = time.time()
numberOfSockets = 0
concurrent = 25
urls = []
urlsUsed = []
proxies = {
'http': 'http://173.201.183.172:8000',
'http': 'http://94.181.34.64:81',
}
def getURL(): # Get tokens
output = subprocess.Popen(["livestreamer", "twitch.tv/swagvyper", "-j"], stdout=subprocess.PIPE).communicate()[0]
return json.loads(output)['streams']['worst']['url'] # Parse json and return the URL parameter
def build(): # Builds a set of tokens, aka viewers
global numberOfSockets
global numberOfViewers
while True:
if numberOfSockets < numberOfViewers:
numberOfSockets += 1
print "Building viewers " + str(numberOfSockets) + "/" + str(numberOfViewers)
urls.append(getURL())
def view(): # Opens connections to send views
global numberOfSockets
while True:
url=q.get()
# requests.head(url, proxies=proxies)
requests.head(url) # Sending a HEAD request is enough to count as a view
if (url in urlsUsed):
urls.remove(url)
urlsUsed.remove(url)
numberOfSockets -= 1
else:
urlsUsed.append(url)
q.task_done()
if __name__ == '__main__':
for i in range(0, builderThreads):
threading.Thread(target = build).start()
while True:
while (numberOfViewers != numberOfSockets): # Wait until sockets are built
time.sleep(1)
q=Queue(concurrent*2)
for i in range(concurrent):
try:
t=threading.Thread(target=view)
t.daemon=True
t.start()
except:
print 'thread error'
try:
for url in urls:
print url
q.put(url.strip())
q.join()
except KeyboardInterrupt:
sys.exit(1)
这是向我提供请求帮助的错误!
"pythonviwer.py", line 36
print "Building viewers " + str(numberOfSockets) + "/" + str(numberOfViewers)
^
SyntaxError: invalid syntax