示例#1
0
 def format_letter(self, datas, number_of_letters_going_to_chapter):
     attrs = []
     for tup in self.fields:
         if len(tup) == 1:
             attrs.append(tup[0])
         elif len(tup) == 2:
             attrs.append(safe_get_attr(datas[tup[1]], tup[0], datas))
         elif len(tup) == 3:
             attrs.append(tup[2](safe_get_attr(datas[tup[1]], tup[0],
                                               datas)))
         elif len(tup) == 6:  # a corporation name
             try:
                 attr = ''
                 attr = getattr(datas[tup[1]], tup[0])
             except AttributeError as e:  # Mising the attribute
                 print(str(e) + ' using default value')
             if attr == '':
                 attrs.append(tup[-1])  # default value
             else:
                 attrs.append(tup[2] + attr + tup[3])
         elif len(tup) == 5:  # a name
             try:
                 attr = ''
                 attr = getattr(datas[tup[1]], tup[0])
             except AttributeError as e:  # Mising the attribute
                 print(str(e) + ' using default value')
             if attr == '':
                 attrs.append(tup[-1])  # default value
             else:
                 attrs.append(tup[2] + attr.split()[-1].capitalize() +
                              tup[3])
         elif len(tup) == 4:
             if number_of_letters_going_to_chapter <= tup[
                     2]:  # threshold for using first value
                 attrs.append(tup[0])
             else:
                 attrs.append(tup[1])
         else:
             print(tup)
             raise Exception(
                 'Unsupported tuple len (not 1, 2, 4, or 5): '.format(tup))
     print(attrs)
     return self.msg.format(*attrs).replace('your', 'the')
示例#2
0
    def get_name(self):
        try:
            if self.data.name != '':
                return self.data.name.title()
        except:
            pass
        first = safe_get_attr(self.datas[1], 'chapter_designation')
        second = safe_get_attr(self.datas[1], 'fraternity')
        if self.datas[1].chapter_designation != '':
            # out of short_name, fraternity, and chapter_designation, we need to make sure we clean the formatting of fraternity and chapter_designation
            ret = '{} of {}'.format(first.title(), second.title())
        else:
            ret = '{} {}'.format(first, second.title())


# format for the board
        if self.data.code in ['general_board', 'suspended']:
            ret += ' House Corporation'
        return ret
示例#3
0
 def send_mail(self, letter_sender):
     if self.data.address == '':
         print(
             'Skipping sending mail when address is empty for contact {}, {}, {}'
             .format(self.data.short_name, self.data.fraternity,
                     safe_get_attr(self.data, 'name')))
         return
     if 'XRTS' in self.data.address:
         print(
             'Skipping sending mail when address has been returned to sender for contact {}, {}, {}'
             .format(self.data.short_name, self.data.fraternity,
                     safe_get_attr(self.data, 'name')))
         return
     if self.data.code in Contact.mail_skip_codes:
         print('Skipping sending mail for code: {}'.format(self.data.code))
         return
     if self.data.code not in letters.letters:
         raise Exception('Code: {} is not in letters.py.letters map'.format(
             self.data.code))
     letter = self.__format_letter()
     letter_sender.send_mail(self.data.address, letter, self)
示例#4
0
    def __create_doc(self, contact_info):
        title = '{} {} {}'.format(contact_info.short_name, contact_info.fraternity, safe_get_attr(contact_info, 'name')) # TODO: same format as creating the letter
        title = contact_info.qr_code_file_name[:-4] # remove the '.png'
        body = {
                'title': title
        }
        doc = self.__exponential_backoff('''self.letter_service.documents().create(body=args[0]).execute()''', body)
        print('Created document with title: {0}'.format(
            doc.get('title')))
        file_id = doc.get('documentId')
# move it to dev sandbox
        file = self.__exponential_backoff('''self.drive_service.files().get(fileId=args[0], fields='parents').execute()''', file_id)
        previous_parents = ",".join(file.get('parents'))
# Move the file to the new folder
        self.__exponential_backoff('''self.drive_service.files().update(fileId=args[0], addParents=self.folder_id, removeParents=args[1], fields='id, parents').execute()''', file_id, previous_parents)
        return doc
示例#5
0
    def __log_contact(self, contact_info, mail_type_enum):
# get row number
        sheet_data = self.sheets_data[sc.sheet_names['contacts']]
        range_name = "addresses_clean!{}"
        row_num = 1
# try to match a contact
        for i, row in enumerate(sheet_data):
# only match when we look at the contact sheet, otherwise look at a match in houses # TODO: this is a kind of hacky way to figure out how we know if we're using a contact or a house
            if row and 'name' in contact_info._fields \
                    and row[0] == contact_info.short_name \
                    and row[1] == contact_info.fraternity:
                if mail_type_enum == MailType.MAIL and row[sc.contact_data_header.index('address')] == contact_info.address:
                    row_num += i
                    print('match for {} at row {} in contacts sheet'.format(row[2], i + 1))
                    break
        if row_num == 1:
# try to match a house
            sheet_data = self.sheets_data[sc.sheet_names['houses']]
            range_name = "houses!{}"
            for i, row in enumerate(sheet_data):
                if row and row[0] == contact_info.short_name \
                    and row[1] == contact_info.fraternity:
                    row_num += i
                    print('match for {} at row {} in houses sheet'.format(row[1], i + 1))
                    break

        if row_num == 1:
            print('ERROR: could not find a match for {} {} {}'.format(contact_info.short_name, contact_info.fraternity, safe_get_attr(contact_info, 'name')))
            return
# get column from constants
        col_num = 1 + sheet_data[0].index(sc.mail_type_enum_to_column_name[mail_type_enum])
        if col_num == 1:
            raise Exception('Column number of mail date tracking column on sheet is misconfigured, aborting.')
        r = sc.range_builder[col_num] + str(row_num)
        range_name = range_name.format(r)

# get the current value of the cell so we can append today's datetime
        current_value = sheet_data[row_num - 1][col_num - 1]
        values = [[current_value + datetime.date.today().strftime('%Y%m%d') + '\n']]
        body = {
            'values' : values,
        }

        result = self.__exponential_backoff('''self.sheet_service.spreadsheets().values().update(spreadsheetId=self.spreadsheet_id, range=args[0], valueInputOption='RAW', body=args[1]).execute()''', range_name, body)