Beispiel #1
0
def delete(arg):
    import urllib,urllib2
    import main

    config = main.config_data()
    try:
        user = config['pinboard_username']
        token = config['pinboard_token']
    except:
        print "Setup not complete\npbauth username:token"
        sys.exit(0)

    deleted_url = main.deleted_url_data()
    history = main.launch_history()
    try:
        url = 'https://api.pinboard.in/v1/posts/delete?format=json&auth_token=%s:%s&url=%s'%(user,token,urllib.quote(arg))
        data = urllib2.urlopen(url).read()
        ret = json.loads(data)
        if ret['result_code']=='done':
            print "%s deleted"%urlparse.urlparse(arg)[1]
            deleted_url.append(arg)
            with open(os.path.join(alfred.work(False),'deleted-url.json'),'w+') as f:
                json.dump(deleted_url,f)

            if arg in history:
                del history[arg]
                with open(os.path.join(alfred.work(False),'launch-history.json'),'w+') as f:
                    json.dump(history,f)
        else:
            print ret['result_code']
    except:
        print "Error"
Beispiel #2
0
def delete(arg):
    import urllib,urllib2
    import main

    config = main.config_data()
    try:
        user = config['pinboard_username']
        token = config['pinboard_token']
    except:
        print "Setup not complete\npbauth username:token"
        sys.exit(0)

    deleted_url = main.deleted_url_data()
    history = main.launch_history()
    try:
        url = 'https://api.pinboard.in/v1/posts/delete?format=json&auth_token=%s:%s&url=%s'%(user,token,urllib.quote(arg))
        data = urllib2.urlopen(url).read()
        ret = json.loads(data)
        if ret['result_code']=='done':
            print "%s deleted"%urlparse.urlparse(arg)[1]
            deleted_url.append(arg)
            with open(os.path.join(alfred.work(False),'deleted-url.json'),'w+') as f:
                json.dump(deleted_url,f)

            if arg in history:
                del history[arg]
                with open(os.path.join(alfred.work(False),'launch-history.json'),'w+') as f:
                    json.dump(history,f)
        else:
            print ret['result_code']
    except:
        print "Error"
Beispiel #3
0
def reload():
    imageregex = re.compile(r"img.*src=\"(.*?)\"")
    config = main.config_data()

    d = feedparser.parse('http://macnews.tistory.com/rss')
    items = []
    for e in d.entries:
        try:
            imageurl = imageregex.search(e.description)
            if imageurl:
                url = imageurl.group(1)
                filepath = os.path.join(alfred.work(True), os.path.split(url)[1])
                if not os.path.exists(filepath):
                    urllib.urlretrieve(url, filepath)
                    cmd = "sips -z 72 72 '%s'" % filepath
                    subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True)
                imageurl = filepath
            else:
                imageurl = u"icon.png"
        except:
            imageurl = u"icon.png"
        items.append({'title':e.title,'published':e.published,'link':e.link,'image':imageurl})

    with open(os.path.join(alfred.work(True), 'rss-cache.json'), 'w+') as myFile:
        myFile.write(json.dumps(items))

    config['last_updated'] = int(time.time())
    with open(os.path.join(alfred.work(False), 'config.json'), 'w+') as myFile:
        myFile.write(json.dumps(config))

    print "Reloading BackToTheMac completed..."
def addpocket(q):
    config = main.config_data()
    try:
        token = config['pocket_access_code']
    except KeyError:
        print "Please login first with pbauthpocket"
        sys.exit(0)

    req_data = {'consumer_key': CONSUMER_KEY, 'access_token': token, 'url': q}
    resp = makeRequest(json.dumps(req_data), 'https://getpocket.com/v3/add/')
    if resp["status"] == 1:
        print "Succesfully posted to pocket"
Beispiel #5
0
def addpocket(q):
    config=main.config_data()
    try:
        token=config['pocket_access_code']
    except KeyError:
        print "Please try to login first with pbauthpocket"
        sys.exit(0)

    req_data = {
        'consumer_key':CONSUMER_KEY,
        'access_token':token,
        'url':q
        }
    resp = makeRequest(json.dumps(req_data),'https://getpocket.com/v3/add/')
    if resp["status"] == 1:
        print "Succesfully posted to pocket"
