Beispiel #1
0
def main():
    wf = Workflow()
    error = None
    try:
        # initialize client
        access_token = wf.get_password('pocket_access_token')
        pocket_instance = Pocket(config.CONSUMER_KEY, access_token)

        since = wf.cached_data('pocket_since', max_age=0) or 0
        links = wf.cached_data('pocket_list', max_age=0) or {}

        next_since = 0
        offset = 0
        while True:
            get = pocket_instance.get(
                detailType='complete',
                since=since,
                state='all',
                count=LINK_LIMIT,
                offset=offset
            )[0]

            data = get['list']
            next_since = get['since']

            if get['status'] != 1 or len(data) == 0:
                break

            links.update(data)
            offset += LINK_LIMIT

        # Delete obsolete entries
        for item_id in links.keys():
            if links[item_id]['status'] == '2':
                del links[item_id]

        wf.cache_data('pocket_since', next_since)
        wf.cache_data('pocket_list', links)
        tags = list(set([t for l in links.values() if 'tags' in l
                         for t in l['tags'].keys()]))
        wf.cache_data('pocket_tags', tags)

        # update fulltext search index
        for item_id in links.keys():
            url = links[item_id]['given_url']
            if not FullText.has_link(url):
                FullText.get_instance().add_page(url)
            time.sleep(.1)

    except (AuthException, URLError, PocketException, PasswordNotFound), e:
        error = type(e).__name__
        wf.cache_data('pocket_error', error)

        # delete token if authentication failed
        if error == 'AuthException':
            wf.delete_password('pocket_access_token')
Beispiel #2
0
def favorite_item(url):
    item_id = get_id(url)
    if not item_id:
        return '"item_id" not found'
    access_token = WF.get_password('pocket_access_token')
    pocket_instance = Pocket(config.CONSUMER_KEY, access_token)
    try:
        pocket_instance.favorite(item_id, wait=False)
        return 'Link favorited'
    except PocketException:
        return 'Connection error'
def delete_item(url):
    item_id = get_id(url)
    if not item_id:
        return '"item_id" not found'
    access_token = WF.get_password('pocket_access_token')
    pocket_instance = Pocket(config.CONSUMER_KEY, access_token)
    try:
        pocket_instance.delete(item_id, wait=False)
        remove_from_cache(item_id)
        FullText.get_instance().del_page(url)
        return 'Link deleted'
    except PocketException:
        return 'Connection error'
def main():
    wf = Workflow()
    error = None
    try:
        # initialize client
        access_token = wf.get_password('pocket_access_token')
        pocket_instance = Pocket(config.CONSUMER_KEY, access_token)

        since = wf.cached_data('pocket_since', max_age=0) or 0
        links = wf.cached_data('pocket_list', max_age=0) or {}

        next_since = 0
        offset = 0
        while True:
            get = pocket_instance.get(detailType='complete',
                                      since=since,
                                      state='all',
                                      count=LINK_LIMIT,
                                      offset=offset)[0]

            data = get['list']
            next_since = get['since']

            if get['status'] != 1 or len(data) == 0:
                break

            links.update(data)
            offset += LINK_LIMIT

        # Delete obsolete entries
        for item_id in links.keys():
            if links[item_id]['status'] == '2':
                del links[item_id]

        wf.cache_data('pocket_since', next_since)
        wf.cache_data('pocket_list', links)

    except (AuthException, URLError, PocketException, PasswordNotFound), e:
        error = type(e).__name__
        wf.cache_data('pocket_error', error)

        # delete token if authentication failed
        if error == 'AuthException':
            wf.delete_password('pocket_access_token')
Beispiel #5
0
import argparse
import os
import subprocess
import urlparse
from pocket_api import Pocket, InvalidQueryException
from workflow import Workflow
import config

WF = Workflow()
POCKET = Pocket(config.CONSUMER_KEY, WF.get_password('pocket_access_token'))

FRONTMOST_APP = """\
osascript -e 'application (path to frontmost application as text)'\
"""
BROWSER_SCRIPTS = {
    'Firefox': {
        'url': """\
osascript -e 'tell application "Firefox" to activate\n \
  set old_clipboard to the clipboard\n \
  tell application "System Events"\n \
      repeat until (exists window 1 of process "Firefox") \n \
        delay 0.1 \n \
      end repeat\n \
      keystroke "l" using command down\n \
      keystroke "c" using command down\n \
  end tell\n \
  delay .5\n \
  set new_clipboard to the clipboard\n \
  set the clipboard to old_clipboard\n \
  return new_clipboard' \
""",