更新了视图行为,switch语句

master
wkyuu 3 years ago
parent 372b3db354
commit 030474ebd1

@ -11,7 +11,7 @@ selenium + redis + 分布式 + xpath + etree + 可视化
- [ ] 同时/后期追加 存入csv 价格趋势,涨跌幅。比对,给出价格波动趋势
- [x] 加入Redis分布式设计
- [ ] 数据可视化
- [ ] 预计两种模式终端交互随机或取评价数为索引目标给出取出的item的具体信息例如价格预测
- [ ] 预计两种模式终端交互随机或取评价数为索引目标给出取出的item的具体信息例如价格趋势
- [ ] 选择目录,友好的选择交互体验
- [ ] 选择抽取item模式热评就列出前五条随机就随机取一条
- [ ] python打包exe需要图形化界面
@ -183,6 +183,40 @@ ChromeDriver
### Matplotlib
[python数据可视化MatLab开源替代方案](https://www.runoob.com/numpy/numpy-matplotlib.html)
用pip管理器安装`pip install matplotlib`
```python
# 使用方法
import numpy as np
from matplotlib import pyplot as plt
x = np.arange(1,11)
y = 2 * x + 5
plt.title("Matplotlib demo")
plt.xlabel("x axis caption")
plt.ylabel("y axis caption")
plt.plot(x,y)
plt.show()
```
切换字体
```python
from matplotlib import pyplot as plt
import matplotlib
def getFont(): # 列出可用的字体
font = sorted([f.name for f in matplotlib.font_manager.fontManager.ttflist])
for i in font:
print(i)
# getFont()
plt.rcParams['font.family'] = ['Microsoft YaHei']
```
### Requests
经典老碟
@ -192,6 +226,15 @@ import requests
```
### 正则表达式
```python
# 完全匹配浮点数
reg = [-+]?[0-9]*\.?[0-9]*
```
### 线程
多线程,手动版
@ -272,8 +315,6 @@ with ThreadPoolExecutor(max_workers = 10) as thread:
print(task.result()) # 返回上面 printTime 函数的返回值
```
### Redis
```python
@ -342,4 +383,6 @@ redisconn = redis.Redis(host = '127.0.0.1', port = '6379', password = 'x', db =
18[python线程池](https://www.cnblogs.com/liyuanhong/p/15767817.html)
19
19[python matplotlib坐标轴设置的方法](https://www.csdn.net/tags/NtzaUgxsOTQ2NjgtYmxvZwO0O0OO0O0O.html)
20

@ -2,13 +2,58 @@
import middlewares
import time
import settings
def showBanner(menu = 'main'):
print(settings.BANNER.get(menu), end='')
def switch(menu = '1'):
case = {
'1' : main,
'2' : introduce,
'3' : view,
'4' : middlewares.save2Redis,
'5' : middlewares.clearRedis,
'6' : milkSpider,
'7' : aexit
}
if menu in case.keys():
case.get(menu)()
else:
print("no such choice", end = '')
return
def main():
while True:
showBanner()
menu = str(input("选择一项:"))
switch(menu)
def introduce():
print(settings.BANNER.get('introduce'), end = '')
while True:
select = str(input())
if select == "r":
return
else:
print("invaild choice!")
def view():
print("this is view()")
return
def milkSpider():
if middlewares.precheck():
start_time = time.time()
middlewares.mainThread()
print("Totally spend " + str(round(time.time() - start_time, 2)) + " secends")
print("Totally spend " + str(round(time.time() - start_time, 2)) + " seconds")
print("milkSpider done.")
def aexit():
print("bye!")
exit()
if __name__ == "__main__":
milkSpider()
# milkSpider()
main()

@ -43,4 +43,36 @@ USER_AGENT = [
COOKIES_FILENAME = "cookies.json"
# 历史价格查询网站 vveby.com
HISTORY_PRICE_URL = r"https://www.vveby.com/search?keyword="
HISTORY_PRICE_URL = r"https://www.vveby.com/search?keyword="
# 视图字体设置
FONT = ['Microsoft YaHei']
# banner信息
BANNER = {
"main": '''
#================*main*=================#
# 1.主界面
# 2.介绍
# 3.数据可视化
# 4.向Redis中填充数据
# 5.清空Redis队列缓存
# 6.调用 milkSpider
# 7.退出
#========================================#
''',
"introduce": '''
#================*introduce*=================#
# 1.使用Selenium + requests分情况地爬取数据
# 2.使用线程池缩减爬取总流程
# 3.使用Redis调度爬取队列并实现分布式
# 4.使用Matplotlib将数据可视化
# 输入[r]返回上一级...
#=============================================#
''',
"view": '''
'''
}

@ -0,0 +1,64 @@
# -*- coding: utf-8 -*-
from matplotlib import pyplot as plt
import matplotlib
import settings
import re
plt.rcParams['font.family'] = settings.FONT
class view:
def __init__(self, itemList):
self.id = itemList[0]
self.string = itemList[1]
def getFont(): # 列出可用的字体
font = sorted([f.name for f in matplotlib.font_manager.fontManager.ttflist])
for i in font:
print(i)
def main(self):
def str2data(string) -> list:
reg = r"[+-]?([0-9]*\.?[0-9]+|[0-9]+\.?[0-9]*)"
pattern = re.compile(reg)
return pattern.findall(string)
def show(itemList):
x = []
y = []
while itemList:
temp = itemList.pop()
date = temp[0] + "" + temp[1] + ""
price = "" + temp[2] + ""
x.append(date)
y.append(price)
date = temp[3] + "" + temp[4] + ""
price = "" + temp[5] + ""
x.append(date)
y.append(price)
plt.title("价格趋势")
plt.bar(x, y, color = 'g', align = 'center')
plt.xticks(size = 10.0, rotation = 45)
plt.xlabel("日期")
plt.ylabel("价格")
plt.plot(x, y, color = 'red', linewidth = 5.0, linestyle = '--')
plt.show()
itemList = []
for astr in self.string.split(';'):
strList = str2data(astr)
try:
print(astr)
itemList.append(strList)
except BaseException:
break
show(itemList)
def getData()
Loading…
Cancel
Save