def build(): _config = config.get('WeChat', None) _wechat = WeChat(_config) docs = list() ret = _wechat.getMaterialsList('news', get_all=True) media_list = list() for item in ret['item']: news_item = item['content']['news_item'][0] media_list.append(news_item['thumb_media_id']) doc = dict( thumb_media_id = news_item['thumb_media_id'], title = '%s' % (news_item['title']), url = news_item['url'], show_cover_pic = news_item['show_cover_pic'], cover_pic_url = fill_pic_url(news_item['thumb_media_id']), summary = '%s' % (news_item['digest']), content = '%s' % (news_item['content']), update_time = datetime.fromtimestamp(item['update_time']), content_source_url = news_item['content_source_url'], ) docs.append(doc) create_index(docs, indexdir=_config['INDEX_DIR']) print "=" * 20 print "Finished creating index." print generate_download_shell(_wechat.getAccessToken(), media_list)
# -*- coding: utf-8 -*- from config import config from wechat import WeChat _config = config.get('WeChat', None) if __name__ == '__main__': _wechat = WeChat(_config) ret = _wechat.getMaterialsList('news', get_all=True) media_id = ret['item'][20]['content']['news_item'][0]['thumb_media_id'] ret = _wechat.getMaterial(media_id) with open('a.jpg', 'w+') as f: f.write(str(ret)) f.close()