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.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 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 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