Skip to content

Instantly share code, notes, and snippets.

@lixingcong
Last active October 16, 2018 07:17
Show Gist options
  • Save lixingcong/b910ab2ee6785c1ef93eab79c03baad5 to your computer and use it in GitHub Desktop.
Save lixingcong/b910ab2ee6785c1ef93eab79c03baad5 to your computer and use it in GitHub Desktop.
用于生成NekoSMS过滤规则的脚本
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Date: 2018-06-06
# NekoSMS filters print/encode
import json
# print keyword from json
def print_kw(filename):
with open(filename) as f:
data=json.load(f)
for filter in data['filters']:
print filter['body']['pattern']
# Generate json from keyword file
def generate_json_from_kw(filename_to_load, filename_to_save, version):
# Read all keywords
keyword_array=[]
with open(filename_to_load, 'r') as f:
for line in f.readlines():
line_striped=line.strip()
if len(line_striped) > 0:
keyword_array.append(line_striped)
# Add keywords to filter array
filters=[]
for keyword in keyword_array:
a_filter={'action':'block', 'body':{'mode':'contains', 'pattern':keyword, 'case_sensitive':False}}
filters.append(a_filter)
# Add version to json head
data_final={'version':version, 'filters':filters}
json_obj=json.dumps(data_final, indent=1, ensure_ascii=False)
# Write to file
with open(filename_to_save, 'wb') as f:
f.write(json_obj)
if __name__ == "__main__":
# To print
print_kw('/tmp/nekosms.nsbak')
# To generate nsbak from keyword.txt
#generate_json_from_kw('/tmp/nekosms_keywords.txt','/tmp/nekosmsNEW.nsbak','3')
百度外卖
唯品会
闲鱼
陌陌
探探
脉脉
领英
找到网
大王卡
ofo
滴滴快车
滴滴打车
滴滴出行
滴滴顺风车
京东
阿里云
美团
饿了么
手机淘宝
匹克
驴妈妈
流量包
流量日包
浦发
交通银行
华夏银行
花旗银行
中信信用卡
上海银行
民生银行
每期本金
掌上生活
额度
e招贷
中国平安
中国人寿
理财
证券
发票
建仓
操盘
大额
贷款
套现
提款
担保
风险
开户
散户
月入
月赚
增值
抢购
抽奖
领取
福利
立减
大促
促销
狂欢
爆款
户型
首付
公益
@lixingcong
Copy link
Author

帮你借

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment