def reply_my_friend(msg):
    if msg.type == "Sharing":
        response = requests.get(msg.url)
        document = PyQuery(response.text)
        content = document('#js_content').text()

        frequency = stats_word.stats_text_en(content, 20)

        data = {}
        for i in frequency:
            data[i[0]] = i[1]

        x = [key for key in data.keys()]
        y = [values for values in data.values()]

        plt.rcdefaults()
        fig, ax = plt.subplots()

        ax.bar(x, y, align='center', color='green', ecolor='black')

        ax.set_xlabel('Words')
        ax.set_ylabel('Numbers')
        ax.set_title('Statistics')

        plt.show()
        plt.savefig('wordcloud.png')
        msg.sender.send_image('wordcloud.png')
Пример #2
0
from mymodule.stats_word import stats_text_en
from mymodule.stats_word import stats_text_cn
from mymodule.stats_word import stats_txt
text = [1, 2, 3, 4, 5]
dic_test = {}
try:
    dic_test = stats_text_en(text)
except ValueError:
    print("Could only deai with string,check input and try again.")
Пример #3
0
import mymodule.stats_word as stats_word

text = 'abddd,plo'
sort_list = []
try:
    #对列表中中英文字符,进行统计降序排列
    sort_list = stats_word.stats_text_en(text)
except ValueError as result:
    print(result)
    
print(sort_list)


Пример #4
0
def test_logger():
    try:
        stats_word.stats_text_en(1)
    except Exception as e:
        logger.exception(e)
Пример #5
0
def test_traceback():
    try:
        stats_word.stats_text_en(1)
    except Exception as e:
        print('test_traceback =', e)
        print(traceback.format_exc())
Пример #6
0
# coding:utf-8
import mymodule.stats_word as stw

text = 'abddd,plo'
try:
    #对列表中中英文字符,进行统计降序排列
    sort_txt = stw.stats_text_en(text)
except ValueError as result:
    print(result)

print(sort_txt)
Пример #7
0
year to travel back and forth once.
On the bank of the Yellow River dwelled an old man much respected for
his wisdom. When he saw their back-breaking labour, he ridiculed
Yugong saying,”Aren’t you foolish, my friend? You are very old now,
and with whatever remains of your waning strength, you won’t be able
to remove even a corner of the mountain.”
Yugong uttered a sigh and said,”A biased person like you will never
understand. You can’t even compare with the widow’s little boy!”
“Even if I were dead, there will still be my children, my
grandchildren, my great grandchildren, my great great grandchildren.
They descendants will go on forever. But these mountains will not
grow any taler. We shall level them one day!” he declared with
confidence.
The wise old man was totally silenced.
When the guardian gods of the mountains saw how determined Yugong and
his crew were, they were struck with fear and reported the incident
to the Emperor of Heavens.
Filled with admiration for Yugong, the Emperor of Heavens ordered two
mighty gods to carry the mountains away.
'''
from mymodule import stats_word

result = stats_word.stats_text(text)
text_test_1 = 'hello, world'
result_test_1 = stats_word.stats_text_en(text_test_1)
print(result_test_1)
text_test_2 = 123456789
try:
    print(stats_word.stats_text_en(text_test_2))
except Exception as error:
    print(error)
Пример #8
0
from mymodule import stats_word
# a=(1,99,199,9999)
# s = {'梁峰':88,'韦彩兰':88}
# t=[55,88,99]
b='1855555222214862'

# stats_word.stats_text_en(a)
# stats_word.stats_text_cn(s)
# stats_word.stats_text(t)
# stats_word.stats_text_en(a)
try:
    stats_word.stats_text_en(b)
 
except IndexError:
    print('list index out of range, Enter a short array')

Пример #9
0


from mymodule import stats_word
s = 369
try:
    stats_word.stats_text_en(s)
except ValueError:
    print('Error:文本为非字符串')



Пример #10
0
def main():
    try:
        print(stats_word.stats_text_en(text1))  #参数传入非字符串,验证参数检查功能是否生效
    except Exception as e:
        print('main error=> ', e)
Пример #11
0
from mymodule import stats_word
import traceback


def text_traceback():
    try:
        stats_word.stats_text_en(1)
    except Exception as e:
        print("text_traceback:", e)
        print(traceback.format_exc())


if __name__ == "__main__":
    stats_word.stats_text_en(1)
    text_traceback()
Пример #12
0
Bohai.
Now Yugong’s neighbour was a widow who had an only child eight years
old. Evening the young boy offered his help eagerly.
Summer went by and winter came. It took Yugong and his crew a full
year to travel back and forth once.
On the bank of the Yellow River dwelled an old man much respected for
his wisdom. When he saw their back-breaking labour, he ridiculed
Yugong saying,”Aren’t you foolish, my friend? You are very old now,
and with whatever remains of your waning strength, you won’t be able
to remove even a corner of the mountain.”
Yugong uttered a sigh and said,”A biased person like you will never
understand. You can’t even compare with the widow’s little boy!”
“Even if I were dead, there will still be my children, my
grandchildren, my great grandchildren, my great great grandchildren.
They descendants will go on forever. But these mountains will not
grow any taler. We shall level them one day!” he declared with
confidence.
The wise old man was totally silenced.
When the guardian gods of the mountains saw how determined Yugong and
his crew were, they were struck with fear and reported the incident
to the Emperor of Heavens.
Filled with admiration for Yugong, the Emperor of Heavens ordered two
mighty gods to carry the mountains away.
'''

