Skip to content

Commit

Permalink
bump to v0.1.18, support goodgoodgenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesPikachu committed Apr 25, 2022
1 parent 9b861e3 commit 695af6b
Show file tree
Hide file tree
Showing 10 changed files with 338 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ You can star this repository to keep track of the project if it's helpful for yo
| arxivhelper | [click](https://mp.weixin.qq.com/s/XypPxlWmzbRoEEEhusEXJA) | [click](./pytools/modules/arxivhelper) | Arxiv小助手 |
| ukrainemap | [click](https://mp.weixin.qq.com/s/zthIMtWqF7mJiIlXy1-bsA) | [click](./pytools/modules/ukrainemap) | 乌克兰地图查询系统 |
| sovietgenerator | [click](https://mp.weixin.qq.com/s/PUTJxDLpCVRSaUzvarizEQ) | [click](./pytools/modules/sovietgenerator) | 苏联笑话生成器 |
| goodgoodgenerator | [click]() | [click](./pytools/modules/goodgoodgenerator) | 稳中向好生成器 |


# Install
Expand Down
7 changes: 6 additions & 1 deletion docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,9 @@
**2022-04-20**

- 版本号: v0.1.17,
- 更新内容: 支持苏联笑话生成器。
- 更新内容: 支持苏联笑话生成器。

**2022-04-25**

- 版本号: v0.1.18,
- 更新内容: 支持稳中向好生成器。
27 changes: 27 additions & 0 deletions docs/Quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,33 @@ tool_client.execute('sovietgenerator')
}
```

#### 稳中向好生成器

**1.公众号文章链接**

[点击查看]()

**2.功能介绍**

简单的稳中向好生成器。

**3.调用示例代码**

```python
from pytools import pytools

tool_client = pytools.pytools()
tool_client.execute('goodgoodgenerator')
```

**4.config中支持的参数**

```
{
title: 软件显示的标题, 默认值"稳中向好生成器 —— Charles的皮卡丘",
}
```


## 随机运行一个小程序

Expand Down
2 changes: 1 addition & 1 deletion pytools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'''url'''
__url__ = 'https://github.com/CharlesPikachu/pytools'
'''version'''
__version__ = '0.1.17'
__version__ = '0.1.18'
'''author'''
__author__ = 'Charles'
'''email'''
Expand Down
1 change: 1 addition & 0 deletions pytools/modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from .artsigngenerator import ArtSignGenerator
from .controlpcbyemail import ControlPCbyEmail
from .naughtyconfession import NaughtyConfession
from .goodgoodgenerator import GoodGoodGenerator
from .luxunsentencesquery import LuxunSentencesQuery
from .hubbleseeonbirthday import HubbleSeeOnBirthday
from .newyearcardgenerator import NewYearCardGenerator
Expand Down
2 changes: 2 additions & 0 deletions pytools/modules/goodgoodgenerator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
'''初始化'''
from .goodgoodgenerator import GoodGoodGenerator
143 changes: 143 additions & 0 deletions pytools/modules/goodgoodgenerator/goodgoodgenerator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
'''
Function:
稳中向好生成器
Author:
Charles
微信公众号:
Charle的皮卡丘
'''
import os
import json
import random
import pyttsx3
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5 import QtWidgets, QtGui


'''稳中向好生成器'''
class GoodGoodGenerator(QWidget):
tool_name = '稳中向好生成器'
def __init__(self, parent=None, title='稳中向好生成器 —— Charles的皮卡丘', **kwargs):
super(GoodGoodGenerator, self).__init__(parent)
rootdir = os.path.split(os.path.abspath(__file__))[0]
self.setFixedSize(800, 500)
self.setWindowTitle(title)
self.setWindowIcon(QIcon(os.path.join(rootdir, 'resources/icon.jpg')))
self.resources = json.load(open(os.path.join(rootdir, 'resources/data.json'), 'r', encoding='utf-8'))
self.article = None
# 定义一些必要的组件
grid = QGridLayout()
# --标签
label_1 = QLabel('稳中向好的事件主题:')
label_2 = QLabel('生成的文章字数:')
# --输入框
self.edit_1 = QLineEdit()
self.edit_1.setText('年轻人买房')
self.edit_2 = QLineEdit()
self.edit_2.setText('500')
# --生成按钮
button_generate = QPushButton('生成稳中向好文章')
# --朗读按钮
button_deacon = QPushButton('朗读生成的文章')
# --结果显示框
self.text_edit = QTextEdit()
# 组件布局
grid.addWidget(label_1, 0, 0, 1, 1)
grid.addWidget(self.edit_1, 0, 1, 1, 1)
grid.addWidget(label_2, 1, 0, 1, 1)
grid.addWidget(self.edit_2, 1, 1, 1, 1)
grid.addWidget(button_generate, 2, 0, 1, 2)
grid.addWidget(button_deacon, 3, 0, 1, 2)
grid.addWidget(self.text_edit, 4, 0, 5, 2)
self.setLayout(grid)
# 事件绑定
button_generate.clicked.connect(self.generate)
button_deacon.clicked.connect(self.deacon)
'''朗诵稳中向好文章'''
def deacon(self):
pyttsx3.speak(self.article)
'''生成稳中向好文章'''
def generate(self):
# 分配开头, 结尾和主体内容的字数
num_words = int(self.edit_2.text())
begin_num_words, body_num_words, end_num_words = num_words * 0.15, num_words * 0.7, num_words * 0.15
# 主题
theme = self.edit_1.text()
# 生成标题
title = self.generatetitle(theme)
# 生成文章开头
begin = self.generatebegin(begin_num_words, theme)
# 生成文章主体
body = self.generatebody(body_num_words, theme)
# 生成文章结尾
end = self.generateend(end_num_words, theme)
# 整合文章
self.article = f'{title}\n {begin}\n {body}\n {end}'
# 显示文章
self.text_edit.setText(self.article)
'''替换原始内容中的占位符'''
def replace(self, input_str, theme):
# vn
while input_str.find('vn') != -1:
total = len(self.resources['verb']) - 1
verb = self.resources['verb'][random.randint(0, total)]
total = len(self.resources['noun']) - 1
noun = self.resources['noun'][random.randint(0, total)]
vn = ','.join([verb + noun for i in range(random.randint(1, 4))])
input_str = input_str.replace('vn', vn, 1)
# v
while input_str.find('v') != -1:
total = len(self.resources['verb']) - 1
verb = self.resources['verb'][random.randint(0, total)]
input_str = input_str.replace('v', verb, 1)
# n
while input_str.find('n') != -1:
total = len(self.resources['noun']) - 1
noun = self.resources['noun'][random.randint(0, total)]
input_str = input_str.replace('n', noun, 1)
# ss
while input_str.find('ss') != -1:
total = len(self.resources['sentence']) - 1
sentence = self.resources['sentence'][random.randint(0, total)]
input_str = input_str.replace('ss', sentence, 1)
# sp
while input_str.find('sp') != -1:
total = len(self.resources['parallel_sentence']) - 1
parallel_sentence = self.resources['parallel_sentence'][random.randint(0, total)]
input_str = input_str.replace('sp', parallel_sentence, 1)
# p
while input_str.find('p') != -1:
total = len(self.resources['phrase']) - 1
phrase = self.resources['phrase'][random.randint(0, total)]
input_str = input_str.replace('p', phrase, 1)
# xx
input_str = input_str.replace('xx', theme)
# return
return input_str
'''生成文章标题'''
def generatetitle(self, theme):
total = len(self.resources['title']) - 1
title = self.resources['title'][random.randint(0, total)]
return self.replace(title, theme)
'''生成文章开头'''
def generatebegin(self, begin_num_words, theme):
begin = ''
while len(begin) < begin_num_words:
total = len(self.resources['beginning']) - 1
begin += self.replace(self.resources['beginning'][random.randint(0, total)], theme)
return begin
'''生成文章结尾'''
def generateend(self, end_num_words, theme):
end = ''
while len(end) < end_num_words:
total = len(self.resources['ending']) - 1
end += self.replace(self.resources['ending'][random.randint(0, total)], theme)
return end
'''生成文章主体'''
def generatebody(self, body_num_words, theme):
body = ''
while len(body) < body_num_words:
total = len(self.resources['body']) - 1
body += self.replace(self.resources['body'][random.randint(0, total)], theme)
return body
Loading

0 comments on commit 695af6b

Please sign in to comment.