def collect_data(rowx, product, region):
    date = sheet.cell(rowx, 0).value
    price = sheet.cell(rowx, 6).value
    turnover = sheet.cell(rowx, 8).value
    # change date format from yy.mm.dd to yy-mm-dd
    date = date.replace('/', '-')
    ad_year = int(date[:3]) + 1911
    ad_date = str(ad_year) + date[3:]
    add_product_price_item(product, ad_date, region, price, turnover)
def collect_data(rowx, product, region):
    date = sheet.cell(rowx, 0).value
    price = sheet.cell(rowx, 6).value
    turnover = sheet.cell(rowx, 8).value
    # change date format from yy.mm.dd to yy-mm-dd
    date = date.replace('/', '-')
    ad_year = int(date[:3]) + 1911
    ad_date = str(ad_year) + date[3:]
    add_product_price_item(product, ad_date, region, price, turnover)
Esempio n. 3
0
info = json.loads(data)
for item in info:
    code = item['作物代號']
    product = item['作物名稱']
    date = item['交易日期']
    region = item['市場名稱']
    price = item['平均價']
    turnover = item['交易量']
    required_market, region = marketFilter(region)

    if code in product_code and required_market:
        # change date format from yy.mm.dd to yy-mm-dd
        date = date.replace('.', '-')
        ad_year = int(date[:3]) + 1911
        ad_date = str(ad_year) + date[3:]
        add_product_price_item(product_code_mapping[code], ad_date, region,
                               price, turnover)

# 自動氣象站-氣象觀測資料
url = 'http://opendata.cwb.gov.tw/opendataapi?dataid=O-A0001-001&authorizationkey=CWB-9A63F68D-76D1-4678-9514-8C5D82B7283B'
ns = {'d': 'urn:cwb:gov:tw:cwbcommon:0.1'}

root = ET.parse(urllib.request.urlopen(url)).getroot()

locations = root.findall('d:location', ns)

for location in locations:
    name = location.find('d:locationName', ns).text
    #if name == '桃園': collect_data(location, 'TAOYUAN')
    if name == '礁溪': collect_data(location, 'YILAN')
    if name == '大甲': collect_data(location, 'TAICHUNG')
    if name == '新興': collect_data(location, 'KAOHSIUNG')
Esempio n. 4
0
        'region':'TAICHUNG',
        'price': 54,
        'turnover': 87
    },
    {
        'region':'KAOHSIUNG',
        'price': 12.5,
        'turnover': 33.5
    },
    {
        'region':'TAITUNG',
        'price': 0.12,
        'turnover': 2E2
    }
]
'''
add_product_price_item(product, date, trading_datas)

# Add Weather Record Example
region = 'YILAN'
date = '2016-04-01'
temperature = 42
rainfall = 94.87
humidity = 66.66    # valid value is 0 ~ 100
add_weather_item(region, date, temperature, rainfall, humidity)

# Reteive Product Histrical Price
# There are only 2 sample product price records in database now
data = get_poduct_price_record('PONKAN', 'TAICHUNG')
print(data['product'])
print(data['region'])
Esempio n. 5
0
info = json.loads(data)
for item in info:
    code = item['作物代號']
    product = item['作物名稱']
    date = item['交易日期']
    region = item['市場名稱']
    price = item['平均價']
    turnover = item['交易量']
    required_market, region = marketFilter(region)

    if  code in product_code and required_market:
        # change date format from yy.mm.dd to yy-mm-dd
        date = date.replace('.', '-')
        ad_year = int(date[:3]) + 1911
        ad_date = str(ad_year) + date[3:]
        add_product_price_item(product_code_mapping[code], ad_date, region, price, turnover)


# 自動氣象站-氣象觀測資料
url = 'http://opendata.cwb.gov.tw/opendataapi?dataid=O-A0001-001&authorizationkey=CWB-9A63F68D-76D1-4678-9514-8C5D82B7283B'
ns = {'d': 'urn:cwb:gov:tw:cwbcommon:0.1'}

root = ET.parse(urllib.request.urlopen(url)).getroot()

locations = root.findall('d:location', ns)

for location in locations:
    name = location.find('d:locationName', ns).text
    #if name == '桃園': collect_data(location, 'TAOYUAN')
    if name == '礁溪': collect_data(location, 'YILAN')
    if name == '大甲': collect_data(location, 'TAICHUNG')
Esempio n. 6
0
    'price': 33,
    'turnover': 10.0
}, {
    'region': 'TAICHUNG',
    'price': 54,
    'turnover': 87
}, {
    'region': 'KAOHSIUNG',
    'price': 12.5,
    'turnover': 33.5
}, {
    'region': 'TAITUNG',
    'price': 0.12,
    'turnover': 2E2
}]
'''
add_product_price_item(product, date, trading_datas)

# Add Weather Record Example
region = 'YILAN'
date = '2016-04-01'
temperature = 42
rainfall = 94.87
humidity = 66.66    # valid value is 0 ~ 100
add_weather_item(region, date, temperature, rainfall, humidity)

# Reteive Product Histrical Price
# There are only 2 sample product price records in database now
data = get_poduct_price_record('PONKAN', 'TAICHUNG')
print(data['product'])
print(data['region'])
# coding=utf-8
from __future__ import print_function
from mydynamodb.utils import add_weather_item, add_product_price_item, get_poduct_price_record
from datetime import datetime, timedelta
from math import sin, cos, pi
from random import randint

my_date = datetime.strptime("2016-01-01", "%Y-%m-%d").date()
count = 0
while my_date <= datetime.now().date():
    trading_datas = [{"region": "台中", "price": sin(pi * count / 10) + 1, "turnover": cos(pi * count / 10) + 1}]
    add_product_price_item("椪柑", str(my_date), trading_datas)
    trading_datas = [{"region": "高雄", "price": randint(1, 100), "turnover": randint(1, 100)}]
    add_product_price_item("高麗菜", str(my_date), trading_datas)
    my_date += timedelta(1)
    count += 1