Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-6 of 6 total  RSS 

delicious read later bookmarklet

javascript:delicious=window.open('https://api.del.icio.us/v1/posts/add?description='+encodeURIComponent(document.title)+'&tags=2read'+'&url='+window.location.href,'delicious','toolbar=no,width=50,height=50');setTimeout('delicious.close()',1500);

Backup all your del.icio.us bookmarks to XML

https://api.del.icio.us/v1/posts/all
curl --user accountname:password -o myDelicious.xml -O 'https://api.del.icio.us/v1/posts/all'

Export del.icio.us links to MT Import Format

A friend of mine needed his del.icio.us links in MT Import format for some reason. This solved that problem.

require 'rexml/document'
require 'net/https'
require 'rubygems'

# change credentials!
user = 'username'
pass = 'password'

# User-Agent: required for del.icio.us api
agent = 'delicious-mt'
xml = ''

http = Net::HTTP.new('api.del.icio.us', 443)
http.use_ssl = true
http.start do |http|
  request = Net::HTTP::Get.new('/v1/posts/all', {'User-Agent' => agent})
  request.basic_auth(user, pass)
  response = http.request(request)
  response.value
  xml = response.body
end
 
REXML::Document.new(xml).elements.each('posts/post') do |el|
  puts "TITLE: #{el.attributes['description']}"
  puts "AUTHOR: Author Name"
  puts "DATE: #{DateTime.parse(el.attributes['time']).strftime("%m/%d/%Y %H:%M:%S")}"
  puts "-----"
  puts "BODY:"
  puts el.attributes['extended']
  puts "-----"
  puts "EXCERPT:"
  puts el.attributes['href']
  puts "KEYWORDS:"
  puts el.attributes['tag']
  puts "-----"
  puts "--------"
end

Use the del.icio.us API via HTTPS from Ruby

Found at http://www.juretta.com/log/2006/08/13/ruby_net_http_and_open-uri/

require 'net/https'
require "rexml/document"

username = "" # your del.icio.us username
password = "" # your del.icio.us password

resp = href = "";
begin      
  http = Net::HTTP.new("api.del.icio.us", 443)
  http.use_ssl = true
  http.start do |http|
    req = Net::HTTP::Get.new("/v1/tags/get", {"User-Agent" => 
        "juretta.com RubyLicious 0.2"})
    req.basic_auth(username, password)
    response = http.request(req)
    resp = response.body
  end     
  #  XML Document
  doc = REXML::Document.new(resp)    
  # iterate over each element <tag count="200" tag="Rails"/>
  doc.root.elements.each do |elem|
    print elem.attributes['tag']  + " -> " + elem.attributes['count'] + "\n"
  end
  
rescue SocketError
  raise "Host " + host + " nicht erreichbar"
rescue REXML::ParseException => e
  print "error parsing XML " + e.to_s
end

get recent tags used by any user on delicious

Still using the delicious-py module
>>>import delicious
>>> delicious.get_userposts('dfdeshom').tags[1:]
[u'gnuplot', u'math math/culture', u'python', u'music', u'creativity', u'python', u'academia/culture advice gradschool', u'academia/culture advice gradschool', u'wordpress', u'python unicode', u'advice creativity', u'delicious', u'creativity', u'code programming tags', u'delicious', u'math/culture', u'wordpress', u'linux', u'wordpress', u'python', u'python', u'python', u'python', u'computer-algebra math number-theory python', u'php', u'haiti', u'delicious', u'haiti', u'delicious', u'creativity']
>>>

Get link popularity on delicious

We are using python's delicious-py module

  
def get_popular_count(user="user"):
    import delicious
    notapi = delicious.DeliciousNOTAPI()

    #Get user's posts 
    user_posts = notapi.get_posts_by_user(user)

    data = '#tagID popularity\n' 
    
    #For each url, get how popular it is
    for i in range(len(user_posts)):
        data += str(i)+" "+str(len(notapi.get_posts_by_url(user_posts[i]["url"])))+'\n' 
    
    str1 = user + "-data" #file name
    data_file = file(str1,'w')
    data_file.write(data)
    data_file.close()


The resulting file will look like this:
$ less jemisa-data
#tagID popularity
0 6
1 744
2 928
3 120
4 1934
5 111
6 425
7 16
8 19
9 2
10 44
11 308
12 12
13 1
14 1
15 7
16 3
17 46
18 7
19 139
20 318
21 174
22 288
23 3
24 1
25 33
26 3
27 154
« Newer Snippets
Older Snippets »
Showing 1-6 of 6 total  RSS