Ejemplo n.º 1
0
def draw_cloud(cleantweets):
    text = " ".join(str(tweet) for tweet in cleantweets)
    tokens = word_tokenize(text)
    dic = Counter(tokens)
    print(dic.most_common(max_words))
    twitter_mask = np.array(Image.open("twitter-logo.jpg"))
    wordcloud = PersianWordCloud(only_persian=True,
                                 max_words=max_words,
                                 margin=0,
                                 width=800,
                                 height=800,
                                 min_font_size=1,
                                 max_font_size=500,
                                 background_color="white",
                                 mask=twitter_mask).generate(text)

    image = wordcloud.to_image()
    wordcloud.to_file(image_file_path)
    image.show()
Ejemplo n.º 2
0
wc = PersianWordCloud(only_persian=True,
                      regexp=r".*\w+.*",
                      font_step=3,
                      font_path=path.join(d, "IRANSans.ttf"),
                      background_color="white",
                      max_words=800,
                      mask=twitter_mask,
                      stopwords=stopwords)
wc.generate(text)

currTime = datetime.datetime.utcnow()
output_name = currTime.strftime("%d-%m-%Y_%H_%M.png")
#output_name = "test.png"

# store to file
wc.to_file(path.join(d, output_name))

import tweepy
import telegram
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
telegram_bot = telegram.Bot(token=telegram_bot_token)

api.update_with_media(
    path.join(d, output_name),
    u'توییتر به روایت تصویر پس از پردازش ' + str(tweet_cnt) + u' توییت!')
wctg = telegram_bot.send_photo(chat_id="@trenditter",
                               photo=open(path.join(d, output_name), 'rb'),
                               caption=u'توییتر به روایت تصویر پس از پردازش ' +
                               str(tweet_cnt) + u' توییت!')