@@ -47,7 +47,7 @@ def fetch_data(uid=None, container_id=None):
4747 params ['page' ] = str (page )
4848 params ['containerid' ] = container_id
4949 res = requests .get (url , params = params , headers = headers )
50- cards = res .json ().get ("cards" )
50+ cards = res .json ().get ("data" ). get ( " cards" )
5151
5252 for card in cards :
5353 # 每条微博的正文内容
@@ -63,7 +63,8 @@ def fetch_data(uid=None, container_id=None):
6363
6464def grey_color_func (word , font_size , position , orientation , random_state = None ,
6565 ** kwargs ):
66- s = "hsl(0, 0%%, %d%%)" % 0
66+ s = "hsl(255, 0%%, %d%%)" % 0
67+ print (s )
6768 return s
6869
6970
@@ -75,18 +76,33 @@ def generate_image():
7576 for text in f .readlines ():
7677 data .extend (jieba .analyse .extract_tags (text , topK = 20 ))
7778 data = " " .join (data )
78- mask_img = imread ('./52f90c9a5131c.jpg' , flatten = True )
79- wordcloud = WordCloud (
80- font_path = 'msyh.ttc' ,
81- background_color = 'white' ,
82- mask = mask_img
83- ).generate (data )
84- plt .imshow (wordcloud .recolor (color_func = grey_color_func , random_state = 3 ),
85- interpolation = "bilinear" )
79+ mask_img = imread ('./logo.jpg' , flatten = True )
80+
81+ wordcloud = WordCloud (font_path = '/Library/Fonts/Songti.ttc' ,
82+ background_color = "white" ,
83+ max_words = 80 ,
84+ mask = mask_img
85+ ).generate (data )
86+ plt .figure (figsize = (9 , 6 ))
87+ # plt.imshow(wordcloud.recolor(color_func=grey_color_func, random_state=3), interpolation="bilinear")
88+
89+ plt .imshow (wordcloud , interpolation = "bilinear" )
90+ # plt.axis("off")
91+ # plt.show()
92+
93+
94+
95+ # wordcloud = WordCloud(
96+ # font_path='/Library/Fonts/Songti.ttc',
97+ # background_color='white',
98+ # mask=mask_img
99+ # ).generate(data)
100+ # plt.imshow(wordcloud.recolor(color_func=grey_color_func, random_state=3),
101+ # interpolation="bilinear")
86102 plt .axis ('off' )
87103 plt .savefig ('./heart2.jpg' , dpi = 1600 )
88104
89105
90106if __name__ == '__main__' :
91- fetch_data ("1192515960" , "1076031192515960" )
107+ # fetch_data("1192515960", "1076031192515960")
92108 generate_image ()
0 commit comments