diff --git a/exercises/1901010161/1001S02E03_calculator.py b/exercises/1901010161/1001S02E03_calculator.py index 51fc809ec..2607f5ae5 100644 --- a/exercises/1901010161/1001S02E03_calculator.py +++ b/exercises/1901010161/1001S02E03_calculator.py @@ -7,13 +7,9 @@ def calculate(): / for division ''') -#<<<<<<< master +# <<<<<<< master number_1 = float(input('Please enter the first number: ')) number_2 = float(input('Please enter the second number: ')) -#======= - number_1 = int(input('Please enter the first number: ')) - number_2 = int(input('Please enter the second number: ')) -#>>>>>>> master if operation == '+': print('{} + {} = '.format(number_1, number_2)) diff --git a/exercises/1901010161/README.md b/exercises/1901010161/README.md index e69de29bb..1276081f3 100644 --- a/exercises/1901010161/README.md +++ b/exercises/1901010161/README.md @@ -0,0 +1,3 @@ + 终于来到了第14个任务,是时候总结一下自己的学习体会了。 + 从最开始对Python的一无所知到现在的一知半解,从最开始安装都要折腾好几个来回到现在对付着运行各种程序,Python的学习总归算是迈进门了一条腿。想当初建个py文件都不知道应该怎么建,现在至少对于各种名词都不那么陌生了。在这个过程中,感谢各位教练的陪伴,尤其是绿巨人教练给了我很多指导,也让我增加了不少信心。具体的体会很多写在了每次作业之后。回头看去,真的能看到自己的成长。 + 以后我会更多从实际出发,让编程带给生活更多的变化。 \ No newline at end of file diff --git a/exercises/1901010161/d10/00.py b/exercises/1901010161/d10/00 similarity index 100% rename from exercises/1901010161/d10/00.py rename to exercises/1901010161/d10/00 diff --git a/exercises/1901010161/d11/00.py b/exercises/1901010161/d11/00.py new file mode 100644 index 000000000..0ebb2a315 --- /dev/null +++ b/exercises/1901010161/d11/00.py @@ -0,0 +1,36 @@ +import requests +import getpass +import yagmail +from pyquery import PyQuery as py +from mymodule import stats_word + +reponse = requests.get('https://mp.weixin.qq.com/s/pLmuGoc4bZrMNl7MSoWgiA') # 缃戦〉璇锋眰 +web_text = reponse.text # 淇濆瓨鏇村缃戦〉鏂囨湰鏁版嵁 +document = py(web_text) +content = document('#js_content').text() +print('content=', content) + +w_list = stats_word.stats_text_cn(content, 100) +w_list = str(w_list) +print(w_list) + +sender = input("璇疯緭鍏ュ彂浠朵汉閭:") +password = getpass.getpass("杈撳叆鍙戜欢浜洪偖绠辨巿鏉冪爜:") + +yagmail.register(sender, password) + +yag = yagmail.SMTP(sender, password, host='smtp.qq.com') +yag.send('pythoncamp@163.com', '銆1901010161銆戣嚜瀛﹁缁冭惀瀛︿範2缇AY11 Zezhou-Sun', w_list) +print("鍙戦佹垚鍔") + +''' +countlist_str = ''.join(str(i) for i in countlist) +print(countlist_str) +# Use getpass to enter the email address related information +import getpass +recipients = input('pythoncamp@163.com') ##'Enter the email address of the reciever:' +# Leverage yagmail to send out emai +import yagmail +yag = yagmail.SMTP(user=sender, password=password, host='smtp.qq.com') +yag.send(recipients, '銆1901010161銆戣嚜瀛﹁缁冭惀瀛︿範2缇AY11 Zezhou-Sun', countlist_str) +''' diff --git a/exercises/1901010161/d11/1111.code-workspace b/exercises/1901010161/d11/1111.code-workspace new file mode 100644 index 000000000..a4fe0a37c --- /dev/null +++ b/exercises/1901010161/d11/1111.code-workspace @@ -0,0 +1,8 @@ +{ + "folders": [ + { + "path": "D:\\鐢ㄦ埛鐩綍\\鎴戠殑鏂囨。\\GitHub\\selfteaching-python-camp\\exercises\\1901010161" + } + ], + "settings": {} +} \ No newline at end of file diff --git a/exercises/1901010161/d11/main.py b/exercises/1901010161/d11/main.py new file mode 100644 index 000000000..4288af16f --- /dev/null +++ b/exercises/1901010161/d11/main.py @@ -0,0 +1,12 @@ +from mymodule import stats_word + +path = r'd:\鐢ㄦ埛鐩綍\鎴戠殑鏂囨。\GitHub\selfteaching-python-camp\exercises\1901010161\d11\mymodule\tang300.json' +with open(path, 'r', encoding='UTF-8') as f: # byte缂栫爜鐨勭被鍨嬪悕绉版槸 UTF-8 + + read_date = f.read() + + +try: + print('鍑虹幇棰戠巼鏈楂樼殑鍓20涓瘝锛 \n', stats_word.stats_text_cn(read_date, 20)) +except ValueError: + print('ValueError:type of argument is not string!') diff --git a/exercises/1901010161/d11/mymodule/stats_word.py b/exercises/1901010161/d11/mymodule/stats_word.py new file mode 100644 index 000000000..f6abc1b21 --- /dev/null +++ b/exercises/1901010161/d11/mymodule/stats_word.py @@ -0,0 +1,35 @@ +import re # 璋冪敤姝e垯琛ㄨ揪寮 +import collections +import jieba +count = int() + + +def stats_text_en(text, count): # 瀹氫箟鑻辫鏂囨湰缁熻鍑芥暟 + if type(text) == str: + m = re.sub(r'[^A-Za-z]', ' ', text) # 灏唗ext涓换鎰忛潪瀛楁瘝鎴愬垎鏇挎崲涓虹┖ + stri = m.split() # 鍒囧垎鑻辨枃鍗曡瘝锛屽缓绔嬪瓧绗︿覆 + return(collections.Counter(stri).most_common(count)) + else: + raise ValueError('type of argument is not string') + + +def stats_text_cn(text, count): # 瀹氫箟涓枃鏂囨湰缁熻鍑芥暟 + if type(text) == str: + p = re.compile(r'[\u4e00-\u9fa5]') # 涓枃鍩烘湰姹夊瓧锛20902瀛楋級鐨勭紪鐮佽寖鍥存槸锛歕u4e00鍒癨u9fa5 + res = re.findall(p, text) # 鑾峰彇鎵鏈変腑鏂囧瓧绗 + str1 = "".join(res) + str2 = jieba.lcut(str1) # 缁撳反鍒嗚瘝 + text1 = [] + for i in str2: + if len(i) >= 2: + text1.append(i) + return(collections.Counter(text1).most_common(count)) + else: + raise ValueError('type of argument is not string') + + +def stats_text(text, count): # 瀹氫箟鏂囨湰缁熻鍑芥暟 + if type(text) == str: + return(stats_text_en(text, count) + stats_text_cn(text, count)) # 杈撳嚭鍚堝苟鑻辨枃鍜屼腑鏂囪瘝棰戠粺璁$粨鏋 + else: + raise ValueError('type of argument is not string') diff --git a/exercises/1901010161/d12/00.py b/exercises/1901010161/d12/00.py new file mode 100644 index 000000000..0ebb2a315 --- /dev/null +++ b/exercises/1901010161/d12/00.py @@ -0,0 +1,36 @@ +import requests +import getpass +import yagmail +from pyquery import PyQuery as py +from mymodule import stats_word + +reponse = requests.get('https://mp.weixin.qq.com/s/pLmuGoc4bZrMNl7MSoWgiA') # 缃戦〉璇锋眰 +web_text = reponse.text # 淇濆瓨鏇村缃戦〉鏂囨湰鏁版嵁 +document = py(web_text) +content = document('#js_content').text() +print('content=', content) + +w_list = stats_word.stats_text_cn(content, 100) +w_list = str(w_list) +print(w_list) + +sender = input("璇疯緭鍏ュ彂浠朵汉閭:") +password = getpass.getpass("杈撳叆鍙戜欢浜洪偖绠辨巿鏉冪爜:") + +yagmail.register(sender, password) + +yag = yagmail.SMTP(sender, password, host='smtp.qq.com') +yag.send('pythoncamp@163.com', '銆1901010161銆戣嚜瀛﹁缁冭惀瀛︿範2缇AY11 Zezhou-Sun', w_list) +print("鍙戦佹垚鍔") + +''' +countlist_str = ''.join(str(i) for i in countlist) +print(countlist_str) +# Use getpass to enter the email address related information +import getpass +recipients = input('pythoncamp@163.com') ##'Enter the email address of the reciever:' +# Leverage yagmail to send out emai +import yagmail +yag = yagmail.SMTP(user=sender, password=password, host='smtp.qq.com') +yag.send(recipients, '銆1901010161銆戣嚜瀛﹁缁冭惀瀛︿範2缇AY11 Zezhou-Sun', countlist_str) +''' diff --git a/exercises/1901010161/d12/1111.code-workspace b/exercises/1901010161/d12/1111.code-workspace new file mode 100644 index 000000000..a4fe0a37c --- /dev/null +++ b/exercises/1901010161/d12/1111.code-workspace @@ -0,0 +1,8 @@ +{ + "folders": [ + { + "path": "D:\\鐢ㄦ埛鐩綍\\鎴戠殑鏂囨。\\GitHub\\selfteaching-python-camp\\exercises\\1901010161" + } + ], + "settings": {} +} \ No newline at end of file diff --git a/exercises/1901010161/d12/main.py b/exercises/1901010161/d12/main.py new file mode 100644 index 000000000..a784315c2 --- /dev/null +++ b/exercises/1901010161/d12/main.py @@ -0,0 +1,31 @@ +from mymodule import stats_word +from wxpy import Bot, Message, embed +from pyquery import PyQuery +import requests + +bot = Bot() # 鍒濆鍖栨満鍣ㄤ汉锛屾壂鐮佺櫥褰 +my_friend = bot.friends().search('闂')[0] # 鏌ユ壘濂藉弸 +my_friend.send('鍒嗕韩浠绘剰寰俊鏂囩珷缁欐垜') # 鍙戠敓鏂囨湰缁欏ソ鍙 + +# 鐩戝惉娑堟伅 +# 鍥炲濂藉弸娑堟伅 +@bot.register(my_friend) +def reply_my_friend(msg): + if msg.type == 'Sharing': + response = requests.get(msg.url) + document = PyQuery(response.text) + content = document('#js_content').text() + reply = stats_word.stats_text_cn(content, 100) + return reply +embed() + + +path = r'd:\鐢ㄦ埛鐩綍\鎴戠殑鏂囨。\GitHub\selfteaching-python-camp\exercises\1901010161\d11\mymodule\tang300.json' +with open(path, 'r', encoding='UTF-8') as f: # byte缂栫爜鐨勭被鍨嬪悕绉版槸 UTF-8 + read_date = f.read() + + +try: + print('鍑虹幇棰戠巼鏈楂樼殑鍓20涓瘝锛 \n', stats_word.stats_text_cn(read_date, 20)) +except ValueError: + print('ValueError:type of argument is not string!') diff --git a/exercises/1901010161/d12/mymodule/stats_word.py b/exercises/1901010161/d12/mymodule/stats_word.py new file mode 100644 index 000000000..f6abc1b21 --- /dev/null +++ b/exercises/1901010161/d12/mymodule/stats_word.py @@ -0,0 +1,35 @@ +import re # 璋冪敤姝e垯琛ㄨ揪寮 +import collections +import jieba +count = int() + + +def stats_text_en(text, count): # 瀹氫箟鑻辫鏂囨湰缁熻鍑芥暟 + if type(text) == str: + m = re.sub(r'[^A-Za-z]', ' ', text) # 灏唗ext涓换鎰忛潪瀛楁瘝鎴愬垎鏇挎崲涓虹┖ + stri = m.split() # 鍒囧垎鑻辨枃鍗曡瘝锛屽缓绔嬪瓧绗︿覆 + return(collections.Counter(stri).most_common(count)) + else: + raise ValueError('type of argument is not string') + + +def stats_text_cn(text, count): # 瀹氫箟涓枃鏂囨湰缁熻鍑芥暟 + if type(text) == str: + p = re.compile(r'[\u4e00-\u9fa5]') # 涓枃鍩烘湰姹夊瓧锛20902瀛楋級鐨勭紪鐮佽寖鍥存槸锛歕u4e00鍒癨u9fa5 + res = re.findall(p, text) # 鑾峰彇鎵鏈変腑鏂囧瓧绗 + str1 = "".join(res) + str2 = jieba.lcut(str1) # 缁撳反鍒嗚瘝 + text1 = [] + for i in str2: + if len(i) >= 2: + text1.append(i) + return(collections.Counter(text1).most_common(count)) + else: + raise ValueError('type of argument is not string') + + +def stats_text(text, count): # 瀹氫箟鏂囨湰缁熻鍑芥暟 + if type(text) == str: + return(stats_text_en(text, count) + stats_text_cn(text, count)) # 杈撳嚭鍚堝苟鑻辨枃鍜屼腑鏂囪瘝棰戠粺璁$粨鏋 + else: + raise ValueError('type of argument is not string') diff --git a/exercises/1901010161/d13/1111.code-workspace b/exercises/1901010161/d13/1111.code-workspace new file mode 100644 index 000000000..a4fe0a37c --- /dev/null +++ b/exercises/1901010161/d13/1111.code-workspace @@ -0,0 +1,8 @@ +{ + "folders": [ + { + "path": "D:\\鐢ㄦ埛鐩綍\\鎴戠殑鏂囨。\\GitHub\\selfteaching-python-camp\\exercises\\1901010161" + } + ], + "settings": {} +} \ No newline at end of file diff --git a/exercises/1901010161/d13/main.py b/exercises/1901010161/d13/main.py new file mode 100644 index 000000000..7c0709ac4 --- /dev/null +++ b/exercises/1901010161/d13/main.py @@ -0,0 +1,29 @@ +import numpy as np +from mymodule import stats_word +from pyquery import PyQuery as py +import requests +import matplotlib.pyplot as plt + +reponse = requests.get('https://mp.weixin.qq.com/s/_oFklhozwgz_1QnB_pLioA') # 缃戦〉璇锋眰 +web_text = reponse.text # 淇濆瓨鏇村缃戦〉鏂囨湰鏁版嵁 +document = py(web_text) +content = document('#js_content').text() + +w_list = stats_word.stats_text_cn(content, 10) +w_list = dict(w_list) +# group_data = list(w_list.values()) +group_data = tuple(w_list.values()) +group_names = list(w_list.keys()) +# plt.rcdefaults() +fig, ax = plt.subplots() # 寤虹珛涓涓猣igure瀵硅薄锛屽缓绔嬩竴涓猘xis瀵硅薄 +y_pos = np.arange(len(group_names)) +ax.barh(y_pos, group_data, align='center') +ax.set_yticks(y_pos) +ax.set_yticklabels(group_names) +ax.invert_yaxis() +ax.set_xlabel('璇嶉') +ax.set_title('缃戦〉涓璗OP10涓枃璇嶈') +plt.show() + +# plt.savefig(r'wordsCnt.jpeg') #淇濆瓨鍥剧墖 +# msg.reply_image(r'wordsCnt.jpeg') #鍥炲鍥剧墖 diff --git a/exercises/1901010161/d13/mymodule/stats_word.py b/exercises/1901010161/d13/mymodule/stats_word.py new file mode 100644 index 000000000..f6abc1b21 --- /dev/null +++ b/exercises/1901010161/d13/mymodule/stats_word.py @@ -0,0 +1,35 @@ +import re # 璋冪敤姝e垯琛ㄨ揪寮 +import collections +import jieba +count = int() + + +def stats_text_en(text, count): # 瀹氫箟鑻辫鏂囨湰缁熻鍑芥暟 + if type(text) == str: + m = re.sub(r'[^A-Za-z]', ' ', text) # 灏唗ext涓换鎰忛潪瀛楁瘝鎴愬垎鏇挎崲涓虹┖ + stri = m.split() # 鍒囧垎鑻辨枃鍗曡瘝锛屽缓绔嬪瓧绗︿覆 + return(collections.Counter(stri).most_common(count)) + else: + raise ValueError('type of argument is not string') + + +def stats_text_cn(text, count): # 瀹氫箟涓枃鏂囨湰缁熻鍑芥暟 + if type(text) == str: + p = re.compile(r'[\u4e00-\u9fa5]') # 涓枃鍩烘湰姹夊瓧锛20902瀛楋級鐨勭紪鐮佽寖鍥存槸锛歕u4e00鍒癨u9fa5 + res = re.findall(p, text) # 鑾峰彇鎵鏈変腑鏂囧瓧绗 + str1 = "".join(res) + str2 = jieba.lcut(str1) # 缁撳反鍒嗚瘝 + text1 = [] + for i in str2: + if len(i) >= 2: + text1.append(i) + return(collections.Counter(text1).most_common(count)) + else: + raise ValueError('type of argument is not string') + + +def stats_text(text, count): # 瀹氫箟鏂囨湰缁熻鍑芥暟 + if type(text) == str: + return(stats_text_en(text, count) + stats_text_cn(text, count)) # 杈撳嚭鍚堝苟鑻辨枃鍜屼腑鏂囪瘝棰戠粺璁$粨鏋 + else: + raise ValueError('type of argument is not string') diff --git a/exercises/1901010161/main.py b/exercises/1901010161/main.py new file mode 100644 index 000000000..c0c273e07 --- /dev/null +++ b/exercises/1901010161/main.py @@ -0,0 +1,65 @@ +# 瀵煎叆妯″潡 +from pylab import * +import matplotlib.pyplot as plt +import numpy as np +from wxpy import * +import yagmail +import requests +from pyquery import PyQuery +import getpass +import logging +from mymodule import stats_word + +# 瀹夎渚濊禆鍖 requests yagmail pyquery lxml +# pip install -i https://pypi.tuna.tsinghua.edu.cn/simple requests yagmail pyquery lxml + +logging.basicConfig(format='file:%(filename)s|line:%(lineno)s|message:%(message)s',level=logging.DEBUG) + +# 閫氳繃 requests.get 鑾峰緱 URL缃戦〉鐨勬枃绔狅紝瀛樺叆 response 骞惰繑鍥 +def get_article(url): + response = requests.get(url) + document = PyQuery(response.text) + return document('#js_content').text() + +def main(): + + # 鍒濆鍖栨満鍣ㄤ汉锛屾壂鐮佺櫥闄 + bot = Bot() + + # 鎼滅储濂藉弸 + my_friends = bot.friends().search('閲戣瀺瀹')[0] + + # 鐩戝惉 my_friend 鐨勫垎浜殑娑堟伅锛屽苟鑾峰緱鍒嗕韩娑堟伅鐨 閾炬帴 + @bot.register(chats=my_friends) + def proc(msg): + try: + logging.info('sharing url - %s', msg.url) + article = get_article(msg.url) + count = 10 + result = stats_word.stats_text_cn(article, count) # 璋 stats_text_cn 锛屽皢鎵姹夊瓧鍙婇娆¤褰 result + + group_data = list(result.values()) + group_names = list(result.keys()) + + y_pos = np.arange(len(group_names)) + + plt.rcdefaults() + fig, ax = plt.subplots() + plt.rcParams['font.sans-serif']=['SimHei'] + ax.barh(y_pos, group_data, align='center') + ax.set_yticks(y_pos) + ax.set_yticklabels(group_names) + ax.invert_yaxis() + ax.set_xlabel('璇嶉') + ax.set_title('缃戦〉涓璗OP10涓枃璇嶈') + plt.savefig(r'wordsCnt.jpeg') + msg.reply_image(r'wordsCnt.jpeg') + + except Exception as e: + logging.exception(e) + + # 杩涘叆 Python 鍛戒护琛屻佽绋嬪簭淇濇寔杩愯 + embed() + +if __name__ == '__main__': + main() \ No newline at end of file