コード例 #1
0
def checkLogin(responseTree = None):
    if responseTree == None:
        response = requests.get(LOGIN_URL, headers=headers, cookies=cookie_jar)
        responseTree = BeautifulSoup(response.content)

    # check for login 
    return responseTree.find('input', id="signinpasswd") == None
コード例 #2
0
ファイル: toggl.py プロジェクト: 00zl00/AlfredWorkflow.com
def startTimer(value):
    if tkn is None:
        return 'Please set Token via \'tgl token <TOKEN>\''
    else:
        wrk = requests.get('https://www.toggl.com/api/v8/workspaces', auth=(tkn, 'api_token'))
        if wrk.status_code == 200:
            default_wrk = wrk.json[0]['id']

            timer = {"time_entry":{"description":value,"duration":-1 * timestamp(datetime.now()),"start":toString(datetime.utcnow()), "wid":default_wrk, "created_with": "Alfred Toggl"}}

            res = requests.post('https://www.toggl.com/api/v8/time_entries', auth=(tkn, 'api_token'), data=json.dumps(timer))

            return 'New Timer Started at %s' % datetime.utcnow().isoformat()
コード例 #3
0
ファイル: toggl.py プロジェクト: 00zl00/AlfredWorkflow.com
def fetchTimers():
    if tkn is None:
        return 'Please set Token via \'tgl token <TOKEN>\''
    else:
        timers = requests.get('https://www.toggl.com/api/v8/time_entries', auth=(tkn, 'api_token'))
        if timers.status_code == 200:
            items = []
            for timer in timers.json:
                subtitle = 'No longer running'
                if timer['duration'] < 0:
                    subtitle = 'Currently running'
                items.append(alp.Item(title=timer['description'], subtitle=subtitle, valid=timer['duration'] >= 0, arg='start %s' % timer['description']))

            return alp.feedback(items)
コード例 #4
0
ファイル: toggl.py プロジェクト: 00zl00/AlfredWorkflow.com
def stopTimer():
    if tkn is None:
        return 'Please set Token via \'tgl token <TOKEN>\''
    else:
        timer = requests.get('https://www.toggl.com/api/v8/time_entries', auth=(tkn, 'api_token'))
        if timer.status_code == 200:
            current = timer.json[len(timer.json)-1]
            alp.log(current)
            if 'stop' in current:
                return 'No currently running timer'
            else:
                current['stop'] = toString(datetime.utcnow())
                current['duration'] = computeDuration(current)
                res = requests.put('https://www.toggl.com/api/v8/time_entries/%s' % current['id'], auth=(tkn, 'api_token'), data=json.dumps({'time_entry':current}))

                return "Stopped current timer %s" %  current['description']
コード例 #5
0
ファイル: toggl.py プロジェクト: LiuFang816/SALSTM_py_data
def fetchTimers():
    if tkn is None:
        return 'Please set Token via \'tgl token <TOKEN>\''
    else:
        timers = requests.get('https://www.toggl.com/api/v8/time_entries',
                              auth=(tkn, 'api_token'))
        if timers.status_code == 200:
            items = []
            for timer in timers.json:
                subtitle = 'No longer running'
                if timer['duration'] < 0:
                    subtitle = 'Currently running'
                items.append(
                    alp.Item(title=timer['description'],
                             subtitle=subtitle,
                             valid=timer['duration'] >= 0,
                             arg='start %s' % timer['description']))

            return alp.feedback(items)
コード例 #6
0
ファイル: toggl.py プロジェクト: LiuFang816/SALSTM_py_data
def stopTimer():
    if tkn is None:
        return 'Please set Token via \'tgl token <TOKEN>\''
    else:
        timer = requests.get('https://www.toggl.com/api/v8/time_entries',
                             auth=(tkn, 'api_token'))
        if timer.status_code == 200:
            current = timer.json[len(timer.json) - 1]
            alp.log(current)
            if 'stop' in current:
                return 'No currently running timer'
            else:
                current['stop'] = toString(datetime.utcnow())
                current['duration'] = computeDuration(current)
                res = requests.put(
                    'https://www.toggl.com/api/v8/time_entries/%s' %
                    current['id'],
                    auth=(tkn, 'api_token'),
                    data=json.dumps({'time_entry': current}))

                return "Stopped current timer %s" % current['description']
コード例 #7
0
ファイル: toggl.py プロジェクト: LiuFang816/SALSTM_py_data
def startTimer(value):
    if tkn is None:
        return 'Please set Token via \'tgl token <TOKEN>\''
    else:
        wrk = requests.get('https://www.toggl.com/api/v8/workspaces',
                           auth=(tkn, 'api_token'))
        if wrk.status_code == 200:
            default_wrk = wrk.json[0]['id']

            timer = {
                "time_entry": {
                    "description": value,
                    "duration": -1 * timestamp(datetime.now()),
                    "start": toString(datetime.utcnow()),
                    "wid": default_wrk,
                    "created_with": "Alfred Toggl"
                }
            }

            res = requests.post('https://www.toggl.com/api/v8/time_entries',
                                auth=(tkn, 'api_token'),
                                data=json.dumps(timer))

            return 'New Timer Started at %s' % datetime.utcnow().isoformat()