def cow_say(): tweets = [] req = urllib2.Request("http://smog.uppmax.uu.se:8080/swift/v1/tweets") response = urllib2.urlopen(req) tweetsObject = response.read().split() for t in tweetsObject: tweets.append(t) job = group(parseTweets.s([i]) for i in tweets) tweetTask = job.apply_async() print "Celery is working..." counter = 0 while tweetTask.ready() == False: # print "... %i s" %(counter) counter += 5 time.sleep(5) print "The task is done!" toReturn = tweetTask.get() c = Counter() for d in toReturn: c.update(d) display = dict(c) return jsonify(display), 200
def cow_say(): req = urllib2.Request("http://smog.uppmax.uu.se:8080/swift/v1/tweets") response = urllib2.urlopen(req) tweetsObject = response.read().split() job = group(parseTweets.s(i) for i in tweetsObject) tweetTask = job.apply_async() #tweetTask.save() print "Celery is working..." counter = 0 while (tweetTask.ready() == False): #print "... %i s" %(counter) counter += 5 time.sleep(5) print "The task is done!" toReturn = tweetTask.get() c = Counter() for d in toReturn: c.update(d) display = dict(c) return jsonify(display), 200
def cow_say(): tweets = [] req = urllib2.Request("http://smog.uppmax.uu.se:8080/swift/v1/tweets") response = urllib2.urlopen(req) tweetsObject = response.read().split() startTime = time.time() job = group(parseTweets.s(i) for i in tweetsObject) tweetTask = job.apply_async() print "Celery is working..." while (tweetTask.ready() == False): #print "... %i s" %(counter) counter = 0 time_elapsed = (time.time() - startTime) print "The task is done!" toReturn = tweetTask.get() c = Counter() for d in toReturn: c.update(d) display = dict(c) return jsonify(display, "Time elapsed: " + str(time_elapsed)), 200
for t in tweetsObject: tweets.append(t["name"]) aA = tweets[:4] aB = tweets[4:8] aC = tweets[8:12] aD = tweets[12:16] aE = tweets[16:] A = tweets[:1] B = tweets[1:2] C = tweets[2:3] D = tweets[3:4] E = tweets[4:5] job = group(parseTweets.s(A), parseTweets.s(B), parseTweets.s(C), parseTweets.s(D), parseTweets.s(E)) global tweetTask tweetTask = job.apply_async()