This commit is contained in:
机器人总动员 2021-05-05 10:59:30 +08:00
commit 14e8e7f627
9 changed files with 192 additions and 0 deletions

1
config.py Normal file
View File

@ -0,0 +1 @@
TOKEN = "1749418611:AAGOV2XB5mkMXqX-J_wtNu7KkrkhO_Xylmg"

31
main.py Normal file
View File

@ -0,0 +1,31 @@
from telegram.ext import Updater
from config import TOKEN
from telegram import InlineKeyboardMarkup, InlineKeyboardButton, ForceReply
from telegram.ext import CommandHandler, MessageHandler, Filters, ConversationHandler, CallbackQueryHandler
import sqlite3
from func import start, reserve, run, kill, status, update, get
updater = Updater(token=TOKEN, use_context=True)
dispatcher = updater.dispatcher
start_handler = CommandHandler('start', start)
reserve_handler = CommandHandler('reserve', reserve)
run_handler = CommandHandler('run', run)
kill_handler = CommandHandler('kill', kill)
update_handler = CommandHandler('update', update)
status_handler = CommandHandler('status', status)
get_handler = CommandHandler('get', get)
dispatcher.add_handler(start_handler)
dispatcher.add_handler(reserve_handler)
dispatcher.add_handler(run_handler)
dispatcher.add_handler(kill_handler)
dispatcher.add_handler(update_handler)
dispatcher.add_handler(status_handler)
dispatcher.add_handler(get_handler)
updater.start_polling()
updater.idle()

22
requirements.txt Normal file
View File

@ -0,0 +1,22 @@
bcrypt==3.2.0
beautifulsoup4==4.9.3
bs4==0.0.1
certifi==2020.4.5.2
cffi==1.14.0
chardet==3.0.4
cryptography==2.9.2
decorator==4.4.2
future==0.18.2
idna==2.9
paramiko==2.7.2
pycparser==2.20
pycryptodomex==3.9.4
PyNaCl==1.4.0
pyOpenSSL==19.1.0
python-alipay-sdk==2.0.1
python-telegram-bot==12.7
requests==2.23.0
six==1.15.0
soupsieve==2.1
tornado==6.0.4
urllib3==1.25.9

Binary file not shown.

21
test/connector.py Normal file
View File

@ -0,0 +1,21 @@
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)

47
test/jieba-test.py Normal file
View File

@ -0,0 +1,47 @@
# 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)

10
test/redishset.py Normal file
View File

@ -0,0 +1,10 @@
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"))

56
test/rediswr.py Normal file
View File

@ -0,0 +1,56 @@
import redis
# encoding=utf-8
import jieba
import wordcloud
import jieba.posseg as pseg
# 导入imageio库中的imread函数并用这个函数读取本地图片作为词云形状图片
import imageio
import time # 引入time模块
pool = redis.ConnectionPool(host='127.0.0.1', port=6379, encoding='utf8', decode_responses=True, db=0)
start_time = float(time.time())
r = redis.StrictRedis(connection_pool=pool)
with open("/root/Jupyter/143751443703354.txt", "r") as file:
i = 0
for line in file.readlines():
i += 1
r.append("maozedong", line)
if i == 10:
break
# content = file.read()
# print(content)
print(r.get("maozedong"))
mk = imageio.imread("/root/Jupyter/circle.png")
w = wordcloud.WordCloud(mask=mk)
# 构建并配置词云对象w注意要加scale参数提高清晰度
w = wordcloud.WordCloud(width=800,
height=800,
background_color='white',
font_path='/root/Jupyter/hanyiqihei.ttf',
mask=mk,
scale=5)
# 对来自外部文件的文本进行中文分词得到string
jieba.enable_paddle() # 启动paddle模式。 0.40版之后开始支持,早期版本不支持
words = pseg.cut(r.get("maozedong"), 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)
string = " ".join(word_list)
# 将string变量传入w的generate()方法,给词云输入文字
w.generate(string)
# 将词云图片导出到当前文件夹
w.to_file('maozedong-3.png')
stop_time = float(time.time())
print(stop_time - start_time)

4
test/timemap.py Normal file
View File

@ -0,0 +1,4 @@
import time # 引入time模块
start_time = int(time.time())
print("当前时间戳为:", int(ticks))