在python中,第一次创建文件夹时,会创建目录并在该文件夹路径中成功创建文件。当再次需要在同一位置创建新文件时,我收到此错误:
Run Code Online (Sandbox Code Playgroud)[Errno 17] File exists: '/home/test/files/tweets/'.
请问有什么建议吗?
if len(downloadedfile) > 0:
#insert_time=time.strftime('%Y_%-m_%-d')
#download_path='/home/test/files/tweets/'
#file_path= download_path+insert_time+"/"+hashes
#print(file_path)
now = datetime.now
new_folder = '/home/test/files/tweets/{}'.format(now().strftime('%Y_%-m_%-d'))
os.mkdir(new_folder, 0755 );
folder_path = new_folder+"/"+hashes
fo = open(folder_path,"wb")
fo.write(downloadedfile)
fo.close()
print("File Downloaded")
else:
print("File Not Downloaded")
Run Code Online (Sandbox Code Playgroud) 我IP address在文件中有一个庞大的列表,我想将所有IP地址替换为指定的字符串( Example : X.X.X.X)。
#Example.txt
1,1.1.1.1
2,10.10.10.10
3,5.5.5.5
4,6.6.6.6
.........
Run Code Online (Sandbox Code Playgroud)
我尝试替换使用 sed
$sed -e 's/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/x.x.x.x/g' example.txt
Run Code Online (Sandbox Code Playgroud)
我做不到。有人可以帮我如何用特定的字符串替换IP地址吗?
当我http://192.168.150.41:8080/filereport/31779/json/在浏览器中提供URL()时,它将自动将文件下载为31779_report.json。
现在使用我正在尝试使用下载文件,curl但是出现以下错误。
$ curl -O http://192.168.150.41:8080/filereport/31779/json/
curl: Remote file name has no length!
curl: try 'curl --help' or 'curl --manual' for more information
Run Code Online (Sandbox Code Playgroud)
当使用' -L'开关时,我显示了JSON内容,但未保存文件。
$curl -L http://192.168.150.41:8080/filereport/31779/json/
{
.....
.....
}
Run Code Online (Sandbox Code Playgroud)
如何31779_report.json使用cURL / wget 下载确切的文件?
我不希望将内容>手动重定向()到文件(31779_report.json)。
有什么建议吗?
我正在尝试查询一个巨大的 mongo 集合,其中包含大约 50 + 百万条记录。在 mongo 查询中,我只需要几个字段。文档中存在的对象 ID 和 MD5。为此,我做到了
询问 :
db.getCollection('experimental_engine').find({},{"md5":1,"_id":1})
Run Code Online (Sandbox Code Playgroud)
结果 :
/* 1 */
{
"_id" : "5cee41f2ca4e0ebf567ffd1be5cdaf1f",
"md5" : "1d813cb29082b13efe572e8088f006dd"
}
/* 2 */
{
"_id" : "fcd79aac0d5c5ebdfd0fa389368ab6f3",
"md5" : "13a1a6cd5c8f1c5eaf3d409f4d809889"
}
/* 3 */
{
"_id" : "2a0b42d01892bd9b7368d045a4c7862c",
"md5" : "2a0b42d01892bd9b7368d045a4c7862c"
}
................
Run Code Online (Sandbox Code Playgroud)
现在,我想同时匹配 "_id" 和 "md5" 并且只得到匹配的值 ( _id = md5) 。
mongo 命令是否支持两个键的匹配值?
请问有什么建议吗?
我有一个 URL 列表,我正在尝试使用该列表构建防火墙日志。例子:
$ cat urls.csv
a.com
Run Code Online (Sandbox Code Playgroud)
我知道如何使用直接提到的 IP 作为变量来构建日志。
$ cat processor.sh
#!/bin/bash
filename="$1"
while read -r line
do
URLS="$line"
IP='10.109.1.1'
today_date=`date +%d/%b/%Y`
conact_1=" - - ["
concat_2=":00:00:00 +0000] "
date_concat=$conact_1$today_date$concat_2
GET='"GET '
protocol=' HTTP/1.1" 304 0 304 0 0 0 655 456 645 368 0'
final_url=$IP$conact_1$today_date$concat_2$GET$URLS$protocol
echo $final_url
done < "$filename"
Run Code Online (Sandbox Code Playgroud)
结果:
$ bash processor.sh urls.csv
10.109.1.1 - - [22/Jul/2018:00:00:00 +0000] "GET a.com HTTP/1.1" 304 0 304 0 0 0 655 456 645 368 0
Run Code Online (Sandbox Code Playgroud)
现在,如果我有一个50 or …
我正在尝试解析一个JSON有600万行的文件.哪个看起来像这样:
temp.json
{
"bbc.com": {
"Reputation": "2.1",
"Rank": "448",
"Category": [
"News"
]
},
"amazon.com": {
"Reputation": "2.1",
"Rank": "448",
"Category": [
"Shopping"
]
}
}
Run Code Online (Sandbox Code Playgroud)
我知道如何单独解析"密钥".要获得这种JSON结构的"关键" ,我试过,
jq -r 'keys[]' temp.json
Run Code Online (Sandbox Code Playgroud)
结果:
amazon.com
bbc.com
Run Code Online (Sandbox Code Playgroud)
获取上述JSON文件中的"类别".我试过了 ,
jq -r '.[].Category[]' temp.json
Run Code Online (Sandbox Code Playgroud)
结果:
Shopping
News
Run Code Online (Sandbox Code Playgroud)
如何获得"类别"只有"购物"的"键"?