def kanboardpost(board, content): #enable API access in kanboard and get url + token url = '' name = '' token = '' kb = kanboard.Client(url, name, token) newsubtask = kb.create_subtask(task_id=board, title=content)
def __init__(self, iden=config.PROJECT_IDENTIFIER): self.kb = kanboard.Client(config.KANBOARD_ADDRESS, config.KANBOARD_USERNAME, config.KANBOARD_USER_TOKEN) self.project = self.kb.getProjectByIdentifier(identifier=iden) self.kb_pid = self.project['id']
PROJECT_ID = '1' NO_PROOFREAD_USER_IDS = ('0', '236', '22') JOB_TYPE_TO_RATE = { 'D': 'I3', 'DD': 'I4', 'P': 'I5', 'S': 'I6', } STARTING_ROW = 1 CNY_PAYMENT_CELLS = 'D2:E' USD_PAYMENT_CELLS = 'F2:G' VIDEO_CELLS = 'A2:B' # read boards kb = kanboard.Client("https://kb.nixiesubs.xyz/jsonrpc.php", secret['kanboard']['username'], secret['kanboard']['api']) # ltt, tq, sc = kb.getBoard(project_id=PROJECT_ID) # if ltt['name'] != 'LTT' or tq['name'] != 'TQ' or sc['name'] != 'SC': # print("Boards should be strictly in order: LTT, TQ, SC") # exit(1) class Video: def __init__(self, **kwargs): self.title = kwargs.get('title') self.segments = kwargs.get('segments') self.totalTime = kwargs.get('totalTime') def secondsToTime(seconds): return '{hour}:{minute}:{sec}'.format(hour=str((seconds // 3600)).zfill(2),
def main(): imap_connection = imap_connect(IMAPS_SERVER, IMAPS_USERNAME, IMAPS_PASSWORD) typ, data = imap_search_unseen(imap_connection) for num in data[0].split(): """ for each unread mail do """ typ, data = imap_connection.fetch(num, '(RFC822)') raw_email = data[0][1] email_message = email.message_from_bytes(raw_email) local_task_start_date_ISO8601 = convert_to_kb_date( email_message['Date']) local_task_due_date_ISO8601 = convert_to_kb_date( email_message['Date'], KANBOARD_TASK_DUE_OFFSET_IN_HOURS) email_from = email_message['From'] """ extract email address if specified as 'name <email address>' """ email_address = re.sub('[<>]', '', re.findall('\S+@\S+', email_from)[-1]) email_to = email_message['To'] subject = email.header.make_header( email.header.decode_header(email_message['Subject'])) body, kb_attachments = walk_message_parts(email_message) email_address, local_task_start_date_ISO8601, local_task_due_date_ISO8601 = handle_well_known_forwarders( WELL_KNOWN_EMAIL_ADDRESSES, KANBOARD_TASK_DUE_OFFSET_IN_HOURS, body, email_address, local_task_start_date_ISO8601, local_task_due_date_ISO8601) kb_text = 'From: %s\n\nTo: %s\n\nDate: %s\n\nSubject: %s\n\n%s' % ( email_from, email_to, local_task_start_date_ISO8601, subject, body) """ connect to kanboard api """ kb = kanboard.Client(KANBOARD_CONNECT_URL + '/jsonrpc.php', 'jsonrpc', KANBOARD_API_TOKEN) kb_user_id = create_user_for_sender(kb, email_address) """ add user to group """ if KANBOARD_GROUP_ID > 0: # pragma: no cover - will get tested once config is refactored kb.add_group_member(group_id=KANBOARD_GROUP_ID, user_id=kb_user_id) """ get id from project specified """ kb_project_id = kb.get_project_by_name( name=str(KANBOARD_PROJECT_NAME))['id'] kb_task_id, kb_task = get_task_if_subject_matches(kb, subject) if kb_task: reopen_and_update(kb, kb_task, kb_task_id, kb_user_id, kb_text, local_task_due_date_ISO8601) else: """ create task in project specified """ kb_task_id = kb.create_task( project_id=str(kb_project_id), title=str(subject), creator_id=kb_user_id, date_started=local_task_start_date_ISO8601, date_due=local_task_due_date_ISO8601, description=kb_text) """ add the email as an attachment to the task in case it's not properly displayed in the description or comment """ if kb_task_id != False: kb_attachments['%s.mbox' % re.sub('[^\w_.)( -]', '_', str(subject))] = base64.b64encode(raw_email) for i in kb_attachments: kb.create_task_file(project_id=str(kb_project_id), task_id=str(kb_task_id), filename=i, blob=kb_attachments[i].decode('utf-8')) imap_close(imap_connection)
#!/usr/bin/env python3 import kanboard kb = kanboard.Client('http://localhost/Sites/kanboard/jsonrpc.php', 'admin', 'admin') x = kb.getmydashboard() mytime = {} for i in range(len(x)): if x[i]['project_name'] == '2019-2020': # mytitle = x[i]['title'] mykey = x[i]['title'].split(':')[0] mytitle = x[i]['title'].split(':')[1] if mykey in mytime.keys(): mytime[mykey] = mytime[mykey] + x[i]['time_spent'] else: mytime[mykey] = x[i]['time_spent'] for i in mytime: print(i, mytime[i]) # myid = x[i]['id'] # mycolumn = x[i]['column_name'] # # mytime = x[i]['time_spent'] # print('{}: {}: {}: {}:'.format(myid, mycolumn, mytime, mytitle)) # x[11]['title'].split(':')[0] # 'benchm' # x[11]['title'].split(':')[1] # ' openacc install gcc'
##################################### reload_json() updater = Updater(token=bot_token, use_context=True) dispatcher = updater.dispatcher logging.basicConfig( format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) #connect to kanboard try: kb = kanboard.Client(kb_url, kb_user, kb_pw) except: print(str(lang["error"]["load_bot"])) ##################################### def is_granted(cur_id, cur_list): for e in range(0, len(cur_list)): if int(cur_id) == int(cur_list[e]): return True return False def has_permission(update, context): access = False cur_id = update.message.chat_id
def main(): """ connect and authenticate against mailserver """ imap_connection = imaplib.IMAP4_SSL(IMAPS_SERVER) imap_connection.login(IMAPS_USERNAME, IMAPS_PASSWORD) """ get unread mails """ imap_connection.select('INBOX') typ, data = imap_connection.search(None, 'unseen') for num in data[0].split(): """ for each unread mail do """ typ, data = imap_connection.fetch(num, '(RFC822)') raw_email = data[0][1] email_message = email.message_from_bytes(raw_email) local_task_start_date_ISO8601 = convert_to_kb_date( email_message['Date']) local_task_due_date_ISO8601 = convert_to_kb_date( email_message['Date'], KANBOARD_TASK_DUE_OFFSET_IN_HOURS) email_from = email_message['From'] """ extract email address if specified as 'name <email address>' """ email_address = re.sub('[<>]', '', re.findall('\S+@\S+', email_from)[-1]) email_to = email_message['To'] subject = email.header.make_header( email.header.decode_header(email_message['Subject'])) kb_attachments = {} for part in email_message.walk(): """ get plain text body details """ if part.get_content_maintype() == 'multipart': continue if part.get('Content-Disposition') is None: if part.get_content_type() == 'text/plain': body = re.sub( '\r\n', '\r\n\r\n', part.get_payload(decode=True).decode('utf-8')) continue fileName = email.header.make_header( email.header.decode_header(part.get_filename())) if bool(fileName): kb_attachments[str(fileName)] = base64.b64encode( part.get_payload(decode=True)) body = '%s\n\n<< Attachment: %s >>' % (body, fileName) """ if the email has been forwarded from specified addresses use sender email address and timestamp from message body """ fwd_email_addresses = re.findall('(From:.*\S+@\S+|To:.*\S+@\S+)', '%s' % body) if fwd_email_addresses: fwd_to_email_address = re.sub( '[<>]', '', re.findall('\S+@\S+', fwd_email_addresses[1])[-1]) if fwd_to_email_address in WELL_KNOWN_EMAIL_ADDRESSES: email_address = re.sub( '[<>]', '', re.findall('\S+@\S+', fwd_email_addresses[0])[-1]) local_task_start_date_ISO8601 = convert_to_kb_date( re.sub( 'Date:\s*', '', re.search('Date:[\S ]+', '%s' % body, re.MULTILINE).group(0))) local_task_due_date_ISO8601 = convert_to_kb_date( re.sub( 'Date:\s*', '', re.search('Date:[\S ]+', '%s' % body, re.MULTILINE).group(0)), KANBOARD_TASK_DUE_OFFSET_IN_HOURS) kb_text = 'From: %s\n\nTo: %s\n\nDate: %s\n\nSubject: %s\n\n%s' % ( email_from, email_to, local_task_start_date_ISO8601, subject, body) """ connect to kanboard api """ kb = kanboard.Client(KANBOARD_CONNECT_URL + '/jsonrpc.php', 'jsonrpc', KANBOARD_API_TOKEN) """ create user for sender email if it doesn't exist """ kb_user_id = None kb_users = kb.get_all_users() for kb_user in kb_users: if kb_user['email'] == email_address: kb_user_id = kb_user['id'] if kb_user_id == None: kb_user_id = kb.create_user(username=email_address, password=email_address, email=email_address) """ add user to group """ if KANBOARD_GROUP_ID > 0: kb.add_group_member(group_id=KANBOARD_GROUP_ID, user_id=kb_user_id) """ get id from project specified """ kb_project_id = kb.get_project_by_name( name=str(KANBOARD_PROJECT_NAME))['id'] """ search for link to already existing task """ kb_task_search_result = re.findall('\[KB#\d+', '%s' % subject) kb_task = None if kb_task_search_result: kb_task_id = re.sub('\[KB#', '', kb_task_search_result[-1]) """ test if task already exists """ kb_task = kb.get_task(task_id=kb_task_id) if kb_task: """ reopen task, update due date and add email as comment """ if kb_task['is_active'] == 0: kb.open_task(task_id=kb_task_id) """ add email as comment """ kb.create_comment(task_id=kb_task_id, user_id=kb_user_id, content=kb_text) kb.update_task(id=kb_task_id, date_due=local_task_due_date_ISO8601) else: """ create task in project specified """ kb_task_id = kb.create_task( project_id=str(kb_project_id), title=str(subject), creator_id=kb_user_id, date_started=local_task_start_date_ISO8601, date_due=local_task_due_date_ISO8601, description=kb_text) """ add the email as an attachment to the task in case it's not properly displayed in the description or comment """ if kb_task_id != False: kb_attachments['%s.mbox' % re.sub('[^\w_.)( -]', '_', str(subject))] = base64.b64encode(raw_email) for i in kb_attachments: kb.create_task_file(project_id=str(kb_project_id), task_id=str(kb_task_id), filename=i, blob=kb_attachments[i].decode('utf-8')) """ close mailserver connection """ imap_connection.close() imap_connection.logout()
def setUp(self): self.url = 'some api url' self.client = kanboard.Client(self.url, 'username', 'password') self.request, self.urlopen = self._create_mocks()
pdf.spacer() for project in kb.get_my_projects(): print(project['name']) pdf.h2(project['name']) l = [] for task in kb.get_all_tasks(project_id=project['id'], status_id=1): l.append(task['title']+" id: " + task['id']) print(" ", task['title']) pdf.ul(l) pdf.generate() return f.getvalue() if __name__ == "__main__": import kanboard import time kb = kanboard.Client('http://localhost/jsonrpc.php', 'admin', 'e7c16f5e7565eaceaaadfb1ef55cfe8f15cbe9853966dfcf057d0ecc355a') # with open("tasks.pdf", "wb") as pdf: # pdf.write(tasks_report(kb)) user = kb.get_me() start_timetracking(kb, 21, user['id']) # time.sleep(90) stop_timetracking(kb, 21, user['id'])
# Import configuration config = configparser.ConfigParser() config.read("ldap2kanboard.conf") # Configure logging logging.basicConfig(level=eval(config.get("logging", 'level')), filename=config.get("logging", 'file'), format='%(asctime)s:%(levelname)s:%(message)s') # logging.info("Running ldap2kanboard.py") # Create Kanboard API instance kb = kanboard.Client(config.get("kanboard", "url"), config.get("kanboard", "user"), config.get("kanboard", "password")) # Create an LDAP instance t = ldap3.Tls(validate=ssl.CERT_NONE) server = ldap3.Server(config.get("ldap", "url"), tls=t) con = ldap3.Connection(server, config.get("ldap", "bind_dn"), config.get("ldap", "password"), auto_bind=False) con.open() con.start_tls() con.bind()
import time from datetime import datetime, timezone, timedelta from www.models import Event, Subtitle, Talk, Speaker, Talk_Persons start = datetime.now(timezone.utc) print("Start: ", start) kanboards_to_check = [2, 3] # all tasks from these boards status_to_check = [0, 1] # all active and inactive tasks # API-KEY of admin user API_KEY = "db03bd402e8bc0a9da581b3481af0f07823e1c012b7c4f2d34ac675a4358" client = kanboard.Client('https://tasks.c3subtitles.de/jsonrpc.php', 'admin', API_KEY) print("Tasks without connection in the database:") for any_board in kanboards_to_check: print("Board:", any_board) for any_status in status_to_check: result = client.get_All_Tasks(project_id=any_board, status_id=any_status) for any in result: task_id = any["id"] counter = 0 my_talks = Talk.objects.filter(kanboard_public_task_id=task_id) counter += my_talks.count() my_talks = Talk.objects.filter(kanboard_private_task_id=task_id) counter += my_talks.count()
#Input # "task_id": t_id=7 import sys t_id=sys.argv[1] import datetime import kanboard kb = kanboard.Client('http://192.168.100.221/kanboard/jsonrpc.php', 'jsonrpc', '392dc75baf66ae2205e9d0655a3e150c5766d011031658c7a1f3d152f5ef') TaskProperties=kb.getTask(task_id=t_id) AllInternalTaskLinks=kb.getAllTaskLinks(task_id=t_id) AllTaskComments=kb.getAllComments(task_id=t_id) AllTaskFiles=kb.getAllTaskFiles(task_id=t_id) UpdateSwitch=0 for i in range(0,len(AllInternalTaskLinks)): InternalTaskLinkById=kb.getTaskLinkById(task_link_id=AllInternalTaskLinks[i]['id']) if InternalTaskLinkById['link_id']=='12' and InternalTaskLinkById['label']=='updatet': UpdateSwitch=1 OppositeTask=kb.getTask(task_id=InternalTaskLinkById['opposite_task_id']) #Comment tmp_Comments=[] for j in range(0,len(AllTaskComments)): tmp_Comments.append("* "+datetime.datetime.fromtimestamp(int(AllTaskComments[j]["date_creation"])).isoformat()+" ("+datetime.datetime.fromtimestamp(int(AllTaskComments[j]["date_modification"])).isoformat()+"):\n'"+AllTaskComments[j]["comment"]+"'\n\n") tmp_CommentsMin=min(len(tmp_Comments), 2) tmp_CommentId=kb.createComment(task_id=InternalTaskLinkById['opposite_task_id'], user_id=0, content=''.join(tmp_Comments[::-1][:tmp_CommentsMin])) #Attachment tmp_AllTaskFiles=kb.removeAllTaskFiles(task_id=InternalTaskLinkById['opposite_task_id']) for j in range(0,len(AllTaskFiles)):