python JSONでとっておく。主に混帐と切り离されている问题迴りのバックアップ目的

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python JSONでとっておく。主に混帐と切り离されている问题迴りのバックアップ目的相关的知识,希望对你有一定的参考价值。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>setminami.py.githubWatcher</string>
    <key>ProgramArguments</key>
    <array>
        <string>/Users/setminami/anaconda/bin/python3</string>
        <string>/Volumes/WD Scorpion Blue/BkupUtils/Pythons/githubWatcher.py</string>
    </array>
    <key>KeepAlive</key>
    <false/>
    <key>RunAtLoad</key>
    <true/>
    <key>UserName</key>
    <string>setminami</string>
    <key>StartInterval</key>
        <integer>7200</integer>
    <key>StandardOutPath</key>
    <string>/Users/setminami/github-watcher.txt</string>
    <key>StandardErrorPath</key>
    <string>/Users/setminami/github-watcher-error.txt</string>
</dict>
</plist>
# -*- coding: utf-8 -*-
"""
What: backup Github environments and fetch remotes to local disk.
How: keep recent local image always, leave backup processing to Timemachine and launchctl.

Supports Github API v3.
https://developer.github.com/v3/
see issues, labels
"""
import os
import sys, io
import requests

HOME = '/Users/setminami'
GITHUB_LOCAL_SRCDIR = HOME + '/Desktop/GitHub/.'
GITHUB_LOCAL_DSTDIR = '/Volumes/WD Scorpion Blue/Bkups/GitHubBackups'
GITHUB_USER = 'setminami'
GITHUB_PASSWORD = '123qweasd'
REPO = 'AppSummoner'  # format is username/repo

AUTH = (GITHUB_USER, GITHUB_PASSWORD)

def write_issues(response, out):
    "output a list of issues to csv"
    if not response.status_code == 200:
        raise Exception(response.status_code)
        pass
    else :
        out.write(response.text)
        pass

def parsePages(response):
    return dict([(rel[6:-1], url[url.index('<')+1:-1]) for url,
        rel in [link.split(';') for link in response.headers['link'].split(',')]])

def fetchGeneral(repo, outFile, list, payload = {}):
    ISSUES_FOR_REPO_URL = 'https://api.github.com/repos/%s/%s/%s' % (GITHUB_USER, repo, list)
    r = requests.get(ISSUES_FOR_REPO_URL, params=payload, auth=AUTH)
    f = open(outFile, 'w', encoding='utf-8')
    write_issues(r, f)

    # more pages? examine the 'link' header returned
    if 'link' in r.headers:
        pages = parsePages(r)
        while 'last' in pages and 'next' in pages:
            print("Next page")
            r = requests.get(pages['next'], auth=AUTH)
            write_issues(r, f)
            if pages['next'] == pages['last']:
                break
            pages = parsePages(r)
            pass
    f.close()

def fetchRepoNames():
    REPO_URL = 'https://api.github.com/user/repos'
    payload = {"type":"owner"}
    r = requests.get(REPO_URL, params=payload, auth=AUTH)
    list = {}
    for d in r.json():
        list[d['name']] = d['clone_url']
        pass
    return list

sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8')
repos = os.listdir(GITHUB_LOCAL_SRCDIR)
print("repos = %s"%repos)
remote = fetchRepoNames()
print(remote)

for x in remote.keys():
    cloned = GITHUB_LOCAL_SRCDIR + '/' + x
    if x in repos and os.path.isdir(cloned) :
        os.chdir(cloned)
        os.system('git fetch --prune')
        os.system('git fetch')
    else:
        os.chdir(GITHUB_LOCAL_SRCDIR)
        os.system('git clone %s' % remote[x])
    fetchGeneral(x, GITHUB_LOCAL_DSTDIR + '/%s-issues.json' % (x.replace('/', '-')), 'issues', {"state":"all"})
    fetchGeneral(x, GITHUB_LOCAL_DSTDIR + '/%s-labels.json' % (x.replace('/', '-')), 'labels')
    pass


以上是关于python JSONでとっておく。主に混帐と切り离されている问题迴りのバックアップ目的的主要内容,如果未能解决你的问题,请参考以下文章

php 20180320ロード中にロゴ表示しておくやつ

忍者乱太郎片尾曲叫啥?

text 混帐のブランチをFZFで切り替える

csharp [ClosedXMLでExcel帐票] Excelで帐票のテンプレートを作成しておくことで,Excel帐票を作成します。ヘッダやフッタはExcelに记载した$ {templatename

javascript 画面幅によって画像を切り替える

javascript [日付のフォーマット处理]日付をフォーマットして返します。フォーマットを省略した场合は2018/03/10(土)21:51:48.578のような形で返します。关数化しておくとフォ