Skip to content

Instantly share code, notes, and snippets.

@dellis23
Created February 16, 2015 00:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dellis23/5309143cb2e3bf17f8af to your computer and use it in GitHub Desktop.
Save dellis23/5309143cb2e3bf17f8af to your computer and use it in GitHub Desktop.
Split up lots of gmail actions into multiple worker threads.
from Queue import Queue
import sys
from threading import Thread
import requests
headers = {
'x-same-domain': '1',
'origin': 'https://mail.google.com',
'accept-encoding': 'gzip, deflate',
'accept-language': 'en-US,en;q=0.8,it;q=0.6',
'user-agent': 'Mozilla/5.0 [...]',
'content-type': 'application/x-www-form-urlencoded;charset=UTF-8',
'accept': '*/*',
'referer': '[...]',
'authority': 'mail.google.com',
'cookie': '[...]',
'content-length': '0',
}
url = 'https://mail.google.com/mail/u/0/?[...]&act=cc_{}&[...]'
def make_label(q):
while True:
num = q.get()
print "I'm doing " + str(num)
requests.post(url.format('testing' + str(num)), headers=headers)
q.task_done()
if __name__ == "__main__":
queue = Queue(maxsize=0)
# Set up workers
for i in xrange(20):
worker = Thread(target=make_label, args=(queue,))
worker.setDaemon(True)
worker.start()
# Set up queue
for i in xrange(1000, 5000):
queue.put(i)
queue.join()
sys.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment