def get_cards(self, check_only=True): now = datetime.now().to_utc() soon = now + timedelta(hours=6) soon_seconds = int(soon.strftime('%s')) now_seconds = int(now.strftime('%s')) all_cards = TrelloCard.filter(due_epoch__gte=now_seconds, due_epoch__lte=soon_seconds, user=self.default_user, closed=False) logging.info('soon: {soon} --now: {now}'.format(soon=soon_seconds, now=now_seconds)) check_ok = False cards = [] # See if there are any cards that have checklists self.num_cards = len(all_cards) logging.info('number of cards: {}'.format(self.num_cards)) for card in all_cards: logging.info('card:{id} {url} {seconds}, {due}'.format(url=card.shortUrl, seconds=str(card.due_epoch), due=card.due, id=card.idCard)) if card.idMembers is not None and \ card.checklist_finished is not None: logging.info('soon: {soon} --card:{card} -- now: {now}'.format(soon=soon_seconds, now=now_seconds, card=card.due_epoch)) if card.due_datetime is not None: if now <= card.due_datetime <= soon and card.checklist_finished is False: check_ok = True if check_only: return check_ok else: cards.append(card) if check_only: return check_ok else: return cards
def action(self): self.notify_checklist_incomplete = 'Ran' logging.debug(self.last_actor) hook = Webhook.get(model_id=self.card_data['idBoard']) card = TrelloCard.get(idCard=self.card_data['id']) logging.debug(hook.user) unarchived = unarchive_card(self.card_data['id'], hook.user) if unarchived == True: if len(self.card_data['idMembers']) == 0: trello_user = TrelloUserInfo.get(trello_id=card.idMemberCreator) send_email('*****@*****.**', """ Hello, A card has been archived that has an incomplete checklist. It has been unarchived. Please take a moment to look into this matter. %s Thanks! The Nebri Support Team This email should have been sent to %s. """ % (self.card_data['shortUrl'], trello_user.username), "An Incomplete Card has been Archived") else: for member in self.card_data['idMembers']: trello_user = TrelloUserInfo.get(trello_id=member) send_email('*****@*****.**', """ Hello, A card has been archived that has an incomplete checklist. It has been unarchived. Please take a moment to look into this matter. %s Thanks! The Nebri Support Team This email should have been sent to %s. """ % (self.card_data['shortUrl'], trello_user.username), "An Incomplete Card has been Archived") else: send_email('*****@*****.**', """ An error occurred... %s """ % unarchived, "An Error Occurred during Archiving")
def action(self): self.trello_search_template_checklist = 'RAN: {}'.format(datetime.now()) if self.default_user is None: self.default_user = DEFAULT_USER template_cards = TrelloCard.filter(is_template=True, closed=False, drip=self.drip, user=self.default_user) logging.info('starting action') logging.info('card gotten') self.num_cards = len(template_cards) card_ids = [] logging.info('starting for loop') for card in template_cards: logging.info('card id: {}'.format(card.idCard)) if card.idCard in card_ids: continue p = Process.objects.create() p.idCard = card.idCard p.drip = self.drip p.trello_copy_template = True p.default_user = self.DEFAULT_USER p.save() card_ids.append(card.idCard) logging.info('action finished')
def check(self): logging.info("start check") if self.default_user is None: self.default_user = DEFAULT_USER if self.trello_copy_template == True: try: card = TrelloCard.get( idCard=self.idCard, is_template=True, closed=False, drip=self.drip, user=self.default_user ) logging.info("card found") except Exception as e: logging.error("Error in copy template") logging.error(str(e)) self.card_get_error = str(e) return False if card: return True return False
def action(self): self.handle_unapproved_archived = 'Ran' hook = Webhook.get(model_id=self.card_data['idBoard']) try: card = TrelloCard.get(idCard=self.card_data['id'], user=self.default_user) except Process.DoesNotExist: return unarchived = unarchive_card(self.card_data['id'], hook.user) if unarchived == True: trello_user = TrelloUserInfo.get(trello_id=card.idMemberCreator) send_email('*****@*****.**', """ Hello, A card has been archived which was not approved by a board admin. It has been unarchived. Please take a moment to look into this matter. %s Thanks! The Nebri Support Team Team This email should have been sent to %s. """ % (self.card_data['shortUrl'], trello_user.username), "An Unapproved Card has been Archived") else: send_email('*****@*****.**', """ An error occurred... %s """ % unarchived, "An Error Occurred during Archiving")
def get_or_check_cards(self, check_only=True): now = datetime.now().to_utc() long_ago = datetime.now() - timedelta(days=2) now_seconds = int(now.strftime('%s')) long_ago_seconds = int(long_ago.strftime('%s')) logging.info(' Now: {now}, seconds: {s}, longago:{ago}'.format( now=now, s=now_seconds, ago=long_ago_seconds )) all_overdue_cards = TrelloCard.filter( due_epoch__lte=now_seconds, due_epoch__gte=long_ago_seconds, overdue_notice_sent=False, user=self.default_user ) if check_only: return len(all_overdue_cards) > 0 else: return all_overdue_cards
def action(self): self.handle_trello_webhook = "Ran" logging.debug("handle new trello webhook") if self.hook_data["action"]["type"] == "updateCard" and self.hook_data["action"]["data"]["card"].get( "closed", False ): # card has been archived. check for rule prerequisites logging.debug("this card was archived!") card = TrelloCard.get(idCard=self.card_data.get("id"), user=self.default_user) logging.debug(card) logging.debug(card.checklist_finished) # let's check checklists first if card.checklist_finished == False: self.notify_checklist_incomplete = True # next let's check for approved status approved_commenter = None for action in self.comment_data["actions"]: if action["data"]["text"] == "approved": approved_commenter = action["memberCreator"] break if approved_commenter is None or approved_commenter["username"] not in self.board_admins: self.handle_unapproved_archived = True
def action(self): self.trello_copy_template = "RAN: {}".format(datetime.now()) logging.info("start action") client = get_client(self.default_user) logging.info("client found") card = TrelloCard.get(idCard=self.idCard, user=self.default_user) card = template_checklist_setup(card, client) self.template_idList = card.template_idList logging.info("template_list {}".format(card.template_idList)) # self.json_data = card.card_json # self.description = self.json_data.get('description') logging.info("card updated") out = copy_template_card(client, card) self.out = out.id # if new_card is not None: # self.new_id = new_card.id logging.info("finished")
def card_json_to_model(card, user): epoch = '1970-01-01T12:00:00.00+0000' pepoch = iso8601.parse_date(epoch) logging.info('card list is next: ') logging.info(str(card)) new = False # card_obj, new = TrelloCard.get_or_create(idCard=card.get('id')) try: card_obj = TrelloCard.get(idCard=card.get('id'), user=user) except Process.DoesNotExist: logging.debug('create new.....') card_obj = TrelloCard(idCard=card.get('id'), user=user) card_obj.save() new = True except Exception as e: logging.info('error finding too many cards...') logging.debug(str(e)) if len(TrelloCard.filter(idCard=card.get('id'))) > 1: for tcard in TrelloCard.filter(idCard=card.get('id'), user=user): tcard.delete() logging.debug('create new.....') card_obj = TrelloCard(idCard=card.get('id'), user=user) card_obj.save() new = True # update card # check webhook json response card_obj.idBoard = card.get('idBoard') card_obj.idMembers = card.get('idMembers') card_obj.idLabels = card.get('idLabels') card_obj.idChecklists = card.get('idChecklists') card_obj.idList = card.get('idList') card_obj.checklists = card.get('checklists') card_obj.due = card.get('due') card_obj.due_epoch = None card_obj.due_datetime = None card_obj.name = card.get('name') card_obj.shortUrl = card.get('shortUrl') card_obj.card_json = card card_obj.closed = card.get('closed', False) card_obj.is_template = False card_obj.template_idBoard = None card_obj.template_idList = None card_obj.drip = None logging.info(str(card_obj.due)) if card_obj.idMemberCreator is False: card_obj.idMemberCreator = None if card_obj.due is not None and card_obj.due != '': try: # Timezone was set to UTC in the instance. This will make sure that # UTC is always broght in duedate = iso8601.parse_date(card_obj.due) except Exception as e: logging.error('TrelloCard date error: ' + str(e)) else: # card_obj.due_epoch = (duedate - epoch).total_seconds() card_obj.due_epoch = int(duedate.strftime('%s')) card_obj.due_datetime = duedate labels = card.get('labels', []) if labels != []: for label in labels: name = label.get('name') if name == 'template checklist': card_items = template_checklist_parser(card_obj) if card_items is None: card_obj.is_template = False else: card_obj.is_template = True card_obj.drip = card_items.get('drip') card_obj.save() return card_obj, new