#stats_word.stats_text(122)
try:
    stats_word.stats_text_en(12123)
except ValueError as e:
    print(e)
Пример #13
0
On the bank of the Yellow River dwelled an old man much respected
for his wisdom. When he saw their back-breaking labour, he ridiculed
Yugong saying,”Aren’t you foolish, my friend? You are very old now,
and with whatever remains of your waning strength, you won’t be able
to remove even a corner of the mountain.”
Yugong uttered a sigh and said,”A biased person like you will never
understand. You can’t even compare with the widow’s little boy!”
“Even if I were dead, there will still be my children, my
grandchildren, my great grandchildren, my great great grandchildren.
They descendants will go on forever. But these mountains will not
grow any taler. We shall level them one day!” he declared with
confidence.
The wise old man was totally silenced.
When the guardian gods of the mountains saw how determined Yugong
and his crew were, they were struck with fear and reported the
incident to the Emperor of Heavens.
Filled with admiration for Yugong, the Emperor of Heavens ordered
two mighty gods to carry the mountains away.
'''
text1 = 165
text2 = [1, 2, 3, 4, 5]
import sys
sys.path.append(
    'E:/self-teaching/selfteaching-python-camp/exercises/1901100167/d09/mymodule'
)
from mymodule import stats_word
try:
    print(stats_word.stats_text_en(text))
except TypeError as e:
    print("error:%s" % e)
Пример #14
0
They descendants will go on forever. But these mountains will not
grow any taler. We shall level them one day!” he declared with
confidence.
The wise old man was totally silenced.
When the guardian gods of the mountains saw how determined Yugong and
his crew were, they were struck with fear and reported the incident
to the Emperor of Heavens.
Filled with admiration for Yugong, the Emperor of Heavens ordered two
mighty gods to carry the mountains away.
'''
#在main.py中通过模块倒入stats_word,调用stats_text统计字符串样本中中文汉子和英文单词出现的次数

dict1 = {}
dict1 = stats_word.stats_text(text)

test = (12312, 123123)  #用于 try except 捕获异常并执行

try:
    stats_word.stats_text_en(test)
except ValueError as a:
    print(a)

try:
    stats_word.status_text_cn(test)
except ValueError as a:
    print(a)

try:
    stats_word.stats_text(test)
except ValueError as a:
    print(a)
Пример #15
0
How The Foolish Old Man Moved Mountains
Yugong was a ninety-year-old man who lived at the north of two high mountains, Mount Taixing and Mount Wangwu.