Beispiel #6
0
def reload():
    imageregex = re.compile(r"img.*src=\"(.*?)\"")
    config = main.config_data()

    d = feedparser.parse('http://macnews.tistory.com/rss')
    items = []
    for e in d.entries:
        try:
            imageurl = imageregex.search(e.description)
            if imageurl:
                url = imageurl.group(1)
                filepath = os.path.join(alfred.work(True),
                                        os.path.split(url)[1])
                if not os.path.exists(filepath):
                    urllib.urlretrieve(url, filepath)
                    cmd = "sips -z 72 72 '%s'" % filepath
                    subprocess.check_output(cmd,
                                            stderr=subprocess.STDOUT,
                                            shell=True)
                imageurl = filepath
            else:
                imageurl = u"icon.png"
        except:
            imageurl = u"icon.png"
        items.append({
            'title': e.title,
            'published': e.published,
            'link': e.link,
            'image': imageurl
        })

    with open(os.path.join(alfred.work(True), 'rss-cache.json'),
              'w+') as myFile:
        myFile.write(json.dumps(items))

    config['last_updated'] = int(time.time())
    with open(os.path.join(alfred.work(False), 'config.json'), 'w+') as myFile:
        myFile.write(json.dumps(config))

    print "Reloading BackToTheMac completed..."
Beispiel #7
0
    def getAuthToken(self):
        config=main.config_data()
        try:
            code = config['pocket_request_code']
        except:
            logger.info("getAuthToken invalid code")
            sys.exit(0)

        logger.info("request code is" + code)
        req_data = json.dumps({
                    "consumer_key": pocket.CONSUMER_KEY, "code": code
                })
        logger.info("Trying to get auth token")
        try:
            resp_data = pocket.makeRequest(req_data, pocket.POCKET_API_URL + 'authorize/')
            logger.info('Token received! :'+ resp_data["access_token"])
            config['pocket_access_code']=resp_data["access_token"]
            with open(os.path.join(alfred.work(False), 'config.json'), 'w+') as myFile:
                myFile.write(json.dumps(config))
            logger.info("Logged in as "+ resp_data["username"])
        except Exception:
            logger.error("Could not login - something went wrong")
Beispiel #8
0
# -*- coding: utf-8 -*-
#
# Copyright 2014 Jaemok Jeong([email protected])
#
# [2014/02/21]

import os
import json
import urllib
import main

import sys
reload(sys)
sys.setdefaultencoding('utf-8')

config = main.config_data()

try:
    user = config['pinboard_username']
    token = config['pinboard_token']
except:
    print "Setup not complete\npbauth username:token"
    exit(0)

try:
    url = 'https://api.pinboard.in/v1/posts/all?format=json&auth_token=%s:%s' % (
        user, token)
    data = urllib.urlopen(url).read()
    filename = os.environ['HOME'] + '/.bookmarks.json'
    f = open(filename, 'w')
    f.write(data)
Beispiel #9
0
        url = 'https://api.pinboard.in/v1/notes/list?format=json&auth_token=%s:%s'%(user,token)
        data = urllib.urlopen(url)
        return json.load(data)
    except IOError:
        return {}

def update_content(notes_cache,id,hash):
    try:
        for n in notes_cache['notes']:
            if n['id']==id and n['hash']==hash:
                return n['text']
    except KeyError:
        return ""
        
if __name__ == '__main__':
    config = main.config_data()
    try:
        user=config['pinboard_username']
        token=config['pinboard_token']
    except:
        print "Setup not complete\npbauth username:token"
        exit(0)

    try:
        url = 'https://api.pinboard.in/v1/posts/all?format=json&auth_token=%s:%s'%(user,token)
        data = urllib.urlopen(url).read()
        filename = os.environ['HOME']+'/.bookmarks.json'
        f = open(filename,'w')
        f.write(data)
        f.close()
        try: