def setUpApi(self, codec='latin-1'):
        "Setup API with custom encoding."
        global pwd, usr
        if not (usr or pwd):
            self.api = None
        else:
            self.creds = usr, pwd
            self.api = DeliciousAPI(usr, pwd, codec)

            # should raise or return:
            update = self.api.posts_update()
            if not update:
                sys.exit("Cannot stat server, unknown error")
def main():
    username = str(raw_input('Username:'******'Pwd:')
    a = DeliciousAPI(username, pwd)

    # Get list of tagged urls
    tagposts = get_tagposts('programming')
    sleep(2)

    # Put tagged urls into list
    list1 = []
    for a in range(len(tagposts)):
        count = 0
        for b in tagposts[a]:
            count += 1
            if count == 4:
                list1.append(tagposts[a][b])

    # Get all instances of urls
    dic2 = {}
    for url in list1:
        post = get_urlposts(url)

        # Put tags into histogram
        for a in range(len(post)):
            count = 0
            for b in post[a]:
                count += 1
                if count == 3:
                    if (post[a][b] not in dic2):
                        dic2[post[a][b]] = 1
                    else:
                        dic2[post[a][b]] = dic2[post[a][b]] + 1

    # Invert the histogram and print most often first
    dic3 = invert_dict(dic2)
    # Print results
    res = dic3.keys()
    res.sort()
    res.reverse()
    print res
    for z in res:
        print dic3[z], "appears", z, "times"
Ejemplo n.º 3
0
def main():
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('db',
                        help="The ybookmarks.sqlite file in firefox "
                        "profile directory")
    args = parser.parse_args()

    conn = sqlite3.connect(args.db)
    curs = conn.cursor()
    curs.execute(
        "select rowid, name, url, shared, description, added_date from bookmarks"
    )
    bookmarks = dict(
        (id,
         Bookmark(name=name,
                  url=url,
                  add_date=added_date / 1000000,
                  private=(shared != "true"),
                  description=description))
        for id, name, url, shared, description, added_date in curs)
    curs.execute("select rowid, name from tags")
    tags = dict((id, name) for id, name in curs)
    bookmarks_tags = defaultdict(list)
    curs.execute("select bookmark_id, tag_id from bookmarks_tags")
    for bookmark_id, tag_id in curs:
        bookmarks_tags[bookmark_id].append(tag_id)

    for bookmark_id, bookmark in bookmarks.items():
        bookmark.tags = [tags[tid] for tid in bookmarks_tags[bookmark_id]]

    api = DeliciousAPI(raw_input("username: "******"password: "******"Posting %s" % bm.name
        api.posts_add(url=bm.url,
                      description=bm.name,
                      extended=bm.description,
                      tags=','.join(bm.tags),
                      dt=bm.add_date.strftime('%Y-%m-%dT%H:%M:%SZ'),
                      replace=True,
                      shared=not bm.private)
        time.sleep(1)
Ejemplo n.º 4
0
    get('DELICIOUS_USER', default='delicious-user-here'),
    get('DELICIOUS_PASS', default='some-delicious-password-here'),
    get('RETRY_ATTEMPTS', default=10, convert=int),
    get('DATABASE_FILE', default='aacinfo_db.sqlite'),
    get('SQLALCHEMY_DATABASE_URI', default='sqlite:///realpath/db_file'),
    get('SQLALCHEMY_ECHO', default=True, convert=word_for_true),
    get('USERNAME', default='admin'),
    get('PASSWORD', default='pass'),
    get('SLACK_HOOK', default='some_slack_url_here')
))

#slack
slacker = Slack(app.config['SLACK_HOOK'])

db = SQLAlchemy(app)
a = DeliciousAPI(app.config['DELICIOUS_USER'], app.config['DELICIOUS_PASS'])

EMAIL_REGEX = '\w[\w\.-]*@\w[\w\.-]+\.\w+'

login_manager = login.LoginManager()
login_manager.init_app(app)

@login_manager.user_loader
def load_user(user_id):
    return db.session.query(Users).get(user_id)


def get_mailchimp_api():
    return mailchimp.Mailchimp(app.config['MAILCHIMP_APIKEY'])

def addPostToDelicious(link,title,text,author,type_name):
Ejemplo n.º 5
0
def main(argv):
    """This will prepare al input data and call a command function to perform
    the operations. Default command is `info()`.

    Configuration file is loaded and used to store username/password.
    """

    global DEBUG

    if not argv:
        argv = sys.argv[1:]

    ### Parse argument vector
    optparser, opts, args = parse_argv_split(__options__, argv, __usage__)

    if opts['verboseness']:
        v = int(opts['verboseness'])
        DEBUG = v
        pydelicious.DEBUG = v

    # First argument is command
    if len(args) > 0:
        cmdid = args.pop(0)
    else:
        cmdid = 'info'

    if not cmdid in __cmds__:
        optparser.exit("Command must be one of %s" % ", ".join(__cmds__))

    ### Parse config file
    conf = ConfigParser()
    conf_file = opts['config']
    # reads whatever it can or nothing:
    conf.read(conf_file)

    # Check for section and initialize using options if needed
    if not 'dlcs' in conf.sections():
        # initialize a new configuration?
        if not 'username' in opts:
            opts['username'] = os.getlogin()

        if not 'password' in opts:
            opts['password'] = getpass.getpass("Password for %s: " %
                                               opts['username'])

        conf.add_section('dlcs')
        conf.set('dlcs', 'username', opts['username'])

        v = raw_input("Save password to config (%s)? [Y]es/No: " % conf_file)
        if v in ('y', 'Y', ''):
            conf.set('dlcs', 'password', opts['password'])

        conf.write(open(conf_file, 'w'))

    if not 'local-files' in conf.sections():
        # Other default settings:
        conf.add_section('local-files')
        conf.set('local-files', 'tags', expanduser("~/.dlcs-tags.xml"))
        conf.set('local-files', 'posts', expanduser("~/.dlcs-posts.xml"))
        conf.write(open(conf_file, 'w'))
    #return "Config written. Just run dlcs again or review the default config first."

    ### Merge config items under 'dlcs' with opts
    # conf provides defaults, command line options override
    options = dict(conf.items('dlcs'))
    options.update(opts)

    if not 'password' in options:
        options['password'] = getpass.getpass("Password for %s: " %
                                              options['username'])

    # Force output encoding
    sys.stdout = codecs.getwriter(options['encoding'])(sys.stdout)
    # TODO: run tests, args = [a.decode(options['encoding']) for a in args]

    # DeliciousAPI instance to pass to the command functions
    dlcs = DeliciousAPI(options['username'],
                        options['password'],
                        codec=options['encoding'])

    # TODO: integrate debugwrapper if DEBUG:
    if DEBUG > 2:
        dlcs = DebugWrapper(dlcs, sys.stderr)

    ### Defer processing to command function
    cmd = getattr(sys.modules[__name__], cmdid)
    try:
        return cmd(conf, dlcs, *args, **options)
    except PyDeliciousException, e:
        print >> sys.stderr, e
Ejemplo n.º 6
0
def post_to_Delicious(art_data):
    a = DeliciousAPI(config.DELICIOUS_USER,config.DELICIOUS_PWD)
    arturl = config.BASE_URL % art_data['bibcode'].strip()
    entry_tags = ",".join(art_data['keywords'])
    a.posts_add(arturl, art_data['title'], extended=config.EXTENDED_DESCRIPTION, tags=entry_tags)
##files = ['delicios_import.png','delicios_import.png']
##files = ['bookmarks-2013-11-05.html']

if len(files) == 0:
    print "Please choose files with tags 'a' (and href attr) and try again."
    print "Exit."
    sys.exit()

k = 1
while k:
    try:
        us = raw_input('Please type your login on Delicios: ')
        pa = raw_input('Please type your passw on Delicios: ')
        print "\n"
        user = DeliciousAPI(us, pa)
        sign = user.posts_recent()
        k = 0
    except Exception, d:
        print str(d) + "\n", "Authentication problem. Try again."
        k = 1

yes = True
no = False

# |  posts_add(self, url, description, extended='', tags='', dt='', replace=False, shared=True, **kwds)
# |      Add a post to del.icio.us. Returns a `result` message or raises an
# |      ``DeliciousError``. See ``self.request()``.
# |
# |      &url (required)
# |          the url of the item.