diff --git a/circle.png b/circle.png new file mode 100644 index 0000000..f62fc2b Binary files /dev/null and b/circle.png differ diff --git a/font.ttf b/font.ttf new file mode 100644 index 0000000..423a8b1 Binary files /dev/null and b/font.ttf differ diff --git a/func.py b/func.py index 3221ce6..260c370 100644 --- a/func.py +++ b/func.py @@ -1,7 +1,10 @@ +import time + import connector import telegram from telegram.ext import CommandHandler, MessageHandler, Filters, ConversationHandler, CallbackQueryHandler from config import TOKEN +import schedule bot = telegram.Bot(token=TOKEN) @@ -40,5 +43,11 @@ def chat_content_exec(update, context): print("---------------------------") +def check_schedule(): + while True: + schedule.run_pending() + time.sleep(1) + + start_handler = CommandHandler('start', start) chat_content_handler = MessageHandler(Filters.text, chat_content_exec) diff --git a/main.py b/main.py index e5f2861..55f635d 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,14 @@ from telegram.ext import Updater from config import TOKEN -from func import start_handler, chat_content_handler +from func import start_handler, chat_content_handler, check_schedule +import schedule +import task +import threading + +# schedule.every().day.at('16:20').do(task).tag('task') +schedule.every(1).minutes.do(task).tag('task') + +threading.Thread(target=check_schedule).start() updater = Updater(token=TOKEN, use_context=True) dispatcher = updater.dispatcher diff --git a/task.py b/task.py index 8d63ca9..9e18481 100644 --- a/task.py +++ b/task.py @@ -1,5 +1,4 @@ import re -import redis import jieba import jieba.posseg as pseg import wordcloud @@ -21,12 +20,12 @@ for i in key_list: group_list.append(i[:i.find("_")]) # print(group_list) -mk = imageio.imread("/root/Jupyter/circle.png") +mk = imageio.imread("/root/word_cloud_bot/circle.png") # 构建并配置词云对象w,注意要加scale参数,提高清晰度 w = wordcloud.WordCloud(width=800, height=800, background_color='white', - font_path='/root/Jupyter/hanyiqihei.ttf', + font_path='/root/word_cloud_bot/font.ttf', mask=mk, scale=5) @@ -127,3 +126,5 @@ for group in group_list: except Exception as e: print(e) continue +r.flushall() +print("已清空数据库") diff --git a/test/connector.py b/test/connector.py deleted file mode 100644 index 7d49ae1..0000000 --- a/test/connector.py +++ /dev/null @@ -1,21 +0,0 @@ -import redis - -# 连接 redis -# 指定主机地址,port与服务器连接,redis默认数据库有16个,默认db是0 -# r = redis.Redis(host='127.0.0.1', port=6379, encoding='utf8', decode_responses=True) # password='**' -# print(r.get('foo')) -# r.set('foo', '[1,2,3]') -# print(r.get('foo')) -# print(r.keys()) -# r.delete('foo') -# print(r.keys()) - -pool = redis.ConnectionPool(host='127.0.0.1', port=6379, encoding='utf8', decode_responses=True) - - -# r = redis.Redis(connection_pool=pool) -# r.set('foo', 'Bar') -# print(r.get('foo')) - -def get_connection(): - return redis.StrictRedis(connection_pool=pool) diff --git a/test/jieba-test.py b/test/jieba-test.py deleted file mode 100644 index 240186a..0000000 --- a/test/jieba-test.py +++ /dev/null @@ -1,47 +0,0 @@ -# encoding=utf-8 -import jieba -import jieba.posseg as pseg -import time # 引入time模块 - -import redis - -import connector -test_word = ''' -📜 ZUOLUOTV 例行群规广播 📜 -📅 2021年5月5日 -⏱ 截至今天08:00 本群共有11374位群友 -———————————— -⚖️ 自由并不意味着没有规则,群内稳定和持续的交流氛围,依靠的是大家对规则的尊重。 -———————————— -📖 ZUOLUOTV群管理规范 📖 -🈯 本群提倡一切事务合法合规操作 -🔞 不允许传播违法、黑灰产相关内容 - -1.必Ban:传播黑灰产,贩卖手机卡、银行卡、个人信息。 -2.必Ban:传播色情、暴力、低俗内容。 -3.必Ban:群发广告,ID或头像中带广告。 -4.别聊政治敏感话题,不鼓励聊翻墙、机场等话题,原因请看WHY。 -5.别搞人身攻击,别搞地域黑,别发布仇恨言论,别骚扰异性。 -6.别做伸手党,先看资料索引,学会谷歌搜索、善看群聊记录。 -7.不要用语音,不要连续刷屏,恶意刷屏将被Ban。 -8.鼓励原创分享,分享外链尽量是科技、数码、摄影、旅行主题。 -9.违反群规者,飞机场见✈,异议可私信管理员,精力时间有限,私聊不解答公开问题。 - -''' - -start_time = float(time.time()) -# words = pseg.cut("我爱北京天安门") # jieba默认模式 -jieba.enable_paddle() # 启动paddle模式。 0.40版之后开始支持,早期版本不支持 -words = pseg.cut(test_word, use_paddle=True) # paddle模式 -word_list = [] -for word, flag in words: - # print(word + "\t" + flag) - if flag in ["n", "nr", "nz", "PER", "f", "ns", "LOC", "s", "nt", "ORG", "nw"]: - word_list.append(word) - r = connector.get_connection() - r.set('foo', 'Bar') - print(r.get('foo')) -print(word_list) -stop_time = float(time.time()) -print(stop_time - start_time) - diff --git a/test/redishset.py b/test/redishset.py deleted file mode 100644 index 27b2493..0000000 --- a/test/redishset.py +++ /dev/null @@ -1,12 +0,0 @@ -import redis -pool = redis.ConnectionPool(host='127.0.0.1', port=6379, encoding='utf8', decode_responses=True, db=0) - -r = redis.StrictRedis(connection_pool=pool) - -# r.hset("user", "a", 1) -# r.hincrby('user', "a") -# r.hincrby('user', "b") -print(r.hget("user", "a")) -print(r.hget("user", "b")) -r.delete() - diff --git a/test/test1.py b/test/test1.py deleted file mode 100644 index 4e9337e..0000000 --- a/test/test1.py +++ /dev/null @@ -1,33 +0,0 @@ -group_name = '-1001403536948_chat_content' - -print(group_name[:group_name.find("_")]) - -word_amount = {} - -word_amount['y1111'] = 1 -word_amount['y2222'] = 2 -word_amount['y3333'] = 4 -word_amount['y4444'] = 3 - -print(word_amount.get("123")) -print(word_amount.get("y4444")) - -print(word_amount) -word_amount = sorted(word_amount.items(), key=lambda word: (word[1])) -print(word_amount) - -print("--------------") -import re - -str = ''' - 23 -''' - -rst = re.match(r"^\s+?$", str) - -print(rst) - -import time - -print(time.strftime("%Y年%m月%d日", time.localtime())) -print(time.strftime("%H:%M", time.localtime())) diff --git a/test/timemap.py b/test/timemap.py deleted file mode 100644 index 1b95fee..0000000 --- a/test/timemap.py +++ /dev/null @@ -1,4 +0,0 @@ -import time # 引入time模块 - -start_time = int(time.time()) -print("当前时间戳为:", int(ticks))