Exemplo n.º 1
0
    def test_text_init(self):
        """Test Spreadsheet object creation from text"""

        # 1. Create Spreadsheet object from text
        myss = spreadsheet.Spreadsheet(text=aoc_02.from_text(P1_EXAMPLE_TEXT))

        # 2. Make sure it has the specified values
        self.assertEqual(len(myss.text), 3)
        self.assertEqual(myss.part2, False)

        # 3. Check methods
        self.assertEqual(myss.checksum(), 18)
Exemplo n.º 2
0
    def test_value_init(self):
        "Test Spreadsheet object creation with values"

        # 1. Create Captcha object with values
        myss = spreadsheet.Spreadsheet(text=["5 1 9 6", "7 5 3", "2 4 6 8"])

        # 2. Make sure it has the specified values
        self.assertEqual(len(myss.text), 3)
        self.assertEqual(myss.part2, False)

        # 3. Check methods
        self.assertEqual(myss.checksum(verbose=False), 18)
Exemplo n.º 3
0
    def test_empty_init(self):
        """Test default Spreadsheet creation"""

        # 1. Create default Captcha object
        myss = spreadsheet.Spreadsheet()

        # 2. Make sure it has the default values
        self.assertEqual(myss.text, None)
        self.assertEqual(myss.part2, False)

        # 3. Check methods
        self.assertEqual(myss.checksum(), None)
Exemplo n.º 4
0
def part_two(args, input_lines):
    "Process part two of the puzzle"

    # 1. Create the spreadsheet
    spread_sheet = spreadsheet.Spreadsheet(part2=True, text=input_lines)

    # 2. Generate the checksum
    solution = spread_sheet.checksum(verbose=args.verbose)
    if solution is None:
        print("You could not generate the checksum")
    else:
        print("The checksum for the spreadsheet is %d" % (solution))

    # 3. Return result
    return solution is not None
def main():
    pp = pprint.PrettyPrinter()
    spreadsheet_object = spreadsheet.Spreadsheet("stats.json")
    heroes_data = spreadsheet_object.get_heroes_stats()
    name = input("Name of hero: ")
    boon = input("Boon(default = neutral): ")
    bane = input("bane(default = neutral): ")
    stats = spreadsheet_object.hero_stats(heroes_data, name, boon, bane)
    list_stats = list(stats.values())
    list_stats.insert(0, 5)  # Hard-code rarity 5 into data
    list_stats.insert(1, name)

    list_stats.append(boon.upper())
    list_stats.append(bane.upper())
    pp.pprint(list_stats)
    spreadsheet_object.spreadsheet_work(list_stats)
Exemplo n.º 6
0
def main():
    pp = pprint.PrettyPrinter()
    spreadsheet_object = spreadsheet.Spreadsheet("stats.json")
    scrape_object = scrape.Scrape()
    name = input("Name of hero: ").capitalize()
    heroes_data = scrape_object.scrape_hero(name)
    heroes_data = scrape_object.data_list(heroes_data, scrape_object.hero_name)
    heroes_data = scrape_object.list_into_dict(heroes_data)

    boon = input("Boon(default = neutral): ")
    bane = input("bane(default = neutral): ")
    stats = spreadsheet_object.hero_stats(heroes_data, boon, bane)
    list_stats = list(stats.values())
    list_stats.insert(0, 5)  # Hard-code rarity 5 into data
    list_stats.insert(1, scrape_object.hero_name)

    list_stats.append(boon.upper())
    list_stats.append(bane.upper())
    pp.pprint(list_stats)
    spreadsheet_object.insert_hero(list_stats)
Exemplo n.º 7
0
 def __init__(self, circuitlist):
     self.circuitlist = circuitlist
     self.watertemp = 70  # deg F
     self.spasettemp = 96  # deg F
     self.poolsettemp = 45  # deg F
     self.airtemp = 70  # deg F
     self.solartemp = 70  # deg F
     self.hash = 0  # for caching
     self.oldhash = 1
     self.responsestart = 0
     self.responseflag = False
     self.pooltime = "00:00"
     self.walltime = "00:00"
     self.r = redis.StrictRedis(host='localhost', port=6379, db=0)
     self.spreadsheet = spreadsheet.Spreadsheet()
     self.password = ''
     if gSendStats == True:
         self.statsclient = StatsdClient(statsServer, statsPort)
     else:
         self.statsclient = None
