4

我需要编写一个脚本,定期从我的 Github 帐户下载特定文件。我已经看到了这个 Github 页面,这似乎是我正在寻找的,但我无法让它工作。也许这是因为我不太了解“用户”字段是什么(而不是“用户名”)。如果有人用这种方法取得了成功,你能举个例子吗?另外,如果您使用其他方法,请告诉我吗?提前致谢!

4

3 回答 3

1

这取决于文件类型。对于非二进制文件,当您在 github 中打开文件时,您可以通过单击“编辑”旁边的“原始”按钮来获取文件的 url。然后,您可以只使用curlwget下载它。

这是一张图片,可以让事情变得清楚:

在此处输入图像描述

然后复制网址:

在此处输入图像描述

于 2013-07-24T20:05:57.857 回答
0

Assuming the file is synced, I'd write a bash script that went something like this:

#!/bin/bash
# file: ./getFromGit
# cd into git-synced directory and update the file
cd /directory/path/
git checkout origin/branch /path/to/file/in/dirStructure

Then

$ chmod u+x ./getFromGit
$ cp getFromGit /usr/local/bin # or wherever your executables like git are

Now from any directory you like, you can call getFromGit and it will get the file you want.

See this tutorial from Jason Rudolph for more info on checking out a single file from a given branch with git.

If it's not synced, I agree with @jh314: just use wget

于 2013-07-24T20:24:31.600 回答
0

这应该有效(未经测试,但应该给你一个想法):

import time
import subprocess
import sys
import shlex

if __name__ == "__main__":
    cmd = ("curl -L" if sys.platform == "darwin" else "wget")
    url = ......
    cmd += " {0} -o {1}".format(url, url.split("/")[-1])
    p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

    (stdout, stderr) = p.communicate()

    if stderr:
        raise Exception(stderr)

    time.sleep(...)

    # Call another instance of this script
    subprocess.Popen(['python', sys.argv[0]])

时间过去后它会再次调用脚本,然后退出。只要命令完成而没有错误,它就会继续再次调用自己。

于 2013-07-25T03:47:54.920 回答