#!/usr/bin/python
# -*- coding: UTF-8 -*-
import sys
import urllib2
import json
args = sys.argv
city = args[1]
a = "http://www.sojson.com/open/api/weather/json.shtml?city=" + city
page = urllib2.urlopen(a, timeout=10)
data = page.read()
sj = json.loads(data)
print "天气数据(今天)"
print "---------------------------------------------"
print len(data)
print "---------------------------------------------"
print '响应:'
print sj['status']
print "---------------------------------------------"
print '城市:'
print city
print '最低气温:'
print sj['data']['forecast'][0]['low']
print '最高气温:'
print sj['data']['forecast'][0]['high']
print '天气:'
print sj['data']['forecast'][0]['type']
print '建议:'
print sj['data']['ganmao']
print "---------------------------------------------"
print 'json:'
print data
#如果想要明天的就将[0]改为[1],后天以此类推,范围:0-4
#获取昨天,如最低温度:sj['yesterday']['low'],参数可以在调试中找
#数据来源:http://www.sojson.com/api/weather.html
#频繁调用会导致封禁