LoginSignup
1
0

More than 5 years have passed since last update.

自分のGistを全部別のアカウントに移動

Last updated at Posted at 2018-08-24

やりたいこと

  • 自分のGistをまとめてダウンロードする
  • それらをまとめて別のアカウントにアップロードする

このGist用のコマンドラインツールを使用する。https://github.com/defunkt/gist
インストール方法:

$ gem install gist  # あるいは `sudo gem install gist`

まとめてダウンロード

まず自分のアカウントにログインする。

$ gist --login

Gistの一覧を出してすべてクローンする。

$ for url in `gist -l | cut -d " " -f 1`; do git clone $url; done

まとめてアップロード

GistのIDとdescriptionをテキストファイルに書き出しておく。

$ gist -l | sed 's#https://gist.github.com/##g' > gist-list.txt

別アカウントにログインする。

$ gist --login

ここでshellコマンドがわからなくなってpythonに逃げる。

import os
import subprocess

with open('gist-list.txt') as f:
    x = f.read().split('\n')

for line in x:
    if line.strip()=='':
        continue
    line = line.split(' ')
    directory = line[0]
    desc = ' '.join(line[1:]).strip()

    files = [os.path.join(directory, f) for f in os.listdir(directory)]
    files = [f for f in files if os.path.isfile(f)]

    command = ['gist', '-d', desc] + files
    print(command)
    subprocess.call(command)

以上、無事移動できました。

後日

たくさん一気に挙げたのが問題だったのか、一時的にGithubアカウントを停止されてしまいました・・・。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0