import pymongo,requests,time
from datetime import timedelta,date
import charts
client = pymongo.MongoClient('localhost',27017)
ganji = client['ganji']
url_list = ganji['url_list']
item_info=ganji['item_info']
def get_all_dates(date1,date2):
the_date = date(int(date1.split('.')[0]),int(date1.split('.')[1]),int(date1.split('.')[2]))
end_date = date(int(date2.split('.')[0]),int(date2.split('.')[1]),int(date2.split('.')[2]))
days=timedelta(days=1)
while the_date <= end_date:
yield the_date.strftime('%Y.%m.%d')
the_date=the_date+days
def get_all_dates(date1,date2):
the_date = date(int(date1.split('.')[0]),int(date1.split('.')[1]),int(date1.split('.')[2]))
end_date = date(int(date2.split('.')[0]),int(date2.split('.')[1]),int(date2.split('.')[2]))
days=timedelta(days=1)
while the_date <= end_date:
yield the_date.strftime('%Y.%m.%d')
the_date=the_date+days
for i in get_data_within('2015.12.30','2016.01.05',['北京二手手機','北京二手筆記本','北京二手臺式機/配件']):
print(i)
options={
'chart':{'zoomType':'xy'},
'title':{'text':'發(fā)帖統(tǒng)計量'},
'subtitle':{'text':'可視化圖表'},
'xAxis':{'categories':[i for i in get_all_dates('2015.12.24','2016.01.05')]},
'yAxis':{'title':{'text':'數(shù)量'}}
}
series=[i for i in get_data_within('2015.12.30','2016.01.05',['北京二手手機','北京二手筆記本','北京二手臺式機/配件'])]
charts.plot(series,options=options,show='inline')
學習了find的用法,下一步應當將對數(shù)據(jù)庫的操作和序列、字典的操作再加強一下
理解一下對日期的處理和對update的用法