-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoster.py
44 lines (37 loc) · 1.02 KB
/
Poster.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
import requests
from Settings import url
from Settings import uniqueKey
from Settings import urlHeads
from jsonCreator import createJson
from multiprocessing.dummy import Pool as ThreadPool
import time
def post(data):
resultList = []
result = {}
pool = ThreadPool(5)
count = 0;
data = [x for x in data]
for x in data:
jsonVal = createJson(dict(x))
if uniqueKey:
result.update(jsonVal)
if count == 5000 or count == len(data) - 1:
resultList.append(result)
count = 0;
result = {}
else:
resultList.append(jsonVal)
count +=1
pool.map(postToUrl, resultList)
def postToUrl(data):
sent = False
tries = 0
while not sent:
try:
tries += 1
r = requests.post(url,headers=urlHeads, json=data)
sent = r.status_code in [200,202]
except Exception as e:
print("Failue due to :%s"%e)
time.sleep(1)
sent = tries > 3