-
Notifications
You must be signed in to change notification settings - Fork 4
/
apkpure_download.py
36 lines (36 loc) · 2.74 KB
/
apkpure_download.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: utf-8 -*-
from pymongo import MongoClient
import bson
import re
if __name__ == '__main__':
collection = MongoClient('mongodb://localhost:27017/')['scrapy']['Third_Party_apps']
regax = bson.Regex.from_native(re.compile('^Apkpure_.*'))
wandoujia_list = collection.find({'ID':regax},{'ID':1,'Version':1,'file_urls':1,'file_type':1})
with open("Apkpure_medical_download.sh",'w') as f:
f.write('#!/bin/bash\n')
for item in wandoujia_list:
index = 0
if isinstance(item['file_urls'],list):
for url in item['file_urls']:
try:
command = 'wget "'+url+'" -O '+ item['ID']+"_"+item['Version'][index].replace('(','%28').replace(')','%29')+item['file_type'][index]+"\n"
error = 'if [ $? -ne 0 ]\nthen\necho "' + item['ID'] + " " + item['Version'][index] + '" >> errors.log\nfi\n'
# error = 'if [ $? -ne 0 ]\nthen\necho wget "\\"'+url+'" -O '+ item['ID']+"_"+item['Version'][index].replace('(','%28').replace(')','%29')+item['file_type'][index]+' >> errors.log\nfi\n'
except:
command = 'wget "'+url+'" -O '+ item['ID']+"_"+item['Version'][index].replace('(','%28').replace(')','%29')+".apk\n"
# error = 'if [ $? -ne 0 ]\nthen\necho wget "\\"'+url+'" -O '+ item['ID']+"_"+item['Version'][index].replace('(','%28').replace(')','%29')+'.apk'+' >> errors.log\nfi\n'
error = 'if [ $? -ne 0 ]\nthen\necho "' + item['ID'] + " " + item['Version'][index] + '" >> errors.log\nfi\n'
f.write(command+error+'sleep 2\n')
index=index+1
elif isinstance(item['file_urls'],str):
try:
command = 'wget "' + url + '" -O ' + item['ID'] + "_" + item['Version'].replace('(','%28').replace(')','%29') +item['file_type']+ "\n"
# error = 'if [ $? -ne 0 ]\nthen\necho wget "\\"'+url+'" -O '+ item['ID']+"_"+item['Version'].replace('(','%28').replace(')','%29')+item['file_type']+' >> errors.log\nfi\n'
error = 'if [ $? -ne 0 ]\nthen\necho "'+item['ID']+" "+item['Version'] + '" >> errors.log\nfi\n'
except:
command = 'wget "' + url + '" -O ' + item['ID'] + "_" + item['Version'].replace('(','%28').replace(')','%29') + ".apk\n"
# error = 'if [ $? -ne 0 ]\nthen\necho wget "\\"'+url+'" -O '+ item['ID']+"_"+item['Version'].replace('(','%28').replace(')','%29')+'.apk'+' >> errors.log\nfi\n'
error = 'if [ $? -ne 0 ]\nthen\necho "'+item['ID']+" "+item['Version'] + '" >> errors.log\nfi\n'
f.write(command+error+'sleep 2\n')
else:
pass