Stretching over a wide expanse of land, the mountains blocked yugong’s way making it inconvenient for him and his family to get around. One day yugong gathered his family together and said,”Let’s do our best to level these two mountains. We shall open a road that leads to Yuzhou. What do you think?”
All but his wife agreed with him. “You don’t have the strength to cut even a small mound,” muttered his wife. “How on earth do you suppose you can level Mount Taixin and Mount Wanwu? Moreover, where will all the earth and rubble go?” “Dump them into the Sea of Bohai!” said everyone.
So Yugong, his sons, and his grandsons started to break up rocks and remove the earth. They transported the earth and rubble to the Sea of Bohai.
Now Yugong’s neighbour was a widow who had an only child eight years old. Evening the young boy offered his help eagerly.
Summer went by and winter came. It took Yugong and his crew a full year to travel back and forth once.
On the bank of the Yellow River dwelled an old man much respected for his wisdom. When he saw their back-breaking labour, he ridiculed Yugong saying,”Aren’t you foolish, my friend? You are very old now, and with whatever remains of your waning strength, you won’t be able to remove even a corner of the mountain.”
Yugong uttered a sigh and said,”A biased person like you will never understand. You can’t even compare with the widow’s little boy!”
“Even if I were dead, there will still be my children, my grandchildren, my great grandchildren, my great great grandchildren. They descendants will go on forever. But these mountains will not grow any taler. We shall level them one day!” he declared with confidence.
The wise old man was totally silenced. When the guardian gods of the mountains saw how determined Yugong and his crew were, they were struck with fear and reported the incident to the Emperor of Heavens.
Filled with admiration for Yugong, the Emperor of Heavens ordered two mighty gods to carry the mountains away. 
'''

# 调⽤用 stats_word 中的任何⼀一个函数,参数传⼊入⾮非字符串串,验证参数检查
# 功能是否⽣生效

try:
    #<<<<<<< master
    print(stats_word.stats_text(520))
    print(stats_word.stats_text_en([1, 2, 3, 4]))
    #=======
    # print(stats_word.stats_text(520))
    # print(stats_word.stats_text_en([1,2,3,4]))
    #>>>>>>> master
    print(stats_word.stats_text_cn(True))
except ValueError:
    print("ValueError: text is not a string")
Пример #16
0
寒來暑往,他們要一年才能往返渤海一次。
住在黃河河畔的智叟,看見他們這樣辛苦,取笑愚公說:「你不是很愚蠢嗎?你已一把年紀了,就是用盡你的氣力,也不能挖去山的一角呢?」
愚公歎息道:「你有這樣的成見,是不會明白的。你比那寡婦的小兒子還不如呢!就算我死了,還有我的兒子,我的孫子,我的曾孫子,他們一直傳下去。而這二山是不會加大的,總有一天,我們會把它們剷平。」
智叟聽了,無話可說:
二山的守護神被愚公的堅毅精神嚇倒,便把此事奏知天帝。天帝佩服愚公的精神,就命兩位大力神揹走二山。
How The Foolish Old Man Moved Mountains
Yugong was a ninety-year-old man who lived at the north of two high mountains, Mount Taixing and Mount Wangwu.
Stretching over a wide expanse of land, the mountains blocked yugong’s way making it inconvenient for him and his family to get around.
One day yugong gathered his family together and said,”Let’s do our best to level these two mountains. We shall open a road that leads to Yuzhou. What do you think?”
All but his wife agreed with him.
“You don’t have the strength to cut even a small mound,” muttered his wife. “How on earth do you suppose you can level Mount Taixin and Mount Wanwu? Moreover, where will all the earth and rubble go?”
“Dump them into the Sea of Bohai!” said everyone.
So Yugong, his sons, and his grandsons started to break up rocks and remove the earth. They transported the earth and rubble to the Sea of Bohai.
Now Yugong’s neighbour was a widow who had an only child eight years old. Evening the young boy offered his help eagerly.
Summer went by and winter came. It took Yugong and his crew a full year to travel back and forth once.
On the bank of the Yellow River dwelled an old man much respected for his wisdom. When he saw their back-breaking labour, he ridiculed Yugong saying,”Aren’t you foolish, my friend? You are very old now, and with whatever remains of your waning strength, you won’t be able to remove even a corner of the mountain.”
Yugong uttered a sigh and said,”A biased person like you will never understand. You can’t even compare with the widow’s little boy!”
“Even if I were dead, there will still be my children, my grandchildren, my great grandchildren, my great great grandchildren. They descendants will go on forever. But these mountains will not grow any taler. We shall level them one day!” he declared with confidence.
The wise old man was totally silenced.
When the guardian gods of the mountains saw how determined Yugong and his crew were, they were struck with fear and reported the incident to the Emperor of Heavens.
Filled with admiration for Yugong, the Emperor of Heavens ordered two mighty gods to carry the mountains away.
'''

a = {1, 2, 3, 4, 5, 6, 7, 8, 9}

try:
    b = stats_word.stats_text_en(a)
except TypeError as t_error:
    print(t_error)