-
Notifications
You must be signed in to change notification settings - Fork 0
/
onebridge_gevent.py
72 lines (63 loc) · 2.17 KB
/
onebridge_gevent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# encoding:utf-8
'''
Created on 2016��7��25��
@author: ssiej
'''
from pymongo import MongoClient
import multiprocessing
import gevent
from gevent import monkey
monkey.patch_all()
import requests,json, time
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
def getInfo(userid):
headers = {'Host': 'atlascopco.1bridge.com',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
'Accept-Encoding': 'gzip, deflate, br',
'DNT': 1,
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'X-Requested-With': 'XMLHttpRequest',
'Referer': 'https://atlascopco.1bridge.com/'
}
url = "https://atlascopco.1bridge.com/guestConference.sf"
try:
r = requests.post(url,data=json.dumps({"id":userid,"passcode":""}), headers=headers,verify=False)
userinfo = r.json()
# print userinfo
if userinfo.get('name'):
insertData(userinfo)
print "%s --- %s" %(userinfo.get('conferenceId'), userinfo.get('name'))
except Exception:
pass
def insertData(data):
client = MongoClient()
db = client['atlas']
coll = db['onebridge']
coll.insert_one(data)
client.close()
def createThread(nums):
strnums = [str(x) for x in nums]
threads = [gevent.spawn(getInfo, i) for i in strnums]
print "start! -- %d" % len(threads)
gevent.joinall(threads)
# once one coroutine is done, all others will be killed
print "It's done! "
if __name__ == '__main__':
start = time.time()
fnum = 86700001
lnum = 86700301
n = 4
part = (lnum - fnum)/n
numlist = map(lambda x:xrange(x*part+fnum, x!=n-1 and (x+1)*part+fnum or lnum+1),range(n))
t = []
for nums in numlist:
p = multiprocessing.Process(target=createThread, args=(nums,))
p.start()
t.append(p)
for each in t:
each.join()
end = time.time()
print "It's done! -- %f s" % (end - start)