[Micro] Letter auxiliary current epidemic, python help you find friends circle of friends to give care in Wuhan

I am a programmer small leaflets, exciting technology to bring original content for everyone.

Epidemic both for individuals or enterprises are too heavy a burden. Hope the epidemic at an early date in the past, it is as a person a little wish.

Friends and family around us are more or less affected by the epidemic, let's find out the circle of friends of friends to show concern by the Wuhan python.
Here Insert Picture Description
The first step, or the first installation wxpy, followed by the installation pyecharts mapping module in this article are used

pip install wxpy # support micro-channel related functions

pip install pyecharts # support mapping functionality

pip install pyecharts_snapshot

The second step, according to map data packets need to download the required, after pyecharts v0.3.2, pyecharts will no longer own map js file. The user needs to use the map charts, installable file bundle corresponding to the map itself . Here we select Chinese provincial map: echarts-china-provinces-pypkg download for displaying a map of Hubei Province

Global country map: echarts-countries-pypkg: map of the world and 213 countries, including China

Chinese provincial map: echarts-china-provinces-pypkg: 23 provinces, five autonomous regions

China city map: echarts-china-cities-pypkg: 370 Chinese cities

Chinese county-level map: echarts-china-counties-pypkg: 2882 a Chinese-area counties

China's regional maps: echarts-china-misc-pypkg: 11 regional map of China, such as South China, North China.

In addition, the United Kingdom 2016 constituency map: echarts-united-kingdom-pypkg: UK constituency map can be used to draw data related to the political and economic

pip install echarts-countries-pypkg

pip install echarts-china-provinces-pypkg

pip install echarts-china-cities-pypkg

pip install echarts-china-counties-pypkg

pip install echarts-china-misc-pypkg

After the environment is ready, followed by design strategy.

1. Bot (cache_path = True) .friends () function to get information about friends, we are looking to find friends Hubei;

2. Add to eCharts custom geojson achieve data map display;

3. Customize the blessing, then surgery were randomly sent to Hubei buddy list ;
Here Insert Picture Descriptionthe complete code:

# encoding: utf-8
"""
@author: 程序员小小叶
@contact: [email protected]
@微信公众号:程序员小小叶
@time: 2020/2/19 13:03
@file: case4.py
@desc: 疫情当前,python帮你找出朋友圈的武汉朋友给予关怀
"""
from wxpy import *
from pyecharts import options as opts
from pyecharts.charts import Geo
from pyecharts.globals import ChartType
from pyecharts.globals import ThemeType
import webbrowser
import random


def is_Chinese(word):  # 由于存在国外友人,所以这里要滤除国外英文地名以及不填地区的好友
	for ch in word:
		if '\u4e00' <= ch <= '\u9fff':
			return True
	return False


bot = Bot(cache_path=True)
# 获取所有好友的信息
friends = bot.friends()
# 获取省份信息,并过滤出湖北的好友
china_friends_sum = {}
hubei_friends_sum = {}
hubei_friends = []
for f in friends:
	province = f.province
	if is_Chinese(province):
		if province in china_friends_sum:
			china_friends_sum[province] += 1
			if province == '湖北':
				city = f.city
				print(f.remark_name)
				print(f.city)
				hubei_friends.append(f)
				if city in hubei_friends_sum:
					hubei_friends_sum[city] += 1
				else:
					hubei_friends_sum[city] = 1
		else:
			china_friends_sum[province] = 1
# 由于微信内的城市名称不带“市”,且部分自治州也是简称,所以要进行补全,如恩施土家族苗族自治州
hubei_citys = ['黄冈市', '黄石市', '鄂州市', '武汉市', '咸宁市', '孝感市', '随州市', '天门市', '仙桃市', '荆州市', '荆门市', '潜江市', '襄阳市', '宜昌市', '十堰市',
               '神农架林区', '恩施土家族苗族自治州']
echart_data = []
max = 0
for m in hubei_friends_sum:
	for city in hubei_citys:
		if m in city:
			item = (city, hubei_friends_sum[m])
			echart_data.append(item)
			if hubei_friends_sum[m] > max:
				max = hubei_friends_sum[m]
print(echart_data)
print(max)
print(china_friends_sum)


# 绘制分布地图
def geo_guangdong() -> Geo:
	c = (
		Geo(init_opts=opts.InitOpts(theme=ThemeType.DARK))
			.add_schema(maptype="湖北")  # 也可以是其他省,那么对应的城市名也是需要修改的
			.add("", echart_data, ChartType.EFFECT_SCATTER,
		         is_selected=True, symbol=None, symbol_size=6, color="red")
			.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
			.set_global_opts(visualmap_opts=opts.VisualMapOpts(is_piecewise=True, max_=max, ),
		                     title_opts=opts.TitleOpts(title="微信好友湖北分布图", pos_left="300")
		                     )
	)
	return c


g = geo_guangdong()
g.render('微信好友湖北分布图.html')
# 用浏览器打开生成的本地网页
# webbrowser.open("微信好友湖北分布图.html")
# 分别发送祝福给对方
# 祝福语录集
wishes = ["出门戴口罩哦!勤洗手勤通风,少出门不聚集!",
          "保持好心态、重防护、勤消毒,减少出门和聚会,保护好自己和家人。",
          "但行好事,莫问前程,共渡难关。"]
print(len(wishes)-1)
for hf in hubei_friends:
	print(hf.remark_name)
	target = bot.search(hf.remark_name)[0]  # 这里‘’填入微信好友昵称
	target.send(wishes[random.randint(0, len(wishes)-1)])
# 进入Python命令行,让程序保持运行
embed()

Here Insert Picture Description

If you're learning Python, may wish to look at the collection point of praise!

No public the same name: programmer small leaflets, Follow Send "Data Analysis", presented "the use of Python for data analysis" (Chinese bookmarked) E-book (best book to learn basic Python library.)

Here Insert Picture Description

Released two original articles · won praise 0 · Views 20

Guess you like

Origin blog.csdn.net/weixin_32229703/article/details/104411996