Exemplo n.º 8
0
    def test_init_create(self):
        """Init Spreadsheet object with mew spreadsheet creation."""
        SS_RESOURCE = "SS_RESOURCE"
        SHEETS = "SHEETS"

        with mock.patch("auth.authenticate",
                        return_value=SS_RESOURCE) as auth_mock:
            with mock.patch("spreadsheet.Spreadsheet._create",
                            return_value=SPREADSHEET_ID) as create_mock:
                with mock.patch(
                        "spreadsheet.Spreadsheet._init_existing_sheets",
                        return_value=SHEETS) as init_sheets_mock:
                    doc = spreadsheet.Spreadsheet(CONFIG)

                    init_sheets_mock.assert_called_once()
                create_mock.assert_called_once()
            auth_mock.assert_called_once()

        self.assertEqual(doc._config, CONFIG)
        self.assertEqual(doc._id, SPREADSHEET_ID)
        self.assertEqual(doc._ss_resource, SS_RESOURCE)
        self.assertEqual(doc.sheets, SHEETS)
Exemplo n.º 9
0
            val.append(int(float(ping2)))
    except:
        print 'Failed to execute speedtest. Network might be dead?'
        val.append(0)
        val.append(0)
        val.append(0)
    return (val)


if __name__ == '__main__':
    print 'Collecting broadband speeds and storing in spreadsheet.'
    print 'Sampling every', INTERVAL, 'minutes'
    print 'Running for', HOURS, 'hours'
    subprocess.call(['ifconfig', 'wlan0', 'down'])
    print 'Wifi disabled'
    s = spreadsheet.Spreadsheet()
    s.open("test", "w")
    list = []
    list.append(time.strftime('%d %b'))
    s.write(list)  # date in top row
    val = s.header()
    s.write(val)
    print 'Opened spreadsheet.'
    myLcd = lcd.Screen()
    myLcd.clear()
    myLcd.writerow(0, 'Broadband')
    for i in range(NUMLOOPS):
        val = get_speeds()
        string = str(val[0]) + ' ' + str(val[1]) + ' ' + str(
            val[2]) + ' ' + str(val[3])
        print string
Exemplo n.º 10
0
    quota_template = config.get('quota_email', 'template')

    # openstack auth
    auth = v3.Password(auth_url=auth_url,
                       username=admin_user,
                       user_domain_id='default',
                       project_name=admin_project,
                       project_domain_id='default',
                       password=admin_pwd)
    session = session.Session(auth=auth)
    keystone = client.Client(session=session)
    all_ks_projects = keystone.projects.list()
    quota_manager = QuotaManager(session=session, nova_version=nova_version)
    
    # get data from Google Sheet
    sheet = spreadsheet.Spreadsheet(quota_auth_file, quota_worksheet_key)
    rows = sheet.get_all_rows("Form Responses 1")
    
    try:
        project_list = parse_rows(rows, select_project=args.project)
    except NoApprovedRequests as e:
        print e.message
        sys.exit(1)

    bad_rows = []
    copy_index = []

    # NOTE: 'project' is the project data from Google Sheets
    # and 'ks_project' is the matching project resource from Keystone
    for project in project_list:
        try:
Exemplo n.º 11
0
                       username=admin_user,
                       user_domain_id='default',
                       password=admin_pwd,
                       project_domain_id='default',
                       project_name=admin_project)
    session = session.Session(auth=auth)

    openstack = Openstack(session=session,
                          nova_version=nova_version,
                          setpass_url=setpass_url)
    auth_file = get_absolute_path(config.get("excelsheet", "auth_file"))
    worksheet_key = config.get("excelsheet", "worksheet_key")
    quotas = dict(config.items('quotas'))
    email_defaults = dict(config.items('email_defaults'))

    sheet = spreadsheet.Spreadsheet(auth_file, worksheet_key)
    rows = sheet.get_all_rows("Form Responses 1")

    content, bad_rows = parse_rows(rows, select_user=args.user)

    copy_index = []
    subscribe_emails = []

    # Get these once at the beginning and update them as we add users and
    # projects with the script
    ks_users = openstack.keystone.users.list()
    ks_projects = openstack.keystone.projects.list()
    ks_member_role = openstack.keystone.roles.find(name='_member_')

    if not content:
        # FIXME: make a better exception
Exemplo n.º 12
0
def make_wtf(letters,
             sentences,
             index,
             filename,
             author='unknown',
             licence="CC BySA",
             email='',
             desc=''):
    '''
    letters is a string of all the letters in row order
    
    index is a list of lists, one list for each sentence.
       it      is  ...
    [[(0, 2), (3, 2), ...
    '''
    word_idx = set()
    for s in index:
        for w in s:
            word_idx.add(w)
    n_word = len(word_idx)
    word_idx = list(word_idx)
    print n_word, 'n_word'
    rows = [start / 16 for start, l in word_idx]
    cols = [start % 16 for start, l in word_idx]
    lens = [l for start, l in word_idx]

    bitmap = numpy.zeros((288, n_word), int)
    for r, s in enumerate(index):
        for w in s:
            col = word_idx.index(w)
            bitmap[r][col] = 1
    words = [letters[start:start + l] for start, l in word_idx]

    wtf = {
        'letters': letters,
        'data': bitmap,
        'rows': rows,  ## starting row of words
        'cols': cols,  ## starting col of words
        'lens': lens,  ## length of words
        'words': words,  ## words themselves
        'min_rows': None,  ## minute hacks
        'min_cols': None,  ## minute hacks
        'n_min_led': None,  ## minute hacks
        'n_min_state': 0,  ## minute hacks
        'min_bitmap': None,  ## minute hacks
        'author': author,
        'email': email,
        'licence': licence,
        'desc': desc,
        'filename': filename,
    }

    ss = spreadsheet.Spreadsheet()
    ss.putRegion("C1", [range(16)])
    ss.putRegion("B2", numpy.arange(16)[numpy.newaxis])
    ss.putCell('U1', 'startrow')
    ss.putCell('U2', 'startcol')
    ss.putCell('U3', 'length')
    ss.putRegion('V1', [rows, cols, lens])
    ss.putRegion('V4', [words])
    wordmap = [[['', '1'][bitmap[i, j]] for j in range(len(bitmap[i]))]
               for i in range(len(bitmap))]
    ss.putRegion('V6', wordmap)
    ss.putCell('V294', 0)  ## n minute leds
    ss.putCell('X294', 0)  ## n minute led states
    ss.putCell('A20', 'Author:')
    ss.putCell('B20', author)
    ss.putCell('A21', 'Email:')
    ss.putCell('B21', email)
    ss.putCell('A23', 'Desc:')
    ss.putCell('B23', desc)
    layout = []
    for i in range(len(letters) // 16 + 1):
        layout.append(list(letters[i * 16:(i + 1) * 16]))
    ss.putRegion('C2', layout)
    open(filename, 'w').write(ss.toString().encode('utf-8'))
    print 'wrote', filename
import pprint

import spreadsheet

pp = pprint.PrettyPrinter()
spreadsheet_object = spreadsheet.Spreadsheet("stats.json")
data = spreadsheet_object.sort_hero_data()
cell_data = []

"""
Start at y_range = 1 (and not 0) because spreadsheet row 1 is
the titles. +1 to account for this and place all hero data
below row 1.
"""
y_range = 1
for hero in data:
    cell_data.append(list(hero.values()))
    y_range += 1

spreadsheet_object.reorganize_spreadsheet(cell_data, y_range)