def updater(self): self.getControl(100).setLabel(self.data['torrentName']) import transmission while self.updaterFlag: data = transmission.get(self.data['transmissionUrl'], [self.data['hashString']])[0] if data['percentDone'] == 1: break eta = 'Unknown' if data['eta'] > 0: eta = time.strftime('%H:%M:%S', time.gmtime(data['eta'])) completed = util.color('Completed: ', 'blue') + str( int(float(data['percentDone']) * 100)) + '%' completed = completed + ' ' + util.color( 'Remaining Time: ', 'blue') + eta self.getControl(110).setLabel(completed) details = util.color('Size: ', 'blue') + str( round((float(data["totalSize"]) / (1024 * 1024 * 1024)), 2)) + 'Gb' details = details + ' ' + util.color('Seeds: ', 'blue') + str( data['peersSendingToUs']) details = details + ' ' + util.color('Rate: ', 'blue') + str( round( (float(data["rateDownload"]) / (1024 * 1024)), 2)) + 'Mbps' self.getControl(111).setLabel(details) time.sleep(self.updaterDelay) self.close()
def get_displayed_time(self, d, timezone="UTC"): color = "dim" if is_past(d) else "white" tz = timezones.TIMEZONES[timezone] d_with_tz = d.astimezone(pytz.timezone(tz)) return util.color(str(d_with_tz.hour).zfill(2) + ":" "" + str(d_with_tz.minute).zfill(2), color)
def start(self): while True: with color("blue"): print "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" print """ __ __ __ """ print """ / //_/___ _____ _________ _____ / /_____ """ print """ / ,< / __ `/ __ \/ ___/ __ `/ __ \/ //_/ _ \\""" print """ / /| / /_/ / / / / / / /_/ / /_/ / ,< / __/""" print """ /_/ |_\__,_/_/ /_/_/ \__,_/\____/_/|_|\___/ """ print """ """ print with color('yellow'): print "输入首字母搜索 (B)浏览歌曲 (V)原唱/伴唱 (N)下一首 (P)暂停/继续" print "\n\n\n\n" cmd = readline("Kanraoke > ") cmd = cmd.strip() if cmd: if cmd == "quit" or cmd == "q": break else: self._process_cmd(cmd)
def pretty_print_single_day(events, filter_method, title, color, timezone="UTC"): events = [e for e in events if filter_method(e.start, timezone)] if len(events): print(util.color(title + "\n" + ("-" * len(title)), color)) for e in events: e.print(timezone) if len(events): print("")
def format_timedelta(minutes, prefix, suffix, highlight_color): color = "white" prefix = "(" + prefix + " " suffix = suffix + ")" if minutes > 24 * 60: color = "dim" infix = "> 1 day" elif minutes > 60: hours = int(minutes / 60) remaining_minutes = minutes - hours * 60 infix = str(hours) + " h " + str(remaining_minutes) + " mn" elif minutes < 60: infix = str(minutes) + " mn" if minutes < 30: color = highlight_color else: infix = str(minutes) + " mn" return util.color(prefix + infix + suffix, color)
def listPlaylists(content): xbmcplugin.setContent(_handleId, 'movies') for data in content: name = data["name"] + ' [' + str(data["count"]) + ']' if data['privacy'] == 'Private': name = util.color(name, 'orange') item = xbmcgui.ListItem(name) item.setArt({ 'thumb': data["thumb"], 'poster': data["thumb"], 'fanart': data["thumb"] }) item.setProperty("IsPlayable", "false") params = {'handler': 'PlaylistVideos', 'id': data["id"]} xbmcplugin.addDirectoryItem(handle=_handleId, url=_baseUrl + '?' + urllib.urlencode(params), isFolder=True, listitem=item)
def _select(self, selection, t, param): if t == "song": song = selection if song and util.add_to_playlist(self.player, song): with color('yellow'): sys.stdout.write("\nSong added: ") Library.display_song(song) print sleep(.5) else: print "Song not found!" elif t == "artist": artist = selection if artist: aid = artist["id"] songs = self.lib.get_song_by_artist(aid) return self.display_list(songs, "song") elif t == "menu": if selection: return selection[1](param)
def __init__(self, **kwargs): """ connect to MySQL and setup the BYOB database kwargs: host hostname/IP address of MySQL host machine user authorized account username password authorized account password """ super(Database, self).__init__(**kwargs) self.config(**kwargs) self.logger = util.logger() self.tasks = {} self._debug = debug self._query = self.cursor(dictionary=True) self._queue = Queue.Queue() self._color = util.color() self._setup(setup)
def listAlbums(albums): for data in albums: name = data["name"] + ' [' + str(data['photosCount']) + ']' if data['owner'] == 'Stas Blagodatny': ## Change to dynamic if data['sharedKey'] is not None: name = util.color(name, 'orange') else: name = name + ' (' + data['owner'] + ')' item = xbmcgui.ListItem(name) item.setArt({ 'thumb': data["thumb"], 'poster': data["thumb"], 'fanart': data["thumb"] }) params = { 'handler': 'ListAlbum', 'id': data["id"], 'sharedKey': data['sharedKey'] } xbmcplugin.addDirectoryItem(handle=_handleId, url=_baseUrl + '?' + urllib.urlencode(params), isFolder=True, listitem=item)
def display_list(self, l, operation_type, param=None): if l: size = len(l) max_page = int(math.ceil(size / 10.0)) page = 0 to_main = False while not to_main: if operation_type == "menu": print "====================" else: print "\n" * 50 + "========= PAGE: %d/%d ===========" % ( page + 1, max_page) for i in range(10): if page * 10 + i >= size: break item = l[page * 10 + i] prefix = i + 1 if i < 9 else 0 if operation_type == "song": Library.display_song(item, prefix) elif operation_type == "artist": Library.display_artist(item, prefix) elif operation_type == "menu": Menu.display_menu(item, prefix) print "====================" print "(Nums)选择 (N)下一页 (P)上一页 (B)后退 (M)主菜单\n" valid_selection = False sys.stdout.write("please select > ") while not valid_selection: select = getch() if select == "b": return if select == "m": return True elif select == "n": new_page = min(page + 1, max_page - 1) if page != new_page: page = new_page valid_selection = True continue elif select == "p": new_page = max(page - 1, 0) if page != new_page: page = new_page valid_selection = True continue elif select.isdigit(): choice_str = select select = int(select) select = select - 1 if select > 0 else 9 idx = page * 10 + select if idx < size: res = l[idx] print choice_str to_main = self._select(res, operation_type, param) valid_selection = True else: continue else: pass return True else: with color("pink"): print "\n" print "\tMMMMMMMMMMMMMMMMMMMMMWNK0kxdooooooodxk0XNWMMMMMMMMMMMMMMMMMM" print "\tMMMMMMMMMMMMMMMWWNKkoc;'...............,:lx0NWMMMMMMMMMMMMMM" print "\tMMMMMMMMMMMMWNX0d:'.........................;lkXWMMMMMMMMMMM" print "\tMMMMMMMMMMWNKkl,........,:clodddddooc:,'.......;d0WMMMMMMMMM" print "\tMMMMMMMMWXKkc'......;ldOKXXXXXXXXXXXXXKOxl;......'l0WMMMMMMM" print "\tMMMMMMWXKOo'.....'lkKXXXXXXXXXXXXXXXXXXXXXKko;.....,dXMMMMMM" print "\tMMMMWNX0k:.....,oOXXXXXXXXXXXXXXXXK0KXXXXXXXX0d;.....:0WMMMM" print "\tMMMWNK0x;.....cOXXXXXXK00XXXXXXXKx:':xKXXXXXXXX0o,....,kWMMM" print "\tMMMNKKk;....'oKXXXXXXKo,,lOXXXNX0l....:xKXXXXXXXXk:....'xWMM" print "\tMMNKKO:....'dKXXXXXXKo...,xXXXXXXKx;....:kKXXXXXXXOc....,OWM" print "\tMWKK0o.....oKXXXXXX0l...'dKXXXXXXXX0l'....ckKXXXXXXO:....:KM" print "\tWXKKk;....:0XXXXXX0c....lKXXXXXXXXXXKk:....'oKXXXXXXk,....dN" print "\tWXKKd'....dXXXXXXO:....c0XXXXXXXXXXXXX0o,..'xXXXXXXXKl....:K" print "\tNKK0l....,kXXXXXXOc...;OXXXXXXXXXXXXXXXXOc;dKXXXXXXXXx'...'k" print "\tNKK0l....;OXXXXXXX0d,,xXXXXXXXXXXXXXXXXXXK0XXXXXXXXXXk;....d" print "\tNKK0l....;OXXXXXXXXXOOXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXO;....o" print "\tNKK0o....'xXXXXXXXXXXXXXXXXXKKK00OOkkxddollclkXXXXXXXk,....d" print "\tWKKKx,....lKXXXXXXXOdoollc::;,,,''..........'xXXXXXXXd....'k" print "\tWXKKOc....;kXXXXXXXx'.......................;OXXXXXX0:....:K" print "\tMNKK0x,....c0XXXXXXKl.....';::ccllloddc.....lKXXXXXKd.....xW" print "\tMWXKK0l.....l0XXXXXXk,....l0XXXXXXXXXXx'....dXXXXXXx,....cXM" print "\tMMWXKKOc.....cOXXXXXKo....;OXXXXXXXXXXx'...,kXXXXKd,....;0WM" print "\tMMMWXKKOl.....;xKXXXXO:....dXXXXXXXXXXd....:0XXX0l'....;OWMM" print "\tMMMMWXKK0o'.....ckKXXXd'...:0XXXXXXXXXd....lKX0d;.....:0WMMM" print "\tMMMMMWNKK0x:......:d0X0c...'dXXXXXXXXXo...'dOo;.....'oXMMMMM" print "\tMMMMMMMWNKKOd;......,cdl'...c0XXXXXXXXo....,'......c0WMMMMMM" print "\tMMMMMMMMMWXKKOd:............'lxxkkxxdl;.........'lONMMMMMMMM" print "\tMMMMMMMMMMMWNXK0xl;..........................':dKWMMMMMMMMMM" print "\tMMMMMMMMMMMMMMWNXX0koc;'.................':lxKNMMMMMMMMMMMMM" print "\tMMMMMMMMMMMMMMMMMWWNNXKOkdolc:::::cclodkOXNWMMMMMMMMMMMMMMMM" print "\tMMMMMMMMMMMMMMMMMMMMMMMWWWWWNNNNNNWWMMMMMMMMMMMMMMMMMMMMMMMM" print "\n" getch( "It seems your query does not match any record in our library, press ENTER to continue... " ) return
def discard2str(player_idx, card_idx, card): string = 'Player {} discards card [{}], a {} {}'.format(player_idx, card_idx, util.color(card), util.number(card)) return string
parser.add_argument('user') parser.add_argument('password') args = parser.parse_args() api = coinroll.Coinroll(args.user, args.password) bets = float('inf') offset = 0 profit = 0 print('number | amount | lucky < less | diff | profit') try: while offset < bets: offset += 5 if offset > bets: offset = bets r = api.bets(offset) bets = r.count for bet in reversed(r.bets): diff = bet.diff profit += diff print('{:6d} | {:.8f} | {} < {:5d} | {} | {}'.format(bet.num, bet.amount, color(diff, bet.lucky, '5d'), bet.lessthan, color(diff), color(profit))) except KeyboardInterrupt: pass
import coinroll from util import color from decimal import Decimal from collections import defaultdict profits = defaultdict(Decimal) seen = set() print('user | bet | amount | lucky < less | ' 'diff | profit') try: while True: for bet in coinroll.livebets().data: if bet.id not in seen: seen.add(bet.id) profits[bet.user] += bet.diff print('{} | {} | {:.8f} | {} < {:5d} | {} | {}'.format( bet.user, bet.id, bet.amount, color(bet.diff, bet.lucky, '5d'), bet.lessthan, color(bet.diff), color(profits[bet.user]))) except KeyboardInterrupt: pass
def card2string(card): return '{0: >6} {1}'.format(util.color(card), util.number(card))
def card_dealt2str(player_idx, card): string = 'A {} {} is dealt to Player {}'.format(util.color(card), util.number(card), player_idx) return string
def invalid_play2str(card): string = 'A {} {} is not playable, fuse reduced'.format(util.color(card), util.number(card)) return string
parser.add_argument('password') args = parser.parse_args() api = coinroll.Coinroll(args.user, args.password) bets = float('inf') offset = 0 profit = 0 print('number | amount | lucky < less | diff | profit') try: while offset < bets: offset += 5 if offset > bets: offset = bets r = api.bets(offset) bets = r.count for bet in reversed(r.bets): diff = bet.diff profit += diff print('{:6d} | {:.8f} | {} < {:5d} | {} | {}'.format( bet.num, bet.amount, color(diff, bet.lucky, '5d'), bet.lessthan, color(diff), color(profit))) except KeyboardInterrupt: pass
def select(self, item): item.setLabel(util.color(util.bold(item.getLabel()), 'orange'))
def get_displayed_text(self): color = "white" if is_past(self.start) and is_past(self.end): color = "dim" return util.color(self.text, color)
this = r.balance index = 0 print('balance | amount | lucky < less | diff | profit') try: while True: amount = seq[index] * base if r.balance < amount or r.balance >= args.target or args.max < amount: break r = bot.bet(lessthan, amount) print('{:.8f} | {:.8f} | {} < {:5d} | {} | {} | {}'.format(r.balance, r.amount, color(r.diff, r.lucky, '5d'), r.lessthan, color(r.diff), color(r.profit), color(r.balance - this))) if r.win: index -= 2 if index < 0: index = 0 else: index += 1 if len(seq) <= index: seq.append(seq[-2] + seq[-1]) except KeyboardInterrupt:
def display_list(self, l, operation_type, param=None): if l: size = len(l) max_page = int(math.ceil(size / 10.0)) page = 0 to_main = False while not to_main: if operation_type == "menu": print "====================" else: print "\n"*50+"========= PAGE: %d/%d ===========" % (page+1, max_page) for i in range(10): if page * 10 + i >= size: break item = l[page * 10 + i] prefix = i + 1 if i < 9 else 0 if operation_type == "song": Library.display_song(item, prefix) elif operation_type == "artist": Library.display_artist(item, prefix) elif operation_type == "menu": Menu.display_menu(item, prefix) print "====================" print "(Nums)选择 (N)下一页 (P)上一页 (B)后退 (M)主菜单\n" valid_selection = False sys.stdout.write("please select > ") while not valid_selection: select = getch() if select == "b": return if select == "m": return True elif select == "n": new_page = min(page + 1, max_page - 1) if page != new_page: page = new_page valid_selection = True continue elif select == "p": new_page = max(page - 1, 0) if page != new_page: page = new_page valid_selection = True continue elif select.isdigit(): choice_str = select select = int(select) select = select - 1 if select > 0 else 9 idx = page * 10 + select if idx < size: res = l[idx] print choice_str to_main = self._select(res, operation_type, param) valid_selection = True else: continue else: pass return True else: with color("pink"): print "\n" print "\tMMMMMMMMMMMMMMMMMMMMMWNK0kxdooooooodxk0XNWMMMMMMMMMMMMMMMMMM" print "\tMMMMMMMMMMMMMMMWWNKkoc;'...............,:lx0NWMMMMMMMMMMMMMM" print "\tMMMMMMMMMMMMWNX0d:'.........................;lkXWMMMMMMMMMMM" print "\tMMMMMMMMMMWNKkl,........,:clodddddooc:,'.......;d0WMMMMMMMMM" print "\tMMMMMMMMWXKkc'......;ldOKXXXXXXXXXXXXXKOxl;......'l0WMMMMMMM" print "\tMMMMMMWXKOo'.....'lkKXXXXXXXXXXXXXXXXXXXXXKko;.....,dXMMMMMM" print "\tMMMMWNX0k:.....,oOXXXXXXXXXXXXXXXXK0KXXXXXXXX0d;.....:0WMMMM" print "\tMMMWNK0x;.....cOXXXXXXK00XXXXXXXKx:':xKXXXXXXXX0o,....,kWMMM" print "\tMMMNKKk;....'oKXXXXXXKo,,lOXXXNX0l....:xKXXXXXXXXk:....'xWMM" print "\tMMNKKO:....'dKXXXXXXKo...,xXXXXXXKx;....:kKXXXXXXXOc....,OWM" print "\tMWKK0o.....oKXXXXXX0l...'dKXXXXXXXX0l'....ckKXXXXXXO:....:KM" print "\tWXKKk;....:0XXXXXX0c....lKXXXXXXXXXXKk:....'oKXXXXXXk,....dN" print "\tWXKKd'....dXXXXXXO:....c0XXXXXXXXXXXXX0o,..'xXXXXXXXKl....:K" print "\tNKK0l....,kXXXXXXOc...;OXXXXXXXXXXXXXXXXOc;dKXXXXXXXXx'...'k" print "\tNKK0l....;OXXXXXXX0d,,xXXXXXXXXXXXXXXXXXXK0XXXXXXXXXXk;....d" print "\tNKK0l....;OXXXXXXXXXOOXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXO;....o" print "\tNKK0o....'xXXXXXXXXXXXXXXXXXKKK00OOkkxddollclkXXXXXXXk,....d" print "\tWKKKx,....lKXXXXXXXOdoollc::;,,,''..........'xXXXXXXXd....'k" print "\tWXKKOc....;kXXXXXXXx'.......................;OXXXXXX0:....:K" print "\tMNKK0x,....c0XXXXXXKl.....';::ccllloddc.....lKXXXXXKd.....xW" print "\tMWXKK0l.....l0XXXXXXk,....l0XXXXXXXXXXx'....dXXXXXXx,....cXM" print "\tMMWXKKOc.....cOXXXXXKo....;OXXXXXXXXXXx'...,kXXXXKd,....;0WM" print "\tMMMWXKKOl.....;xKXXXXO:....dXXXXXXXXXXd....:0XXX0l'....;OWMM" print "\tMMMMWXKK0o'.....ckKXXXd'...:0XXXXXXXXXd....lKX0d;.....:0WMMM" print "\tMMMMMWNKK0x:......:d0X0c...'dXXXXXXXXXo...'dOo;.....'oXMMMMM" print "\tMMMMMMMWNKKOd;......,cdl'...c0XXXXXXXXo....,'......c0WMMMMMM" print "\tMMMMMMMMMWXKKOd:............'lxxkkxxdl;.........'lONMMMMMMMM" print "\tMMMMMMMMMMMWNXK0xl;..........................':dKWMMMMMMMMMM" print "\tMMMMMMMMMMMMMMWNXX0koc;'.................':lxKNMMMMMMMMMMMMM" print "\tMMMMMMMMMMMMMMMMMWWNNXKOkdolc:::::cclodkOXNWMMMMMMMMMMMMMMMM" print "\tMMMMMMMMMMMMMMMMMMMMMMMWWWWWNNNNNNWWMMMMMMMMMMMMMMMMMMMMMMMM" print "\n" getch("It seems your query does not match any record in our library, press ENTER to continue... ") return
def unprocessed(self, *msg): if self.show_unprocessed: self.show( color('37', ' ' * 6 + ' | ' + ' '.join(map(lambda m: str(m), msg))))
print('balance | amount | lucky < less | diff | profit') try: while len(seq) > 0: size = seq[0] if len(seq) > 1: size += seq[-1] amount = size * base if r.balance <= amount or args.max < amount: break r = bot.bet(lessthan, amount) print('{:.8f} | {:.8f} | {} < {:5d} | {} | {}'.format(r.balance, r.amount, color(r.diff, r.lucky, '5d'), r.lessthan, color(r.diff), color(r.profit))) if r.win: seq.pop(0) if len(seq) > 0: seq.pop() else: seq.append(size) except KeyboardInterrupt: pass
bot = coinroll.Coinroll(args.user, args.password) r = bot.stats() game = coinroll.gameinfo(args.lessthan) start = args.start or game.minbet amount = start loses = 0 print('balance | amount | lucky < less | diff | profit') try: while amount <= r.balance < args.target and amount <= args.max: r = bot.bet(args.lessthan, amount) print('{:.8f} | {:.8f} | {} < {:5d} | {} | {} | {}'.format( r.balance, r.amount, color(r.diff, r.lucky, '5d'), r.lessthan, color(r.diff), color(r.profit))) if r.win: amount = start loses = 0 else: loses += 1 if loses % args.interval == 0: amount *= args.multiplier if args.add: amount += start
def log(self, *msg): if self.verbose: self.out.write( color('37', 'wl log: ') + ' '.join(map(lambda m: str(m), msg)))
def warn(self, *msg): self.err.write( color('1;33', 'Warning: ') + ' '.join(map(lambda m: str(m), msg)))
def error(self, *msg): self.err.write( color('1;31', 'Error: ') + ' '.join(map(lambda m: str(m), msg)))
import coinroll from util import color from decimal import Decimal from collections import defaultdict profits = defaultdict(Decimal) seen = set() print('user | bet | amount | lucky < less | ' 'diff | profit') try: while True: for bet in coinroll.livebets().data: if bet.id not in seen: seen.add(bet.id) profits[bet.user] += bet.diff print('{} | {} | {:.8f} | {} < {:5d} | {} | {}'.format(bet.user, bet.id, bet.amount, color(bet.diff, bet.lucky, '5d'), bet.lessthan, color(bet.diff), color(profits[bet.user]))) except KeyboardInterrupt: pass
#!/usr/bin/env python3 import dotfiles import util import shutil import os from pathlib import Path util.initialize(Path(__file__).parent) modules = dotfiles.Module.__subclasses__() for i, module in enumerate(modules): progress = "({} out of {})".format(i + 1, len(modules)) module_name = util.color(module.__name__, util.Color.green) module_source = util.color(module.__module__, util.Color.yellow) print("Installing module", module_name, "from", module_source, progress) instance = module() for message in instance.install(): print(util.timestamp(message)) print("Copying over files from module", module_name) default_path = Path(os.path.expanduser(module.default_dest)) module_path = Path(module.__module__) valid_file_paths = [path for path in module_path.glob("*") if util.validate_path(path)] for path in valid_file_paths: