Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import threading
- import requests
- import json
- from dateutil import parser
- from time import sleep
- import time
- a = 0
- def worker(thread_name):
- global a
- global treatedApplications
- global treatedApplicationsIntermediaire
- global startTime
- global flagTimer
- while 1:
- #r = requests.get('https://api.staffomaticapp.com/v3/kerast/locations/26462/shifts.json', auth=('jb2.collet@gmail.com', 'jbbb1565'))
- r = requests.get('https://api.staffomaticapp.com/v3/kerast/locations/26462/shifts.json?from=2017-06-26T00%3A00%3A00%2B02%3A00&until=2017-08-01T00%3A00%3A00%2B02%3A00', auth=('solarderet@hotmail.fr', 'Lupercal01'))
- rJsonResponse = json.loads(r.text)
- if flagTimer == 1:
- startTime = int(round(time.time() * 1000))
- flagTimer = 0
- toTreat = -1
- for x in range(0, len(rJsonResponse)):
- for y in range(0, len(applications)):
- dtStart = applications[y]["shift"]["startsAt"]
- dtStart2 = rJsonResponse[x]["starts_at"]
- dtEnd = applications[y]["shift"]["endsAt"]
- dtEnd2 = rJsonResponse[x]["ends_at"]
- if dtStart == dtStart2 and dtEnd == dtEnd2 and rJsonResponse[x]["department_id"] == applications[y]["shift"]["department"]["staffomaticId"] and rJsonResponse[x]["location_id"] == applications[y]["shift"]["department"]["location"]["staffomaticId"]:
- if not applications[y]["id"] in treatedApplicationsIntermediaire:
- treatedApplicationsIntermediaire.append(applications[y]["id"])
- toTreat = rJsonResponse[x]["id"]
- user_id = 322176
- email = 'jb2.collet@gmail.com'
- password = "jbbb1565"
- r2 = requests.post('https://api.staffomaticapp.com/v3/kerast/shifts/'+str(toTreat)+'/applications.json', auth=(email, password), json={"user_id": user_id,"do": "assign"})
- r2Jsonresponse = json.loads(r2.text)
- if 'shift_id' not in r2Jsonresponse:
- if '{"errors":{"user_id":["already exists"]}}' == r2.text :
- treatedApplications.append(applications[y]["id"])
- print "|treated - " + thread_name + " - " + str(int(round(time.time() * 1000)) - startTime) + " - " + str(r2.status_code) + "- " + str(toTreat) + "\n"
- else:
- treatedApplicationsIntermediaire.remove(applications[y]["id"])
- else :
- treatedApplications.append(applications[y]["id"])
- print "|treated - " + thread_name + " - " + str(int(round(time.time() * 1000)) - startTime) + " - " + str(r2.status_code) + "- " + str(toTreat) + "\n"
- #print r2.text
- for x in range(0, len(rJsonResponse)):
- for y in range(0, len(applications)):
- dtStart = applications[y]["shift"]["startsAt"]
- dtStart2 = rJsonResponse[x]["starts_at"]
- dtEnd = applications[y]["shift"]["endsAt"]
- dtEnd2 = rJsonResponse[x]["ends_at"]
- if dtStart == dtStart2 and dtEnd == dtEnd2 and rJsonResponse[x]["department_id"] == applications[y]["shift"]["department"]["staffomaticId"] and rJsonResponse[x]["location_id"] == applications[y]["shift"]["department"]["location"]["staffomaticId"]:
- if not applications[y]["id"] in treatedApplications:
- treatedApplications.append(applications[y]["id"])
- toTreat = rJsonResponse[x]["id"]
- user_id = 322176
- email = 'jb2.collet@gmail.com'
- password = "jbbb1565"
- r2 = requests.post('https://api.staffomaticapp.com/v3/kerast/shifts/'+str(toTreat)+'/applications.json', auth=(email, password), json={"user_id": user_id,"do": "assign"})
- r2Jsonresponse = json.loads(r2.text)
- if 'shift_id' in r2Jsonresponse or '{"errors":{"user_id":["already exists"]}}' == r2.text:
- treatedApplications.append(applications[y]["id"])
- print "|treated FAILSAFE - " + thread_name + " - " + str(int(round(time.time() * 1000)) - startTime) + " - " + str(r2.status_code) + "- " + str(toTreat) + "\n"
- a += 1
- print " " + str(a) + "/" + str(r.status_code) + "/" + "\n"
- allShifts = requests.get('https://api.staffomaticapp.com/v3/kerast/locations/26462/shifts.json?from=2017-06-19T00%3A00%3A00%2B02%3A00&until=2017-06-16T00%3A00%3A00%2B02%3A00', auth=('jb2.collet@gmail.com', 'jbbb1565'))
- allShiftsJsonResponse = json.loads(allShifts.text)
- initialShiftsCounter = len(allShiftsJsonResponse)
- with open('inputApplications.json') as data_file:
- applications = json.load(data_file)
- threads = []
- treatedApplications = []
- treatedApplicationsIntermediaire= []
- flagTimer = 1
- startTime = int(round(time.time() * 1000))
- for x in range(0,10):
- sleep( 0.05 )
- t = threading.Thread(target=worker, args=(str(x)+"-thread",))
- threads.append(t)
- t.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement