17.xx - wwj-2017-1117/graph GitHub Wiki

coding=utf-8

version: python3.5

发现那个在outlook中最关心你的人!!!

python 操作outlook

import win32com.client from collections import Counter from pylab import *

mpl.rcParams['font.sans-serif'] = ['SimHei'] outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI") Mailing_list_name = [] n_groups = 10 email_num = [] email_per = []

def Mailing_list(): total_receive = outlook.GetDefaultFolder(6) messages = total_receive.Items total_number = messages.count print("total_number=", total_number) for i in range(1, total_number + 1): Mailing_list_name.append(total_receive.Items.Item(i).SenderName) # Counter 对象返回一个(key-value)对,可以转化成字典,然后获取item排序 Mailing_collect = sorted(dict(Counter(Mailing_list_name)).items(), key=lambda d: d[1])[::-1][:n_groups] print(Mailing_collect) for x_y in Mailing_collect: email_per.append(x_y[0]) email_num.append(x_y[1])

# subplot()创建单个子图
fig, ax = plt.subplots(1, 1, figsize=(9, 6))
index = np.arange(n_groups)
bar_width = 0.35
opacity = 0.5
plt.bar(index, email_num, bar_width, alpha=opacity, color='b', label='Person')

plt.xlabel('Person')
plt.ylabel('Total_number')
plt.title('who cares most about you in the mail')
plt.xticks(index, email_per, rotation=30)
plt.ylim(0, max(email_num) + 10)
for a, b in zip(index, email_num):
    plt.text(a, b + 0.05, '%.0f' % b, ha='center', va='bottom', fontsize=7)
plt.legend()
plt.tight_layout()

plt.savefig("care_people.jpg", dpi=720)
plt.show()
plt.close()

if name == "main": Mailing_list()