Bash或Python:如何从Github下载单个指定文件? [英] Bash or Python: How to download a single specified file from Github?

查看:113
本文介绍了Bash或Python:如何从Github下载单个指定文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个脚本,该脚本会定期从我的Github帐户下载特定文件。我已经看到此Github页面,这似乎是我正在寻找什么,但是我无法使其正常工作。可能是因为我不太了解用户字段是什么(而不是用户名)。如果有人成功使用此方法,请举个例子吗?另外,如果您使用其他方法,请告诉我吗?

I need to write a script which periodically downloads a specific file from my Github account. I've seen this Github page which seems to be what I am looking for, but I have not been able to get it to work. Perhaps this is because I do not really understand what the "user" field is (as opposed to "username"). If anybody had any success with this method, could you please provide an example? Also, if you used another method, could you please let me know? Thanks in advance!

推荐答案

这应该可以(未经测试,但应该给您一个想法):

This should work (untested, but should give you an idea):

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]])

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

It will call the script again after the time has elapsed, and exit. As long as the command finishes without an error, it will keep calling itself again.

这篇关于Bash或Python:如何从Github下载单个指定文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