昔からブックマーク=twitterのfavだったのですが、いつの間にやら積んどく状態に…
いい加減postgresにいれてみた。

  1. twitterのGET favorites/list ページの 「OAuth Signature Generator」のプルダウンから自分のアカウントを選択(自分の場合はapi_john_doe_)
  2. 生成ページで「GET OAuth Signature」をポチるとcurlのコマンドが出てくるのでそれをコピー(Request query:でcountの値を変えると取得できるレコード数が増える
  3. favのデータのjsonを取得/変換してjson型のテーブルにぶっこむ
  4. [postgres@localhost ~]$ curl --get 'https://api.twitter.com/1.1/favorites/list.json' --data 'amp%3Bscreen_name=episod&count=200' --header 'Authorization: OAuth oauth_consumer_key="***************", oauth_nonce="******************", oauth_signature="*******************", oauth_signature_method="HMAC-SHA1", oauth_timestamp="************", oauth_token="*************", oauth_version="1.0"' --verbose > a
    * About to connect() to api.twitter.com port 443 (#0)
    *   Trying 199.59.148.20... connected
    * Connected to api.twitter.com (199.59.148.20) port 443 (#0)
    * Initializing NSS with certpath: sql:/etc/pki/nssdb
    *   CAfile: /etc/pki/tls/certs/ca-bundle.crt
      CApath: none
    * SSL connection using TLS_RSA_WITH_AES_128_CBC_SHA
    * Server certificate:
    * 	subject: CN=api.twitter.com,OU=Twitter Security,O="Twitter, Inc.",L=San Francisco,ST=California,C=US
    * 	start date: Aug 03 00:00:00 2014 GMT
    * 	expire date: Dec 31 23:59:59 2016 GMT
    * 	common name: api.twitter.com
    * 	issuer: CN=VeriSign Class 3 Secure Server CA - G3,OU=Terms of use at https://www.verisign.com/rpa (c)10,OU=VeriSign Trust Network,O="VeriSign, Inc.",C=US
    > GET /1.1/favorites/list.json?amp%3Bscreen_name=episod&count=20 HTTP/1.1
    > User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.13.6.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
    > Host: api.twitter.com
    > Accept: */*
    > Authorization: OAuth oauth_consumer_key="***************", oauth_nonce="******************", oauth_signature="*******************", oauth_signature_method="HMAC-SHA1", oauth_timestamp="************", oauth_token="*************", oauth_version="1.0"
    >
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
      0     0    0     0    0     0      0      0 --:--:--  0:00:05 --:--:--     0< HTTP/1.1 401 Authorization Required
    < content-length: 61
    < content-type: application/json;charset=utf-8
    < date: Fri, 16 Jan 2015 14:13:18 UTC
    < server: tsa_a
    < set-cookie: guest_id=v1%3A142141759813334824; Domain=.twitter.com; Path=/; Expires=Sun, 15-Jan-2017 14:13:18 UTC
    < strict-transport-security: max-age=631138519
    < x-connection-hash: 57d6660532cbbb0a7799d9fa7f2dcbce
    < x-response-time: 5
    <
      0    61    0     0    0     0      0      0 --:--:--  0:00:05 --:--:--     0{ [data not shown]
      0    61    0    61    0     0     10      0 --:--:--  0:00:05 --:--:--   525* Connection #0 to host api.twitter.com left intact
    
    * Closing connection #0
    [postgres@localhost ~]$ cat a | jq . -c | sed -e s%\},\{\"created_at%}]\\n[{\"created_at%g | sed -e "s/\\\/\\\\\\\\/g" > aa
    
    あ、そういえばjq使ってました。sed で1行づつにして、エスケープを追加しています。
     
    [postgres@localhost ~]$ psql test
    psql (9.4.0)
    Type "help" for help.
    
    test=# \d+ test
                            Table "public.test"
     Column | Type | Modifiers | Storage  | Stats target | Description
    --------+------+-----------+----------+--------------+-------------
     json   | json |           | extended |              |
    
    test=# COPY test FROM '/home/postgres/aa' ;
    COPY 200
    test=# SELECT json#>'{0}'->'text' FROM test limit 1;
                                                                ?column?
    --------------------------------------------------------------------------------------------------------------------------------
     "whitech0c0のはてブ棚卸し : チーム開発に必要なgit コマンドを神速で習得しよう! - 酒と泪とRubyとRailsと http://t.co/4zHgoZozfA"
    (1 row)
    
    test=# \q
    [postgres@localhost ~]$
    
    大外いらない気もするけど削除するのも面倒だったのでとりあえず…

Add Comments

名前
 
  絵文字
 
 
プロフィール

john_doe_

Twitter
instagram(SnapWidget)
タグクラウド
  • ライブドアブログ