Skip to content

Commit

Permalink
Introduce workflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrzej Skrodzki authored and Andrzej Skrodzki committed Aug 11, 2019
1 parent 6f2e27e commit 19de39d
Show file tree
Hide file tree
Showing 14 changed files with 6,142 additions and 12 deletions.
27 changes: 27 additions & 0 deletions alfred-workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# encoding: utf-8

import sys
from workflow import Workflow, ICON_WEB, web
from src import api, env


def main(wf):
print("asdasd")
local_env = env.read_local_env()
token = local_env["token"]
workspaces = api.get_all_workspaces(token)

# Loop through the returned posts and add an item for each to
# the list of results for Alfred
for workspace in workspaces:
wf.add_item(title=workspace['name'],
subtitle=workspace['id'],
icon=ICON_WEB)

# Send the results to Alfred as XML
wf.send_feedback()


if __name__ == u"__main__":
wf = Workflow()
sys.exit(wf.run(main))
Empty file added src/__init__.py
Empty file.
20 changes: 8 additions & 12 deletions src/api.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from config import API_URL
import datetime
import utils
import requests



def get_all_workspaces(token):
headers = {
'content-type': 'application/json',
Expand All @@ -21,31 +19,29 @@ def get_all_projects(token, workspaceId):
'content-type': 'application/json',
'X-Api-Key': token
}
response = requests.get(API_URL + f"workspaces/{workspaceId}/projects", headers=headers)
response = requests.get(API_URL + "workspaces/" + workspaceId + "/projects", headers=headers)
data = response.json()

projects = list(map(lambda x: { "id": x['id'], "name": x['name'] }, data))
return projects

def put_time_entry(token, workspaceId, projectId, date, numHours):
def put_time_entry(token, workspaceId, projectId, date_str, hours_spent):
headers = {
'content-type': 'application/json',
'X-Api-Key': token
}
start_date = datetime.datetime.strptime(date, '%Y-%m-%d') + datetime.timedelta(hours=7)
end_date = start_date + datetime.timedelta(hours=numHours)

date_format = "%Y-%m-%dT%H:%M:%S.%fZ"

[start, end] = utils.get_timeentry_range(date_str, hours_spent)

data = {
"start": start_date.strftime(date_format),
"start": start,
"billable": "true",
"projectId": projectId,
"end": end_date.strftime(date_format),
"end": end,
}

print(data)
response = requests.post(API_URL + f"workspaces/{workspaceId}/time-entries", json=data, headers=headers)
response = requests.post(API_URL + "workspaces/" + workspaceId + "/time-entries", json=data, headers=headers)
data = response.json()

print(data)
15 changes: 15 additions & 0 deletions src/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from datetime import datetime, timedelta

def get_timeentry_range(date_str, hours_spent):
parsed_date = None
try:
parsed_date = datetime.strptime(date_str, '%Y-%m-%d')
except ValueError:
raise AssertionError("Date is in wrong format")

start_date = parsed_date + timedelta(hours=7)
end_date = start_date + timedelta(hours=hours_spent)

date_format = "%Y-%m-%dT%H:%M:%S.%fZ"

return [start_date.strftime(date_format), end_date.strftime(date_format)]
Binary file added workflow/Notify.tgz
Binary file not shown.
108 changes: 108 additions & 0 deletions workflow/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/usr/bin/env python
# encoding: utf-8
#
# Copyright (c) 2014 Dean Jackson <deanishe@deanishe.net>
#
# MIT Licence. See http://opensource.org/licenses/MIT
#
# Created on 2014-02-15
#

"""A helper library for `Alfred <http://www.alfredapp.com/>`_ workflows."""

import os

# Workflow objects
from .workflow import Workflow, manager
from .workflow3 import Variables, Workflow3

# Exceptions
from .workflow import PasswordNotFound, KeychainError

# Icons
from .workflow import (
ICON_ACCOUNT,
ICON_BURN,
ICON_CLOCK,
ICON_COLOR,
ICON_COLOUR,
ICON_EJECT,
ICON_ERROR,
ICON_FAVORITE,
ICON_FAVOURITE,
ICON_GROUP,
ICON_HELP,
ICON_HOME,
ICON_INFO,
ICON_NETWORK,
ICON_NOTE,
ICON_SETTINGS,
ICON_SWIRL,
ICON_SWITCH,
ICON_SYNC,
ICON_TRASH,
ICON_USER,
ICON_WARNING,
ICON_WEB,
)

# Filter matching rules
from .workflow import (
MATCH_ALL,
MATCH_ALLCHARS,
MATCH_ATOM,
MATCH_CAPITALS,
MATCH_INITIALS,
MATCH_INITIALS_CONTAIN,
MATCH_INITIALS_STARTSWITH,
MATCH_STARTSWITH,
MATCH_SUBSTRING,
)


__title__ = 'Alfred-Workflow'
__version__ = open(os.path.join(os.path.dirname(__file__), 'version')).read()
__author__ = 'Dean Jackson'
__licence__ = 'MIT'
__copyright__ = 'Copyright 2014-2019 Dean Jackson'

__all__ = [
'Variables',
'Workflow',
'Workflow3',
'manager',
'PasswordNotFound',
'KeychainError',
'ICON_ACCOUNT',
'ICON_BURN',
'ICON_CLOCK',
'ICON_COLOR',
'ICON_COLOUR',
'ICON_EJECT',
'ICON_ERROR',
'ICON_FAVORITE',
'ICON_FAVOURITE',
'ICON_GROUP',
'ICON_HELP',
'ICON_HOME',
'ICON_INFO',
'ICON_NETWORK',
'ICON_NOTE',
'ICON_SETTINGS',
'ICON_SWIRL',
'ICON_SWITCH',
'ICON_SYNC',
'ICON_TRASH',
'ICON_USER',
'ICON_WARNING',
'ICON_WEB',
'MATCH_ALL',
'MATCH_ALLCHARS',
'MATCH_ATOM',
'MATCH_CAPITALS',
'MATCH_INITIALS',
'MATCH_INITIALS_CONTAIN',
'MATCH_INITIALS_STARTSWITH',
'MATCH_STARTSWITH',
'MATCH_SUBSTRING',
]
Loading

0 comments on commit 19de39d

Please sign in to comment.