from wxpy import *
from pyecharts import Pie
import webbrowser
bot=Bot(cache_path=True)
friends = bot.friends(update=False)
male = female = other = 0
for i in friends:
sex=i.sex
if sex==1:
male+=1
elif sex==2:
female+=1
else:
other+=1
total=len(friends)
attr = ["男性","女性","其他"]
v1 = [float(male),float(female),float(other)]
pie=Pie("我的微信好友男女比例",title_pos='center')
pie.add("", attr, v1, radius=[40, 75], label_text_color=None, is_label_show=True, legend_orient='vertical', legend_pos='left')
pie.render("pie.html")
webbrowser.open("pie.html")
from wxpy import *
from pyecharts import Map
import webbrowser
#因为获取的列表城市都没有带市字,而pyecharts需要带个市字
b = '市'
def s(x):
return x+b
#因为我好友里面除了广东的外和其他的,剩下非广东的寥寥无几,所以只提取广东的
bot = Bot(cache_path = True)
friends = bot.friends(update=False).search(province = '广东')
citys = []
for f in friends :
city = f.city
citys.append(city)
r = map(s,citys)
cityss = list(r)
#为城市计数
a = {}
for i in cityss:
a[i] = cityss.count(i)
a.pop('市')
#把字典进行有序拆分为2个列表
attrs = []
values = []
for value, attr in a.items():
values.append(attr)
attrs.append(value)
#开始绘图
map = Map("广东地图示例", width=1200, height=600)
map.add("", attrs, values, maptype='广东', is_visualmap=True, visual_text_color='#000')
map.render("city.html")
webbrowser.open("city.html")
from wxpy import *
import re
import jieba
import numpy as np
import webbrowser
from pyecharts import WordCloud
bot = Bot(cache_path = True)
friends = bot.friends(update=False)
#提取好友签名,并去掉span,class,emoji,emoji1f3c3等的字段
signatures = []
for i in friends:
signature = i.signature.strip().replace("span", "").replace("class", "").replace("emoji", "")
# 正则匹配过滤掉emoji表情,例如emoji1f3c3等
rep = re.compile("1f\d.+")
signature = rep.sub("", signature)
signatures.append(signature)
# 拼接字符串
text = "".join(signatures)
# jieba分词
wordlist_jieba = jieba.cut(text, cut_all=True)
ws=[]
ct={}
keywords=[]
counts=[]
for word in wordlist_jieba:
ws.append(word)
ct[word]=ct.get(word,0)+1
items =list(ct.items())
items.sort(key=lambda x: x[1], reverse=True)
for item in items:
word,count=item
keywords.append(word)
counts.append(count)
wordcloud = WordCloud(width=1200, height=800)
wordcloud.add("", keywords, counts, word_size_range=[10, 300])
wordcloud.render("wordcloud.html")
webbrowser.open("wordcloud.html")