selfteaching / selfteaching/selfteaching-python-camp

Day13 将结果作为图片发送给好友时,好友收到的是文本`day13.png`,而非图片

Open
#3,191 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
151
Forks
875
PR merge metrics
No merged PRs in 30d

Description

from wxpy import *
import requests
from pyquery import PyQuery
import stats_word
import matplotlib.pyplot as plt
import numpy as np

bot = Bot()
my_friend=bot.friends().search("妈")[0]
my_friend.send("send me a message")
@bot.register(my_friend,SHARING)
def my_friend_sharing(msg):
    msg=msg.url
    r = requests.get(msg)
    document=PyQuery(r.text)
    content = document('#js_content').text()
    a=stats_word.stats_text(content,10)
    b=dict(a)
    keys,values=zip(*b.items())


    plt.rcdefaults()#从Matplotlib的内部默认样式恢复rc参数
    fig, ax = plt.subplots()#创建一个图形和一组子图

    word=a
    y_pos = np.arange(len(word))#在给定间隔内返回均匀间隔的值。
    performance = 3 + 10 * np.random.rand(len(word))#给定形状的随机值。
    error = np.random.rand(len(word))
    
    plt.rcParams['font.sans-serif']=['SimHei'] #不用这行会出现中文字变框框,windows平台可用
    
    
    ax.barh(y_pos, values, xerr=error, align='center',color='green', ecolor='black')
    ax.set_yticks(y_pos)
    ax.set_yticklabels(keys)
    ax.invert_yaxis()  # labels read top-to-bottom
    ax.set_xlabel('词频数目')
    ax.set_title('统计词频图表')

    plt.savefig("day13.png")
    my_friend.send("day13.png")

embed()

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start from the shown @bot.register(my_friend, SHARING) handler and compare the image-generation lines with the final my_friend.send("day13.png") call. Check the wxpy sending API to determine how a saved PNG should be sent as an image, then verify that the friend receives the generated chart rather than the filename as text.

Written by the indexing model from the issue text.

Assessment

Tech stack
matplotlib, numpy, python
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.