Skip to content

Instantly share code, notes, and snippets.

@dpawluk
Created January 15, 2014 22:07
Show Gist options
  • Save dpawluk/8445689 to your computer and use it in GitHub Desktop.
Save dpawluk/8445689 to your computer and use it in GitHub Desktop.
import thread
import threading
import requests
s = requests.Session()
s.headers.update({'Content-Type': 'application/json'})
s.auth = ('{username/token}','{password/token}')
#r = s.post("http://requestb.in/1hjs6jw1", data=payload)
ticketCount = 2000
threads = []
finished = 0
def postTicket(threadName, newData):
try:
r = s.post("https://{subdomain}.zendesk.com/api/v2/imports/tickets.json", data=newData)
print "finished with request number: " + `threadName`
global finished
finished += 1
except requests.exceptions.ConnectionError as e:
print "There was a connection error in thread "+ `threadName` + ": %s" % (e)
except requests.exceptions.Timeout as e:
print "There was a timeout in thread " + `threadName` + "!!!"
except Exception as e:
print e
for x in range (0,ticketCount):
try:
payload = '{"ticket":{"requester":{"name":"Joe Thread", "email":"threadsonfire@threadded.com"}, "subject":"Thread ' + `x` + ' is on fire", "comment": { "body": "I want thousands of tickets" }}}'
threads.append(thread.start_new_thread( postTicket, (x, payload, )))
except Exception as e:
print "Error: unable to start thread " + `x` + "\n" + `e`
while finished != ticketCount:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment