恩, 很久没发python小工具了, 现在来发点=.=
串群检查 – 检查两个或多个QQ群里相同的QQ号, 输出每个QQ号在哪些群及在各群的马甲.
输入格式:
1群: 1.txt
2群: 2.txt
…
把1.txt, 2.txt, 3.txt等文件和下面的py脚本放一个目录里, 然后运行py脚本即可~
下面就是代码啦~
v0.2 – 2011/01/18
重写了算法, 速度更快
增加了全部群友信息输出, 方便管理员查找
感谢牛B轰轰的吉米大大贡献代码!
#coding:utf-8
#!/usr/bin/env python
# QQ 串群检查 - By Felix Yan GPL v3
# felixonmars@gmail.com
# http://blog.felixc.at
import sys
chuanqun = []
ren = []
for i in range(1,100):
try:
f = open("%d.txt" % (i), "r")
for line in f:
try:
tmp = line.decode(sys.getfilesystemencoding()).strip().split()
qq = tmp[-1]
nick = tmp[0]
ren.append([qq, [str(i), nick]])
except:
pass
except IOError:
pass
#下面这段精妙的代码是吉米大大的!!!!!!!!!
d = {}
l = []
for i, j in ren:
try:
d[i] += [j]
except KeyError:
d[i] = [j]
for i in d.keys():
l += [[i] + d[i]]
l.sort(key=lambda x:int(x[0]))
ren = l
for i in ren:
if len(i[1:]) > 1:
chuanqun.append(i)
chuanqun.sort(key=lambda x:len(x[1:]), reverse=True)
resultchuan = []
for i in chuanqun:
resultchuan.append(u"%s 串群 %s" % (i[0], ", ".join([u"%s群(%s)" % (x[0], x[1]) for x in i[1:]])))
f = open(u"串群检查结果.txt".encode(sys.getfilesystemencoding()), "w")
f.write("\n".join(resultchuan).encode(sys.getfilesystemencoding()))
f.close()
resultall = []
for i in ren:
resultall.append(u"%s 在 %s" % (i[0], ", ".join([u"%s群(%s)" % (x[0], x[1]) for x in i[1:]])))
f = open(u"全部群员信息.txt".encode(sys.getfilesystemencoding()), "w")
f.write("\n".join(resultall).encode(sys.getfilesystemencoding()))
f.close()
Continue reading QQ群管理员小工具 – 串群检查(Python)