您当前的位置:首页 > 计算机 > 编程开发 > Python

Python QQ群管理员小工具 – 串群检查

时间:11-14来源:作者:点击数:

串群检查 – 检查两个或多个QQ群里相同的QQ号, 输出每个QQ号在哪些群及在各群的马甲.

输入格式:

1群: 1.txt

2群: 2.txt

把1.txt, 2.txt, 3.txt等文件和下面的py脚本放一个目录里, 然后运行py脚本即可~

下面就是代码啦~

重写了算法, 速度更快

增加了全部群友信息输出, 方便管理员查找

感谢牛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()

第一个版本=.=

#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(100)]
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[i].append([qq, nick])
            except:
                pass
    except IOError:
        pass

for qun in enumerate(ren):
    for qq in qun[1]:
        newset = False
        for qun2 in enumerate(ren[qun[0] + 1:]):
            if qun2[0] != qun[0]:
                for qq2 in qun2[1]:
                    if qq[0] == qq2[0]:
                        flag = False
                        for item in chuanqun:
                            if item[0] == qq[0]:
                                flag = True
                                if newset:
                                    item.append(u"%d群(%s)" % (qun[0] + qun2[0] + 1, qq2[1]))
                        if not flag:
                            newset = True
                            chuanqun.append([qq[0], u"%d群(%s)" % (qun[0], qq[1]), u"%d群(%s)" % (qun[0] + qun2[0] + 1, qq2[1])])
chuanqun.sort(key=lambda x:len(x[1:]),reverse=True)

result = []
for i in chuanqun:
    result.append(u"%s 串群 %s" % (i[0], ", ".join(i[1:])))
    
f = open(u"串群检查结果.txt".encode(sys.getfilesystemencoding()), "w")
f.write("\n".join(result).encode(sys.getfilesystemencoding()))
f.close()
方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门