manywaypark's Blog
개발, 검색, 함수

delicious.com firefox extension data 파일에서 링크 정보 추출하기에 관해 설명한다.

opt in 어쩌구 하는 메시지는 가볍게 무시했었는데, 어느날 부터 서비스가 안되는 것이었다. Orz.
메시지 뿌려대기 시작할 때 무지무지 바빴는데, 바쁜게 끝났을 때는 메시지 무시하는 것이 버릇이 되어있었다.

서비스가 안되는 시점에 여러 검색을 해봤지만 뾰족한 방법이 없었다.
이상한 베타 블로그(http://deliciousengineering.blogspot.com/2011/09/welcome-to-delicious-beta-status-blog.html)에서 곧 조치를 취할거니 기다려 달라는 이야기만 있었다.

그래서 기다리는 중에 또 정신 없이 바빠졌다. 
시간이 좀 지나서 검색해보니 방법들이 있었다.
그런데 아래 링크대로 해봤지만 안됐다.
한시적인 서비스인 것도 있었고, dns 속여서 이전 서비스 접속하는 것도 안됐다.
http://www.avos.com/how-to-get-old-bookmarks-from-yahoo/
http://gabrielleabelle.livejournal.com/337468.html
https://www.delicious.com/settings/ws/import/bookmarks

욕이 나오기 시작했다.
한국 욕을 하면 못알아먹으니 영어로해야할것만 같은 생각도 두어번 들었다.

약간의 오기로 조금 뒤지기 시작했다.
의외로 간단히 firefox의 데이터 파일을 찾을 수 있었다.
C:\Documents and Settings\[UserId]\Application Data\Mozilla\Firefox\Profiles\rwiin5gt.default\ybookmarks.sqlite

혹시 모르니 데이터 파일 백업후 플러그인만 업글해보기로했다.
nsYDelLocalStore.js가 신나게 돌며 전부 삭제해버렸다. 미치기 직전이다.

ybookmarks.sqlite를 delicious.com의 import/export 에 쓰는 html(대충 보니 netscape 형식인듯)로 변환해서 해결하기로 방향을 정하고 다음과 같은 erlang 프로그램으로 모든 link들을 html 파일로 변경한 다음에 import 하니 해결되었다.

출력파일을 보면 제대로 동작해야할 것같은데 현재로서는 다음과 같은 문제가 있다:
  1. 한글이 모조리 없어지는 문제. 
  2. utf-8로 인코딩된 url이 delicious.com에서 redirect될 때 제대로 되지 않는 문제
    (%EC가 URL 내에 있다면, 실제 제목에 걸린 링크에서 redirect시키면서 %25EC로 된다).
일단 상기 문제는 delicious.com에 problem으로 등록했다.

%%%-------------------------------------------------------------------
%%% File    : to_html.erl
%%% Author  : M.W. Park <manywaypark@gmail.com>
%%% Description : converts delicious bookmark data file into html file for import.
%%%   1. install sqlite-erlang3(https://github.com/alexeyr/erlang-sqlite3).
%%%   2. copy ybookmarks.sqlite as delicious.db in current dir.
%%%   3. elrc to_html.erl
%%%   4. erl -noshell -pa [path/to/sqlite-erlang/ebin/] -run to_html doIt -run init stop
%%%   5. import output file(delicious.html) at http://export.delicious.com/settings/bookmarks/import
%%%
%%% Known Problems (for now) :
%%%   1. Hangul(Korean letters) is ignored by delicious (i registered ths issue).
%%%   2. UTF-8 encoded urls are not working (an odd 25 is added(%EC->%25EC) when delicious redirects it, so can't connect to the right url).
%%%
%%% Created : 2011-12-09 Friday by M.W. Park
%%%-------------------------------------------------------------------

-module(to_html).
-export([doIt/0]).

doIt() ->
    {ok,Output}=file:open("delicious.html",[write]),
    io:format(Output, "~s~n", [prefix()]),
    sqlite3:open(delicious), % open 'delicious.db'
    [{columns, _Columns}, {rows, Bookmarks}] = sqlite3:sql_exec(delicious, "select rowid,name,url,added_date,shared,description from bookmarks;"), % for all bookmarks
    lists:foreach(fun(Bookmark) ->
 %%io:format("row=~p~n", [Bookmark]),
 io:format(Output, "~s~n", [xmerl_ucs:to_utf8(bookmark(Bookmark))])
 end,
 Bookmarks),
    sqlite3:close(delicious),
    io:format(Output, "~s~n", [postfix()]),
    file:close(Output).

bookmark(Bookmark) ->
    {RowId, Name, Url, Date, Shared, Desc} = Bookmark,
    io_lib:format("<DT><A HREF=\"~s\" ADD_DATE=\"~ts\" PRIVATE=\"~p\" TAGS=\"~ts\">~ts</A>
<DD>~ts", [Url, re:replace(integer_to_list(Date), "000000$", "", [{return,list}]), if <<"true">> =:= Shared -> 0; true -> 1 end, get_tags(RowId), xmerl_ucs:from_utf8(Name), xmerl_ucs:from_utf8(Desc)]).

get_tags(RowId) ->
    Q = io_lib:format("select * from tags where rowid in (select tag_id from bookmarks_tags where bookmark_id=~p);", [RowId]),
    [{columns, _Columns}, {rows, Tags}] = sqlite3:sql_exec(delicious, Q),
    string:join(lists:map(fun({Tag}) -> xmerl_ucs:from_utf8(Tag) end, Tags), ",").

prefix() ->
    io_lib:format("<!DOCTYPE NETSCAPE-Bookmark-file-1>~n"
     "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\">~n"
     "<!-- This is an automatically generated file.~n"
     "It will be read and overwritten.~n"
     "Do Not Edit! -->~n"
     "<TITLE>Bookmarks</TITLE>~n"
     "<H1>Bookmarks</H1>~n"
     "<DL><p>", []).

postfix() ->
    io_lib:format("</DL><p>", []).

 happy hackin'
1 
분류 전체보기 (306)
잡담 (20)
함수형 언어 (65)
emacs (16)
java (18)
tips & tricks (154)
사랑 (1)
가사 (0)
독서 (4)
mobile (6)
비함수형 언어 (2)

공지사항

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

04-18 21:03