def on_data(self, tweet): # decode JSON data received from twitter data = json.loads(tweet) try: user = data['user']['screen_name'] tweet = data['text'] # make sure to use unicode strings for python 2 print(u"-" * self.linewidth) hilighted = u"{}: {}".format(colorize(user, "blue"), hilight(tweet, self.tag)) wrapped = u"\n".join(wrap(u"{}: {}".format(colorize(user, "blue"), hilight(tweet, self.tag)), width=self.linewidth)) print(wrapped) except: print(colorize('Something went wrong ...')) return True
def submitSession( session, jobs, opt, jNums=[] ): updated = [] hline = '-'*80 allJobs = len(jNums) == 0 print hline print '| Session',console.colorize("teal", session.name) print '| Creating scripts', for job in jobs: if not allJobs and job.jid not in jNums: continue # print '| ',job.name(),'...', job.cleanFiles() # makes destination directories job.mkDirs() # dump the script into the destination folder script = open(job.scriptPath,'w') script.write(job.script) script.close() # make it executable os.chmod(job.scriptPath, 0755) #dump the input files into the input folder inputFile = open(job.inputFile,'w') inputFile.write(job.fileList) inputFile.close() print job.name(), sys.stdout.flush() print '...done' print '| Submitting jobs ', for job in jobs: if not allJobs and job.jid not in jNums: continue if not opt.dry: if job.status is not PrawnTools.kCreated and not opt.resubmit: raise Exception('The job '+job.name()+' is already submitted. Use -r to resubmit.') qsubCmd = ['qsub',job.scriptPath,'-q',session.queue,'-o',job.stdOutPath,'-e',job.stdErrPath] # print ' '.join(qsubCmd) qsub = subprocess.Popen(qsubCmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) qsub.communicate() if qsub.returncode is not 0: print 'Warning: qsub returned',qsub.returncode job.status = PrawnTools.kSubmitted job.exitCode = None updated.append(job) print job.name(), sys.stdout.flush() print '...done' print hline return updated
def log(s, with_prefix=True, with_timestamp=True, color=None): out = s if with_prefix: out = _prefix_str + out if with_timestamp: now = datetime.datetime.now(dateutil.tz.tzlocal()) timestamp = now.strftime('%Y-%m-%d %H:%M:%S.%f %Z') out = "%s | %s" % (timestamp, out) if color is not None: out = colorize(out, color) if not _log_tabular_only: # Also log to stdout print(out) for fd in list(_text_fds.values()): fd.write(out + '\n') fd.flush() sys.stdout.flush()
def dprint(msg): """print colorfule debug message""" print console.colorize('red', 'debug: ' + str(msg))
missing=['-']*6 if opt.over else ['-']*2 if opt.stat: missing = ['-'] zeroes = OrderedDict() lowstat = OrderedDict() lsheader = ['int/nentr','nentr','int'] for arg in sorted(entries): zeroes[arg] = {} lowstat[arg] = {} histograms = entries[arg] for name,(n,i,uf,of,b1,bn) in histograms.iteritems(): if not n: zeroes[arg][name] = ['\x1b[41m'+console.colorize('white','0')] if opt.all or n > 0 and i/n > 1: lowstat[arg][name] = [ '%.2f' % x for x in [i/n if n!=0 else -1,n,i] ] PrintTable(zeroes, 'zeroes',missing,5) PrintTable(lowstat,'lowstat',['-']*3,9,lsheader) sys.exit(0) else: lsheader = ['entries','I'] if opt.over: lsheader += ['uf','b1','bn','of'] table = OrderedDict() for arg in sorted(entries): table[arg] = {} histograms = entries[arg] for name,(n,i,uf,b1,bn,of) in histograms.iteritems():
def on_error(self, status): print(colorize(status))
exit() # get consumer key and secret auth = tweepy.OAuthHandler(consumer_key, consumer_secret) # get access token and secret auth.set_access_token(access_token, access_token_secret) # get a topic from the trending topics if mode == "trending": api = tweepy.API(auth) trends = api.trends_place(1) topics= trends[0]['trends'] # let's be gentle and pick the very last topic from the list top_topic = topics[-1]['name'] elif mode == "emoji": top_topic = u"😃" print(u"Filtering for {}.".format(colorize(top_topic))) # create a receiver to print the tweets on the console receiver = StdOutListener(top_topic) # create and configure a twitter stream stream = tweepy.Stream(auth, receiver) stream.filter(track=[top_topic])
def submitSession(session, jobs, opt, jNums=[]): updated = [] hline = '-' * 80 allJobs = len(jNums) == 0 print hline print '| Session', console.colorize("teal", session.name) print '| Creating scripts', for job in jobs: if not allJobs and job.jid not in jNums: continue # print '| ',job.name(),'...', job.cleanFiles() # makes destination directories job.mkDirs() # dump the script into the destination folder script = open(job.scriptPath, 'w') script.write(job.script) script.close() # make it executable os.chmod(job.scriptPath, 0755) #dump the input files into the input folder inputFile = open(job.inputFile, 'w') inputFile.write(job.fileList) inputFile.close() print job.name(), sys.stdout.flush() print '...done' print '| Submitting jobs ', for job in jobs: if not allJobs and job.jid not in jNums: continue if not opt.dry: if job.status is not PrawnTools.kCreated and not opt.resubmit: raise Exception('The job ' + job.name() + ' is already submitted. Use -r to resubmit.') qsubCmd = [ 'qsub', job.scriptPath, '-q', session.queue, '-o', job.stdOutPath, '-e', job.stdErrPath ] # print ' '.join(qsubCmd) qsub = subprocess.Popen(qsubCmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) qsub.communicate() if qsub.returncode is not 0: print 'Warning: qsub returned', qsub.returncode job.status = PrawnTools.kSubmitted job.exitCode = None updated.append(job) print job.name(), sys.stdout.flush() print '...done' print hline return updated
def colState(state): return console.colorize(StateColors[state], StateLabel[state])