Ejemplo n.º 1
0
class NS1Base(object):

    # https://trello.com/b/1diHBDGp/
    SPRINT_BOARD_ID = '56b0bee08a91f6b079ba6ae9'

    def __init__(self):
        self.client = None
        self._me = None

    def check_api_key(self):
        if not os.getenv('TRELLO_API_KEY') or not os.getenv('TRELLO_API_SECRET'):
            raise Exception("You must define TRELLO_API_KEY and TRELLO_API_SECRET, from these: https://trello.com/app-key")

    def check_oauth(self):
        if not os.getenv('TRELLO_OAUTH_KEY') or not os.getenv('TRELLO_OAUTH_SECRET'):
            self.create_oauth()

    def create_oauth(self):
            from trello import util
            util.create_oauth_token()
            sys.exit(0)

    def init_client(self):
        self.client = TrelloClient(api_key=os.getenv('TRELLO_API_KEY'),
                                   api_secret=os.getenv('TRELLO_API_SECRET'),
                                   token=os.getenv('TRELLO_OAUTH_KEY'),
                                   token_secret=os.getenv('TRELLO_OAUTH_SECRET'))
        # check for auth
        try:
            self.client.list_organizations()
        except Unauthorized:
            print "RECEIVED UNAUTHORIZED, RECREATING OAUTH"
            self.create_oauth()

    @property
    def me(self):
        if self._me:
            return self._me
        self._me = Member(self.client, 'me')
        self._me.fetch()
        return self._me

    def boot(self):
        self.check_api_key()
        self.check_oauth()
        self.init_client()
Ejemplo n.º 2
0
    def process_julgamento_list(self):
        try:
            for card in self.AUDIENCIAS_E_JULGAMENTOS_LIST.list_cards():
                #Dict Structure
                data = {
                    "processo": None,
                    "descricao": None,
                    "Tarefa": None,
                    "Cliente": None,
                    "Criado em": None,
                    "Prazo Fatal": None,
                    "Prazo": None,
                    "Realizado em": None,
                    "Advogado": None
                }

                #Processing Dict
                data["processo"] = card.name  #card name -> processo
                data["descricao"] = card.description  #Description

                #Setting up custom fields
                for customField in card.customFields:
                    data[customField.name] = customField.value

                #Setting up name
                try:
                    user_id = card.member_id[0]
                    user_id = Member(self.client, user_id)
                    user = user_id.fetch().full_name
                    data["Advogado"] = self.filter_name(user)
                except:
                    print("Advogado não atrelado ao card " + card.name)
                    continue

                #Dates
                data["Realizado em"] = self.clean_date(data["Realizado em"])
                data["Criado em"] = self.clean_date(data["Criado em"])
                data["Prazo Fatal"] = self.clean_date(data["Prazo Fatal"])
                data["Prazo"] = self.clean_date(data["Prazo"])

                self.AUDIENCIAS.addCard(data['Advogado'], data)
        except:
            self.LOGGER += "Advogado não atrelado ao card " + card.name
            print("[FAILURE] process_julgamento_list")
Ejemplo n.º 3
0
    def _create_card(self, data):
        trello_client = self.get_trello_client()
        trello_list = trello_client.get_board(data.get('board_id')).get_list(
            data.get('board_list_id'))
        card = trello_list.add_card(name=data.get('name'),
                                    desc=data.get('desc'))
        (filename, mime_type,
         file_content) = self._get_attachment_file(data.get('attachment'))
        card.attach(name=filename, mimeType=mime_type, file=file_content)

        for member_id in data.get('members', tuple()):
            member_id and card.add_member(Member(trello_client, member_id))

        for label_id in data.get('labels', tuple()):
            label_id and card.add_label(Label(trello_client, label_id, ""))

        return card
Ejemplo n.º 4
0
 def me(self):
     if self._me:
         return self._me
     self._me = Member(self.client, 'me')
     self._me.fetch()
     return self._me