def idletimes(self, irc, msg, args, source): """[[<network>/]<channel>] Shows idle time averages. """ source = wvm.nctuple(source, irc.network, msg.args[0]) data = self._getstats(source) if not data: irc.error('Currently no data for this channel.') return stats = "{0}: {1} \\ {2}: {3} \\ {4}: {5} \\ {6}: {7}".format( ircutils.bold('Current'), wvm.secstostamp(data[0]), ircutils.bold('Short-term'), wvm.secstostamp(data[1]), ircutils.bold('Long-term'), wvm.secstostamp(data[2]), ircutils.bold('Samples'), data[3], ) irc.reply(stats)
def youtube(self, irc, msg, args, opts, string): """[--u=<user>] [--d] <query|index> Searches YouTube for <query>, optionally from <user>, if set, and returns results. Automatically points to the direct (embed) URL if it is availible. """ try: gdata except NameError: irc.error("'python-gdata' is not installed.") return if not string.isdigit(): client = gdata.youtube.service.YouTubeService() query = gdata.youtube.service.YouTubeVideoQuery() query.vq = str(string) query.max_results = 15 query.start_index = 1 query.racy = 'include' query.format = '5' query.orderby = 'relevance' description = False for o, a in opts: if o == 'u': query.author = a elif o == 'd': description = True feed = client.YouTubeQuery(query) self.ytresults = [] self.ytindex = 0 for entry in feed.entry: title = ircutils.bold(entry.title.text) duration = wvm.secstostamp(entry.media.duration.seconds) views = entry.statistics.view_count if entry.statistics else 0 rating = entry.rating.average if entry.rating else 0 rating = float(rating) / 5.0 * 100 votes = entry.rating.num_raters if entry.rating else 0 #date = entry.published.text.split('T') author = entry.author[0].name.text result = '%s - %s (%s) - %s views, %s votes, %.1f%% ' \ 'approval rating - %s' result = result % ( author, title, duration, views, votes, float(rating), entry.link[0].href ) if description: description = str(entry.media.description.text) result = '%s - %s' % (result, description) self.ytresults.append(result) if len(self.ytresults) == 0: irc.error("No results.") return else: self.ytindex = min(len(self.ytresults) - 1, int(string)) if self.ytindex == -1: irc.error("No results.") return irc.reply('[%d/%d] %s' % (self.ytindex, len(self.ytresults) - 1, self.ytresults[self.ytindex]))
def timestamp(self, irc, msg, args, seconds): """<elapsedsecs> Converts <elapsedsecs> to a timestamp. """ irc.reply(wvm.secstostamp(seconds))