【发布时间】:2015-06-22 16:44:37
【问题描述】:
这里是 Python 新手,这是我当前的脚本:
#!/usr/bin/env python
import os
import time
import datetime
import subprocess
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime(%Y%m%d)
我的 curl 命令:
curl -i -k -H -o <timestamp>.txt "Accept: application/json" -H "Content-Type: application/json" -H "appID:******" -H "appKey:*******" -X GET https://*****.com/csOpen/workplace/hr/v1/employees_s?type=EMP&location=******&term_from=<timestamp>
这个 curl 请求的动态方面来自我脚本的 python 部分。我需要输出文件是 $currentTime.txt,我需要 php 变量 $term_from 也是时间戳。
到目前为止,我尝试使用
调用 curl 命令os.system('curl -i -k -H -o' + %st + '.txt "Accept: application/json" -H "Content-Type: application/json" -H "appID:arcsght_app" -H "appKey:*****" -X GET https://csopen.teamaol.com/csOpen/workplace/hr/v1/employees_s?type=EMP&location=Dulles&term_from=' + %st)
那没用,然后我尝试使用
subprocess.call(<same curl command as above>)
那没用。
我已经从 bash 尝试了我的 curl 命令并且它可以工作,我可以获取我的时间戳来显示我需要它。我只是无法弄清楚如何将所有内容联系在一起。在我发布这篇文章之前,我确实尝试过自己解决这个问题,但这是我对 python 的第一次真正的冒险,所以我对什么有效,什么无效的了解非常少。寻求帮助!谢谢。
【问题讨论】:
-
我只会在 shell 的
curl调用中使用$(date +"%Y%m%d"),不会编写任何 Python 代码。