Google Readerのデータを保存する

Googleリーダーの終了日が近づくと、同様のサービスへのサブスクリプションの転送だけでなく、現在のすべてのレコードを保存するという質問が緊急になります。



ハブ( ここここ )のソリューションを含む見つかったソリューションは、主に2つの理由で適合しませんでした。データベースに保存する方法がなく、速度が遅いためです。 私は自転車を組み立てなければなりませんでした-grbackup

grbackup -e fake@gmail.com -p password -ba -o mongodb://localhost:27017 -w 20
      
      





20分で102のサブスクリプションから328250レコードをローカルMongoDBデータベースに保存しました



主な機能:





使用可能なストレージのタイプは、拡張機能(プラグイン)によって決定され、タイプの( -o、--output )オプションを使用して設定されます:uri type

執筆時点では、次の拡張機能が利用可能です。



Ubuntu(64)およびWin7(64)でパフォーマンスがテストされました。

提案とコメントの本はここにあります

以下は、ユーティリティの詳細な説明です。



設置


 pip install grbackup
      
      





または

 easy_install grbackup
      
      





または

 pip install git+git://github.com/wistful/grbackup.git
      
      





コマンドラインオプション


ログイン



grbackupは2つのアクションをサポートしています。



アクションは、次の4つのデータタイプのいずれかで実行できます。



追加オプション:



すべてのオプションとプラグインの説明は、 -h、-helpオプションを使用して表示できます。

 grbackup -h
      
      





前のコマンドの出力
 Usage: grbackup [options] [args] Examples: list subscriptions: grbackup -e email@gmail.com -p password -ls list topics: grbackup -e email@gmail.com -p password -lt http://feed.com list starred: grbackup -e email@gmail.com -p password -lx list all items: grbackup -e email@gmail.com -p password -la backup subscriptions: grbackup -e email@gmail.com -p password -bs -o json:/tmp/subscriptions.json backup topics: grbackup -e email@gmail.com -p password -bt http://myfeed.com -o json:/tmp/myfeed.json backup starred into MongoDB: grbackup -e email@gmail.com -p password -bx -o mongodb://localhost:27017 backup all items into Redis: grbackup -e email@gmail.com -p password -ba -o redis://localhost:6379/3 Available plugins: mongodb: save items into MongoDB output scheme: mongodb://[username:password@]hostN[:portN]]][/[db][?opts]] output examples: mongodb://localhost:27017 mongodb://user:pwd@localhost,localhost:27018/?replicaSet=grbackup json: save items into file output scheme: json:/path/to/file.json output examples: json:/home/grbackup/grbackup.json json:/tmp/grbackup/grbackup.json redis: save items into Redis output scheme: redis://username:password@host[:port]/dbindex output examples: redis://localhost:6379/3 redis://user:password@localhost:6379/0 Options: Auth Options: -e EMAIL, --email=EMAIL gmail account -p PWD, --password=PWD account password Command Options: -b, --backup backup items -l, --list list items Scope Options: -a, --all processing all items -s, --subscriptions processing subscriptions only -t, --topics processing topics only -x, --starred processing starred topics only MongoDB Options: --mongodb-db=MONGODB_DB the name of the database[default: greader] --mongodb-scol=MONGODB_SUBSCRIPTIONS collection name for subscriptions[default: subscriptions] --mongodb-tcol=MONGODB_TOPICS collection name for topics[default: topics] --mongodb-tstar=MONGODB_STARRED collection name for starred items[default: starred] --mongodb-w=MONGODB_W <int> Write operations will block until they have been replicated to the specified number [default: 1] --mongodb-j block until write operations have been committed to the journal [default: False] Redis Options: --redis-scol-prefix=REDIS_SUBS subscriptions key prefix[default: subscription] --redis-tcol-prefix=REDIS_TOPICS topics key prefix[default: topic] --redis-xcol-prefix=REDIS_STARRED starred key prefix[default: starred] Other Options: -w WORKERS, --workers=WORKERS number of workers [default: 1] -o OUTPUT, --output=OUTPUT output uri -n COUNT, --count=COUNT the number of topics that can be read at once [default: 200] -c CODING, --coding=CODING output coding [default: utf8] -v, --verbose verbose output -h, --help
      
      







使用する


サブスクリプションのリスト:
 grbackup -e email@gmail.com -p password -ls
      
      





特定のサブスクリプションのエントリのリスト:
  grbackup -e email@gmail.com -p password -lt http://habrahabr.ru/rss/hub/python/
      
      





マークされたすべてのエントリのリスト:
 grbackup -e email@gmail.com -p password -lx
      
      





すべてのエントリのリスト:
 grbackup -e email@gmail.com -p password -la
      
      





jsonファイルへのサブスクリプションの保存:
  grbackup -e email@gmail.com -p password -bs -o json:/tmp/subscriptions.json
      
      





特定のサブスクリプションのすべてのレコードをjsonファイルに保存する:
 grbackup -e email@gmail.com -p password -bt http://habrahabr.ru/rss/hub/python/ -o json:/tmp/python.json
      
      





マークされたすべてのエントリをMongoDBに保存します。
 grbackup -e email@gmail.com -p password -bx -o mongodb://localhost:27017
      
      





20スレッドを使用してRedisのすべてのレコードを保存します。
 grbackup -e email@gmail.com -p password -ba -o redis://localhost:6379/3 -w 20
      
      





プラグイン


ジョンソン


共通のURI形式: json:/path/to/file.json

マルチスレッドのサポート:はい

使用例:

 grbackup -e email@gmail.com -p password -ba -o json:/home/grbackup/grbackup.json
      
      





エントリは、オブジェクトのリストとして別のファイルに保存されます。

オブジェクトには3つのタイプがあります。





モンゴッド


共通のURI形式: mongodb:// [ユーザー名:パスワード@] hostN [:portN]]] [/ [db] [?Opts]]

マルチスレッドのサポート:はい

使用例:

 grbackup -e email@gmail.com -p password -ba -o mongodb://localhost:27017 -w 20
      
      





エントリは、 サブスクリプショントピックスター 付きの 3つのコレクションに配置されます

コレクション名は変更できます。



レディス


共通のURI形式: redis://ユーザー名:パスワード@ホスト[:ポート] / dbindex

マルチスレッドのサポート:はい

使用例:

 grbackup -e email@gmail.com -p password -ba -o redis://user:password@localhost:6379/0 -w 20
      
      





レコードの保存には、 ハッシュデータ型が使用されます。

キーには、 「subscription:record_id」「starred:record_id」「topic:record_id」の3つのタイプがあります。record_idは、レコードの一意の識別子です。

キーのプレフィックスは変更できます。



独自のプラグイン


モジュールはgrb_pluginsパッケージに含まれている必要があります。モジュールの名前は重要ではありません。

モジュール構造:



ロギングを使用してレコードをファイルに保存するプラグインの例
 #!/usr/bin/env python # coding=utf-8 from optparse import OptionGroup import logging plugin_type = "myplugin" support_threads = True description = """save items using logging output scheme: myplugin:/path/to/logfile.log output examples: myplugin:/tmp/storage.log """ def add_option_group(parser): # Plugin Options myplugin_group = OptionGroup(parser, "myplugin Options") myplugin_group.add_option("--myplugin-format", dest="format", type="str", default="%(asctime)s %(message)s", help="record format" "[default: %default]") myplugin_group.add_option("--myplugin-datefmt", dest="datefmt", type="str", default="%m/%d/%Y %I:%M:%S %p", help="date format" "[default: %default]") parser.add_option_group(myplugin_group) class WriteMyPlugin(object): def __init__(self, logger): self.logger = logger def put_subscription(self, subscription): subscription_url = subscription['id'][5:] self.logger.warning("write subscription: %s", subscription_url) def put_all(self, subscription, topic): subscription_url = subscription['id'][5:] self.put_subscription(subscription) self.put_topic(subscription_url, topic) def put_starred(self, topic): self.logger.warning("write starred: %s", topic.get('title', '')) def put_topic(self, subscription_url, topic): self.logger.warning("write topic: %s %s", subscription_url, topic.get('title', '')) class writer(object): def __init__(self, opt): path = opt.output[opt.output.index(":") + 1:] self._logger = logging.getLogger("myplugin") handler = logging.FileHandler(path) handler.setFormatter(logging.Formatter(opt.format, opt.datefmt)) self._logger.addHandler(handler) def __enter__(self): return WriteMyPlugin(self._logger) def __exit__(self, *exc_info): pass
      
      








All Articles