async def on_ready(): logging.debug("--------") logging.debug("Starting up...") logging.debug(str( "Logged in as {0.user}, with ID {0.user.id}".format(bot))) await bot.change_presence(activity=discord.Activity( type=discord.ActivityType.listening, name=prefix + 'rtfm')) logging.info(discord.version_info) global bot_channel global general_channel global greeting_channel global info_channel bot_channel = bot.get_channel(server_cfg["bot_channel"]) general_channel = bot.get_channel(server_cfg["general_channel"]) greeting_channel = bot.get_channel(server_cfg["greeting_channel"]) info_channel = bot.get_channel(server_cfg["info_channel"]) logging.info("--------") doc = sheets.get_sheet() sheet = sheets.get_player_sheet() logging.info("Opened doc: " + str(doc.title)) logging.info("Selected sheet: " + str(sheet.title)) logging.info("Number of rows: " + str(sheet.row_count - 1)) logging.info("--------") bot.remove_command('help')
def from_gsheets(cls, sheet_name): """Make AllPairs from rectangular list.""" data = defaultdict(list) sheet = sheets.get_sheet(sheet_name) [ data[row[0]].extend(row[1:]) for i, row in enumerate(sheet) if i != 0 # skip the first row ] return cls(data)
def update_with_all_gsheets(self, stu_name_pos=0, pair_id_pos=-1): """Update pairs data with all sheets in Google Sheets.""" all_sheets = sheets.get_sheets_names() [ self.update_with_dict( _get_pairs_from_list(sheets.get_sheet(sheet_name), stu_name_pos, pair_id_pos)) for sheet_name in all_sheets if sheet_name != 'All Pairs' ] return self
def upload_metrics(credentials, sheet_id, sheet_name, combine_fns, new_metrics): sheet_range = sheet_name + "!" + DEFAULT_RANGE values = sheets_api.get_sheet(credentials, sheet_id, sheet_range) order, metrics = values_to_metrics(values) combined_order, combined_metrics = combine_metrics(order, metrics, new_metrics, combine_fns) new_values = metrics_to_values(combined_order, combined_metrics) sheets_api.set_sheet(credentials, sheet_id, sheet_range, new_values) return combined_metrics
def update_with_gsheets(self, sheet_name, stu_name_pos=0, pair_id_pos=-1): """Update pairs data with Google Sheets.""" pairs_by_id = _get_pairs_from_list(sheets.get_sheet(sheet_name), stu_name_pos, pair_id_pos) return self.update_with_dict(pairs_by_id)
#!/usr/bin/env python3.6 """ A utility to update current prices of cryptocurrencies I currently hold. """ from decimal import Decimal import yaml from CryptoCoinChartsApi import API from sheets import get_sheet, update_cells SHEETS = yaml.safe_load(open('config.yml')) THE_SHEET = SHEETS['Active'] print('Grabbing spreadsheet...\n') wallets = get_sheet(THE_SHEET['id'], THE_SHEET['range'], as_dict=True) pairs_to_update = {} for idx, wallet in enumerate(wallets): if not wallet.get('Currency') or wallet.get('Status') == 'SOLD': continue pairs_to_update[wallet['Currency'].lower()] = { 'index': idx, 'curr_rate': wallet['Current Rate'] } # Create a dict of all the currencies and the current rate # grab all trading pairs that are not sold # update any that have changed # Always add LTC/USD and BTC/USD to keep the references updated pairs = ','.join(pairs_to_update.keys()) + ',LTC/USD,BTC/USD'
from sheets import get_sheet from enum import Enum, auto uc_data = get_sheet('1IDfClme9QDOyW_P_3Gs4HiDlI6ZsblvmkH5Y3mJAejo', 'B2:N1000').get('values') class Student: class Gender(Enum): MALE = auto() FEMALE = auto() OTHER = auto() def __init__(self, schools=None, top=None, gender=None, race=None, resident=None, major=None, income=None, sat=None, act=None, wgpa=None, gpa=None, apib=None, sleep=None): self.schools = schools self.top = top #None if non-UC self.gender = gender self.race = race
def load_grades(grade_tabs=None): global grade_schemes global default_schemes grade_schemes = deepcopy(default_schemes) if grade_tabs: for tab in grade_tabs: if prefs.get_pref("is_web"): grade_rules = get_sheet(prefs.get_pref('report_sheet'), "{}!A1:Z1000".format(tab), mode='COLUMNS').get('values') else: s = openpyxl.load_workbook(prefs.get_pref('report_sheet')) grade_rules = [ list(filter(None, col)) for col in s[tab].iter_cols(values_only=True) ] s.close() if grade_rules: for s in grade_rules: scheme_data = ["", "", ""] for i, part in enumerate(r.strip() for r in re.split("[$|]", s[0])): scheme_data[i] = part scheme_arguments = list(filter(None, s[1:])) if len(scheme_arguments) > 0: scheme_data[1] = stringToGradeScale(scheme_data[1]) if scheme_data[1] == GradeScale.NONE: scheme_data[1] = GradeScale.DECREASING scheme_data[2] = stringToGradeType(scheme_data[2]) if scheme_data[2] == GradeType.NONE or scheme_data[ 2] == GradeType.SET: if scheme_data[2] == GradeType.NONE: scheme_data[2] = GradeType.SET grade_schemes[scheme_data[0]] = GradeScheme( gscale=scheme_data[1], gtype=scheme_data[2], gset=scheme_arguments) else: if GradeType.is_numeric(scheme_data[2]): try: ub = int( scheme_arguments[0] ) if scheme_arguments == GradeType.INTEGER else float( scheme_arguments[0]) if len(scheme_arguments) == 1: pb = 0 lb = 0 elif len(scheme_arguments) == 2: pb, lb = int( scheme_arguments[1] ) if scheme_arguments == GradeType.INTEGER else float( scheme_arguments[1]) else: pb = int( scheme_arguments[1] ) if scheme_arguments == GradeType.INTEGER else float( scheme_arguments[1]) lb = int( scheme_arguments[2] ) if scheme_arguments == GradeType.INTEGER else float( scheme_arguments[2]) grade_schemes[ scheme_data[0]] = GradeScheme( gscale=scheme_data[1], gtype=scheme_data[2], lower_bound=lb, upper_bound=ub, pass_bound=pb) except ValueError: print("Invalid member data") elif scheme_arguments[2] == GradeType.ALPHABETIC: pass