diff --git a/Unit01/examples/pokemon.py b/Unit01/examples/pokemon.py index aea1f50..7f01b42 100644 --- a/Unit01/examples/pokemon.py +++ b/Unit01/examples/pokemon.py @@ -2,6 +2,7 @@ def fight(ch): c_choice = random.randint(0, 2) # 0 - 2 (0, 1, 2 隨機數) + print(c_choice) if ch == 0: print('你派了妙蛙種子') if c_choice == 0: @@ -28,15 +29,15 @@ def fight(ch): print('對方派出傑尼龜,平分秋色!') def start(): - return int(input('請選擇是否進行對戰? 0.開始對戰 1. 走為上策')) + return int(input('請選擇是否進行對戰 XDDB? 0.開始對戰 1. 走為上策')) command = start() +print('outer', command) + while command != 1: - if command == 0: - choice = int(input('請問你要派哪隻神奇寶貝呢?0. 妙蛙種子 1.小火龍 2. 傑尼龜')) - fight(choice) - command = start() - else: - command = start() + choice = int(input('請問你要派哪隻神奇寶貝呢?0. 妙蛙種子 1.小火龍 2. 傑尼龜')) + fight(choice) + command = start() -print('遊戲結束') \ No newline at end of file +print('遊戲結束') + diff --git a/Unit08/examples/YoutubeDownloader/index.py b/Unit08/examples/YoutubeDownloader/index.py index 391b7e9..b766aff 100644 --- a/Unit08/examples/YoutubeDownloader/index.py +++ b/Unit08/examples/YoutubeDownloader/index.py @@ -14,7 +14,7 @@ def post_submit(): url = request.form.get('url') yt.url = url video = yt.get('mp4', '360p') - video.download('./') + video.download('./', force_overwrite=True) filename = yt.filename print(yt) print(yt.filename) diff --git a/Unit09/examples/Gossiping/gossiping.py b/Unit09/examples/Gossiping/gossiping.py index e239142..5cc7d24 100644 --- a/Unit09/examples/Gossiping/gossiping.py +++ b/Unit09/examples/Gossiping/gossiping.py @@ -19,11 +19,12 @@ rs.post('https://www.ptt.cc/ask/over18', data=payload, headers=headers) res = rs.get('https://www.ptt.cc/bbs/Gossiping/index.html', headers=headers) - soup = BeautifulSoup(res.text, 'html.parser') items = soup.select('.r-ent') +print(type(items[0])) for item in items: #print('日期 {}'.format(item.select('.data')[0].text)) - print(item.select('.date')[0].text, item.select('.author')[0].text, item.select('.title')[0].text) \ No newline at end of file + #print(item.select('.date')[0].text, item.select('.author')[0].text, item.select('.title')[0].text) + pass \ No newline at end of file diff --git a/Unit10/examples/Finance/2015_tse_2317.csv b/Unit10/examples/Finance/2015_tse_2317.csv index 12c854d..4827fc7 100644 --- a/Unit10/examples/Finance/2015_tse_2317.csv +++ b/Unit10/examples/Finance/2015_tse_2317.csv @@ -491,3 +491,107 @@ 104/12/29,8.57,5.33,1.33 104/12/30,8.59,5.32,1.33 104/12/31,8.58,5.32,1.33 +104/01/07,10.83,3.52,1.46 +104/01/08,11.04,3.45,1.49 +104/01/09,10.99,3.47,1.49 +104/01/12,10.89,3.5,1.47 +104/01/13,10.97,3.48,1.48 +104/01/14,10.84,3.52,1.47 +104/01/15,10.78,3.54,1.46 +104/01/16,10.69,3.57,1.44 +104/01/19,10.64,3.58,1.44 +104/01/20,10.76,3.54,1.46 +104/01/21,10.84,3.52,1.47 +104/01/22,10.86,3.51,1.47 +104/01/23,11.16,3.42,1.51 +104/01/26,11.28,3.38,1.53 +104/01/27,11.28,3.38,1.53 +104/01/28,11.17,3.41,1.51 +104/01/29,11.02,3.46,1.49 +104/01/30,11.02,3.46,1.49 +104/02/04,11.12,3.43,1.5 +104/02/05,11.09,3.44,1.5 +104/02/06,11.09,3.44,1.5 +104/02/09,11.05,3.45,1.49 +104/02/10,10.86,3.51,1.47 +104/02/11,10.78,3.54,1.46 +104/02/12,10.95,3.48,1.48 +104/02/13,10.9,3.5,1.47 +104/02/24,10.9,3.5,1.47 +104/02/25,10.97,3.48,1.48 +104/02/26,11.07,3.44,1.5 +104/03/04,11.22,3.4,1.52 +104/03/05,11.25,3.39,1.52 +104/03/06,11.28,3.38,1.53 +104/03/09,11.16,3.42,1.51 +104/03/10,11.07,3.44,1.5 +104/03/11,11.09,3.44,1.5 +104/03/12,11.07,3.44,1.5 +104/03/13,11.18,3.41,1.51 +104/03/16,11.09,3.44,1.5 +104/03/17,11.09,3.44,1.5 +104/03/18,11.17,3.41,1.51 +104/03/19,11.58,3.29,1.57 +104/03/20,11.82,3.23,1.6 +104/03/23,11.88,3.21,1.61 +104/03/24,11.86,3.22,1.6 +104/03/25,11.99,3.18,1.62 +104/03/26,11.99,3.18,1.62 +104/03/27,11.82,3.23,1.6 +104/03/30,11.94,3.19,1.61 +104/03/31,11.64,3.28,1.46 +104/04/07,10.6,3.21,1.49 +104/04/08,10.61,3.2,1.49 +104/04/09,10.53,3.23,1.48 +104/04/10,10.54,3.22,1.48 +104/04/13,10.52,3.23,1.48 +104/04/14,10.62,3.2,1.49 +104/04/15,10.43,3.26,1.46 +104/04/16,10.57,3.22,1.48 +104/04/17,10.45,3.25,1.47 +104/04/20,10.51,3.23,1.48 +104/04/21,10.43,3.26,1.46 +104/04/22,10.42,3.26,1.46 +104/04/23,10.57,3.22,1.48 +104/04/24,10.71,3.17,1.5 +104/04/27,10.72,3.17,1.51 +104/04/28,10.6,3.21,1.49 +104/04/29,10.43,3.26,1.46 +104/04/30,10.42,3.26,1.46 +104/05/06,10.53,3.23,1.48 +104/05/07,10.43,3.26,1.46 +104/05/08,10.5,3.24,1.47 +104/05/11,10.55,3.22,1.48 +104/05/12,10.5,3.24,1.47 +104/05/13,10.7,3.17,1.5 +104/05/14,10.61,3.2,1.49 +104/05/15,10.54,3.22,1.46 +104/05/18,10.13,3.1,1.51 +104/05/19,10.29,3.05,1.54 +104/05/20,10.2,4.41,1.52 +104/05/21,10.15,4.43,1.52 +104/05/22,10.09,4.46,1.51 +104/05/25,10.14,4.44,1.52 +104/05/26,10.19,4.41,1.52 +104/05/27,10.19,4.41,1.52 +104/05/28,10.28,4.37,1.54 +104/05/29,10.37,4.34,1.55 +104/06/03,10.15,4.43,1.52 +104/06/04,9.88,4.55,1.48 +104/06/05,9.86,4.56,1.47 +104/06/08,9.93,4.53,1.48 +104/06/09,9.75,4.61,1.46 +104/06/10,10.0,4.5,1.49 +104/06/11,10.02,4.49,1.5 +104/06/12,9.94,4.53,1.49 +104/06/15,9.83,4.57,1.47 +104/06/16,9.92,4.54,1.48 +104/06/17,9.87,4.56,1.48 +104/06/18,9.9,4.55,1.48 +104/06/22,10.17,4.42,1.52 +104/06/23,10.16,4.43,1.52 +104/06/24,10.21,4.41,1.53 +104/06/25,10.36,4.34,1.55 +104/06/26,10.38,4.33,1.55 +104/06/29,10.14,4.44,1.52 +104/06/30,10.15,4.43,1.52 diff --git a/Unit10/examples/Finance/stock.py b/Unit10/examples/Finance/stock.py index 8e45ca0..7e603cc 100644 --- a/Unit10/examples/Finance/stock.py +++ b/Unit10/examples/Finance/stock.py @@ -2,45 +2,24 @@ from bs4 import BeautifulSoup import pandas as pd import time +import json -url = 'http://www.twse.com.tw/ch/trading/exchange/BWIBBU/BWIBBU.php' def parseTSE(year, month, no): - year = str(year) - month = str(month) - no = str(no) - - payload = { - 'query_year': year, - 'query_month': month, - 'CO_ID':no, - 'query-button': '查詢' - } + print(year, month, no) + url = 'http://www.twse.com.tw/exchangeReport/BWIBBU?response=json&date=20170501&stockNo=2880&_=1496411050617' headers = { 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36' } - res = requests.post(url, headers=headers, data=payload) + res = requests.post(url, headers=headers) data = res.text - soup = BeautifulSoup(data, 'html.parser') - - content = soup.select('table')[0] - - with open('./' + year + month + '_tse_' + no + '.html', 'w') as f: - f.write(str(content)) - - table = pd.read_html('./' + year + month + '_tse_' + no + '.html', encoding='utf-8')[0] - table = table.drop(table.index[0:2]) - #print(table) - print(table.to_csv(header=False, index=False)) - with open('./' + year + '_tse_' + no + '.csv', 'a') as f: - f.write(str(table.to_csv(header=False, index=False))) - #print(content) + print(json.loads(data)['data']) for m in range(1, 13): # [1, 2, 3... 12] time.sleep(5) - parseTSE(2015, m, 2317) + parseTSE(2015, m, 2880) \ No newline at end of file diff --git a/Unit22/examples/opencook/recipe/migrations/0009_recipe_lable.py b/Unit22/examples/opencook/recipe/migrations/0009_recipe_lable.py new file mode 100644 index 0000000..74599cd --- /dev/null +++ b/Unit22/examples/opencook/recipe/migrations/0009_recipe_lable.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2017-05-22 22:40 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('recipe', '0008_auto_20170326_1216'), + ] + + operations = [ + migrations.AddField( + model_name='recipe', + name='lable', + field=models.TextField(default='Test default'), + ), + ] diff --git a/Unit22/examples/opencook/recipe/models.py b/Unit22/examples/opencook/recipe/models.py index 7408116..9f76b9f 100644 --- a/Unit22/examples/opencook/recipe/models.py +++ b/Unit22/examples/opencook/recipe/models.py @@ -6,6 +6,7 @@ class Recipe(models.Model): title = models.CharField(max_length=100) image_path = models.CharField(max_length=100) description = models.TextField() + lable = models.TextField(default="default test value") created_at = models.DateTimeField(default=timezone.now) # def __unicode__(self):