强大的脚本

篇幅有限

完整内容及源码关注公众号:ReverseCode,发送

Python

合并多dex

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import os, sys

# python3.7 merge_dex.py ./file/ livedex 反编译成java文件


if __name__ == "__main__":
if len(sys.argv) < 3 :
print("start error")
sys.exit()

print(sys.argv[1], sys.argv[2])

path = sys.argv[1] #文件夹目录
files= os.listdir(path) #得到文件夹下的所有文件名称
s = []
for file in files: #遍历文件夹
if file.find("dex") > 0: ## 查找dex 文件
sh = 'jadx -j 1 -r -d ' + sys.argv[2] + " " + path + file
print(sh)
os.system(sh)

集合

排列组合

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
productType = [1, 2, 3]
goodType = [4, 5]
energyType = [6, 7]
productGoodEnergyType = [[1,2,3],[4,5],[6, 7]]
# 多个集合随机有序排列,同itertools.product(*productGoodEnergyType)
for newValue in itertools.product(productType,goodType,energyType):
print(newValue)

# 按组合个数进行无序组合
print(list(itertools.permutations(productType)))

for productTypeIndex in range(1, len(productType) + 1):
# 单个集合按指定个数随机有序排列
productTypeTter1 = itertools.combinations(productType, productTypeIndex)
print(list(productTypeTter1))

# 单个集合按指定个数随机无序组合
productTypeTter2 = itertools.permutations(productType, productTypeIndex)
print(list(productTypeTter2))

多集合组合

  1. 拿到集合的组合
  2. 根据这些组合进行分组笛卡尔积
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
def combine(big_dict):
# Cn1+Cn2+...+Cnn
# Cmn=m!/n!*(m-n)!
keys = list(big_dict.keys()) # 获取keyList
combine_key_list = [] # key值 排列组合
valueList = [] # 将key替换为值
for i in range(1, len(keys) + 1):
iter = itertools.combinations(keys, i)
# [('a',), ('b',), ('c',), ('a', 'b'), ('a', 'c'), ('b', 'c'), ('a', 'b', 'c')]
combine_key_list.extend(list(iter)) # key的所有组合 以list形式加入列表

for m in combine_key_list:
# [[[1, 2, 3]], [[4, 5]], [[6, 7, 8, 9]], [[1, 2, 3], [4, 5]], [[1, 2, 3], [6, 7, 8, 9]], [[4, 5], [6, 7, 8, 9]], [[1, 2, 3], [4, 5], [6, 7, 8, 9]]]
valueList.append([big_dict.get(n) for n in m if n in keys]) # key所有组合转value组合 以object形式加入列表

param_list = []
for index, value in enumerate(valueList): # list转为索引序列
search_type_key = list(combine_key_list[index]) # 根据当前值对应key
for item in itertools.product(*value): # 集合中n个集合n组笛卡尔积
params = dict(zip(search_type_key, list(item)))
param_list.append(urlencode(params))
print(param_list)

d = {
'a': [1,2,3],
'b': [4,5],
'c': [6,7,8,9],
}
combine(d)

格式转换

转str

1
2
3
4
t = (1,2)
l = [3,4]
print(','.join(map(str, t)) if isinstance(t,tuple) else t)
print(','.join(map(str, l)) if isinstance(l,list) else l)

转dict

1
print(dict(zip(productType,goodType)))

转list

1
2
def flatten(li):
return sum(([x] if not isinstance(x, list) else flatten(x) for x in li), [])

字典key替换

1
param_dict['area'] = param_dict.pop('ownerProvince')+'-'+param_dict.pop('ownerCity')

Mongo

1
2
3
4
5
6
import pymongo
client = pymongo.MongoClient(settings.get('MONGO_URI'))[settings.get('MONGO_DB')]
client['MUsedCar'].create_index([("url", 1)], unique=True)
client['MUsedCar'].insert(dict({'url':used_car_url+urlencode(param_dict)}))
for doc in client['MUsedCarParams'].find():
print(doc['params'])

爬虫

url

1
2
param_dict = dict(parse.parse_qsl(parse.unquote(doc['params'])))  url解码并转为字典
urlencode(param_dict) 字典转url编码

Java

idea生成注释文档

File => setting => editor => File and Code Templates

1
2
3
4
5
"""
@author: onejane
@time: ${DATE} ${TIME}
@desc:
"""

File => Setting=> Editor=> Live Templates

live template

输入onejane代码提示直接回车即可

Tools-Generate JavaDoc

idea生成注释文档

1
2
zh_CN
-tag ProjectDetails:a:"项目详情:" -tag update:a:"项目更改:" -tag CreateDate:a:"创建时间:" -encoding UTF-8 -charset UTF-8

javaDoc

lambda

多个分组多列求和

1
2
3
4
5
6
7
Function<MotoEssayShowDailyContextInfoDTO, List<Object>> keyExtractor = wr -> Arrays.<Object>asList(wr.getBusinessDate(), wr.getContext());
List<MotoEssayShowDailyContextInfoDTO> showDailyContextInfoDTOS = infoByCondition.stream().collect(Collectors.groupingBy(keyExtractor,
Collectors.reducing((sum, s) ->
new MotoEssayShowDailyContextInfoDTO(s.getBusinessDate(), s.getContext(), sum.getExposureArticleNum() + s.getExposureArticleNum(),
sum.getExposureNum() + s.getExposureNum(), sum.getClickNum() + s.getClickNum(),
sum.getDetailClickNum() + s.getDetailClickNum(), sum.getDuration() + s.getDuration(), sum.getFinish() + s.getFinish()))
)).entrySet().stream().map(c -> c.getValue().get()).collect(Collectors.toList());

分组排序

1
showDailyContextInfoDTOS.stream().collect(Collectors.groupingBy(o -> o.getBusinessDate(), TreeMap::new,Collectors.toList()));

Git

多仓库

1
2
git remote set-url --add origin git@github.com:OneJane/CrawlerBase.git
git push origin --all

git remote add origin git@gitee.com:OneJane/picture.git 初始化后建立git库

版本回退

1
2
git reflog
git reset --hard 版本号

大仓库提交

1
git config http.postBuffer 524288000

不行就使用git替代https地址

合并不同提交历史

1
git pull origin master --allow-unrelated-histories

恢复被删分支

1
2
git reflog
git branch f/wj-0419-5924 bcd2e64

Mongo

更新

批量将字段更新成字符串

1
2
3
4
db.getCollection('alimama').find({}).forEach(function(x){
db.getCollection('alimama').updateOne(
{_id: x._id}, {$set:{income_rate: String(x.income_rate)}}
)})

批量新增字段

1
db.getCollection('taobao').update({}, {$set: {'name':"taobao"}}, {multi: true});

批量修改字段名

1
db.getCollection('long_link').update({}, {"$rename":{"long_link":"orientPlanLinkUrl"}}, false, true)

查询

返回指定字段id

1
db.getCollection('alimama').find({},{_id:0,id:1})

按照url分组查询并倒序

1
db.getCollection('conditions').aggregate([{$group : {_id : "$url", num_tutorial : {$sum : 1}}},{ $sort : {  num_tutorial: -1 } }])

模糊查询

1
db.getCollection('conditions').find({'url':{'$regex':'https:*'}}).count()

导出

sublime 中ctrl+h 进行 {“_id”:.:”(.)”}\n 替换为 $1\n

1
mongoexport -h 172.20.0.186:27017 -d jddmoto -c mbrand -o mbrand.json --type json -f url

Mysql

locate

1
SELECT GROUP_CONCAT(a.n_id), COUNT(a.`n_id`) FROM `motor_business_essay` a, `motor_business_essay_ext` b where  locate('"img":""',a.c_short_vod_info)

Linux

删除大文件

1
2
3
4
du -h --max-depth=1
df -h
lsof | grep deleted 查询内存中持续删除的进程
kill -9 id

windows

新增复制文件路径.reg

UTF-8-BOM编码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\copypath]
@="复制文件路径到剪贴板"
[HKEY_CLASSES_ROOT\*\shell\copypath\command]
@="cmd /c echo %1 | clip"

[HKEY_CLASSES_ROOT\*\shell\copypathwithquote]
@="复制文件路径到剪贴板(带引号)"
[HKEY_CLASSES_ROOT\*\shell\copypathwithquote\command]
@="cmd /c echo \"%1\" | clip"

[HKEY_CLASSES_ROOT\Directory\shell\copypath]
@="复制文件夹路径到剪贴板"
[HKEY_CLASSES_ROOT\Directory\shell\copypath\command]
@="cmd /c echo %1 | clip"
[HKEY_CLASSES_ROOT\Directory\shell\copypathwithquote]
@="复制文件夹路径到剪贴板(带引号)"
[HKEY_CLASSES_ROOT\Directory\shell\copypathwithquote\command]
@="cmd /c echo \"%1\" | clip"
文章作者: J
文章链接: http://onejane.github.io/2021/02/22/强大的脚本/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 万物皆可逆向
支付宝打赏
微信打赏