#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
Created on 2014-12-31
@author: beyondzhou
@name: json_data_text.py
'''
# Get public timeline of sina weibo and save json response data into text file
def json_data_text():
# import
from login import weibo_login
from data import save_to_text, load_from_text
# Access to sina api
weibo_api = weibo_login()
# Get public timeline
public_timeline = weibo_api.statuses.public_timeline.get(count=200)
# Output the public timeline
# print json.dumps(public_timeline, indent=1)
# Save the json data into text file
save_to_text('publicTimeline', public_timeline)
# Read the json data from text file
results = load_from_text('publicTimeline')
print results
if __name__ == '__main__':
json_data_text()
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
Created on 2014-12-31
@author: beyondzhou
@name: data.py
'''
import io, json
# Save json data into text file
def save_to_text(filename, data):
with io.open(r'e:\automation\{0}.json'.format(filename),'w', encoding='utf-8') as f:
f.write(unicode(json.dumps(data, ensure_ascii=False, indent=1)))
# Load json data from text file
def load_from_text(filename):
with io.open(r'e:\automation\{0}.json'.format(filename), encoding='utf-8') as f:
return f.read()
Results:
"thumbnail_pic": "http://ww2.sinaimg.cn/thumbnail/e64ab084gw1en83gcxf4dj20j20dr76e.jpg"
}
],
"in_reply_to_user_id": "",
"darwin_tags": [],
"favorited": false,
"original_pic": "http://ww4.sinaimg.cn/large/e64ab084gw1en83fpbam0j20ce0ddjsn.jpg",
"idstr": "3793732287449186",
"source_type": 1,
"user": {
"bi_followers_count": 5,
"domain": "",
"avatar_large": "http://tp1.sinaimg.cn/5227912516/180/5701194981/0",
"verified_source": "",
"ptype": 0,
"statuses_count": 2102,
"allow_all_comment": true,
"id": 5227912516,
"verified_reason_url": "",
"city": "1000",
"province": "100",
"credit_score": 80,
"block_app": 0,
"follow_me": false,
"verified_reason": "",
"followers_count": 77,
"location": "其他",
"verified_trade": "",
"mbtype": 0,
"verified_source_url": "",
"profile_url": "u/5227912516",
"block_word": 0,
"avatar_hd": "http://ww2.sinaimg.cn/crop.0.0.200.200.1024/005HNMRCjw1eiogrh9pubj305k05k0sn.jpg",
"star": 0,
"description": "",
"friends_count": 756,
"online_status": 0,
"mbrank": 0,
"idstr": "5227912516",
"profile_image_url": "http://tp1.sinaimg.cn/5227912516/50/5701194981/0",
"allow_all_act_msg": false,
"verified": false,
"geo_enabled": true,
"class": 1,
"screen_name": "心塞的清芬",
"lang": "zh-cn",
"weihao": "",
"remark": "",
"favourites_count": 0,
"name": "心塞的清芬",
"url": "",
"gender": "f",
"created_at": "Wed Jul 23 00:00:03 +0800 2014",
"verified_type": -1,
"following": false,
"pagefriends_count": 0,
"urank": 7
},
"geo": null,
"created_at": "Wed Dec 31 06:48:43 +0800 2014",
"mlevel": 0,
"comments_count": 0
},
{
"reposts_count": 0,
"truncated": false,
"text": "[疑问] 链 接:http://t.cn/Rzsuyk4",
"visible": {
"type": 0,
"list_id": 0
},
"in_reply_to_status_id": "",
"bmiddle_pic": "http://ww3.sinaimg.cn/bmiddle/e64ab084gw1en83w3opzrj20h30gpdi6.jpg",
"id": 3793732287449183,
"thumbnail_pic": "http://ww3.sinaimg.cn/thumbnail/e64ab084gw1en83w3opzrj20h30gpdi6.jpg",
"mid": "3793732287449183",
"source": "<a href=\"http://app.weibo.com/t/feed/63af84\" rel=\"nofollow\">vivo智能手机</a>",
"attitudes_count": 0,
"in_reply_to_screen_name": "",
"pic_urls": [
{
"thumbnail_pic": "http://ww3.sinaimg.cn/thumbnail/e64ab084gw1en83w3opzrj20h30gpdi6.jpg"
},
{
"thumbnail_pic": "http://ww1.sinaimg.cn/thumbnail/e64ab084gw1en83wnbe88j20hf0gp76i.jpg"
},
{
"thumbnail_pic": "http://ww1.sinaimg.cn/thumbnail/e64ab084gw1en83wukxkfj20d10g8whb.jpg"
},
{
"thumbnail_pic": "http://ww2.sinaimg.cn/thumbnail/e64ab084gw1en83wj3kp6j20hj0gngnp.jpg"
},
{
"thumbnail_pic": "http://ww4.sinaimg.cn/thumbnail/e64ab084gw1en83xwi982j20nk0fg41c.jpg"
},
{
"thumbnail_pic": "http://ww2.sinaimg.cn/thumbnail/e64ab084gw1en83x808ioj20f30g4tb7.jpg"
},
{
"thumbnail_pic": "http://ww3.sinaimg.cn/thumbnail/e64ab084gw1en83y36nhyj20q50gqgov.jpg"
},
{
"thumbnail_pic": "http://ww3.sinaimg.cn/thumbnail/e64ab084gw1en83yys1klj20f70g8ad6.jpg"
},
{
"thumbnail_pic": "http://ww2.sinaimg.cn/thumbnail/e64ab084gw1en83y7ezamj20q80ggwhc.jpg"
}
],
"in_reply_to_user_id": "",
"darwin_tags": [],
"favorited": false,
"original_pic": "http://ww3.sinaimg.cn/large/e64ab084gw1en83w3opzrj20h30gpdi6.jpg",
"idstr": "3793732287449183",
"source_type": 1,
"user": {
"bi_followers_count": 4,
"domain": "",
"avatar_large": "http://tp4.sinaimg.cn/5139153839/180/5694951290/0",
"verified_source": "",
"ptype": 0,
"statuses_count": 2260,
"allow_all_comment": true,
"id": 5139153839,
"verified_reason_url": "",
"city": "1000",
"province": "11",
"credit_score": 80,
"block_app": 0,
"follow_me": false,
"verified_reason": "",
"followers_count": 98,
"location": "北京",
"verified_trade": "",
"mbtype": 0,
"verified_source_url": "",
"profile_url": "u/5139153839",
"block_word": 0,
"avatar_hd": "http://ww3.sinaimg.cn/crop.0.0.200.200.1024/005BNmG3jw1egcx4btt6yj305k05k0sn.jpg",
"star": 0,
"description": "",
"friends_count": 404,
"online_status": 0,
"mbrank": 0,
"idstr": "5139153839",
"profile_image_url": "http://tp4.sinaimg.cn/5139153839/50/5694951290/0",
"allow_all_act_msg": false,
"verified": false,
"geo_enabled": true,
"class": 1,
"screen_name": "屋檐下的映秋",
"lang": "zh-cn",
"weihao": "",
"remark": "",
"favourites_count": 0,
"name": "屋檐下的映秋",
"url": "",
"gender": "f",
"created_at": "Sat May 10 17:11:02 +0800 2014",
"verified_type": -1,
"following": false,
"pagefriends_count": 0,
"urank": 7
},
"geo": null,
"created_at": "Wed Dec 31 06:48:43 +0800 2014",
"mlevel": 0,
"comments_count": 0
},
{
"reposts_count": 0,
"truncated": false,
"text": "[xb拇指]BJJ蕾丝控|地址:http://t.cn/R7k8xJ4",
"visible": {
"type": 0,
"list_id": 0
},
"in_reply_to_status_id": "",
"bmiddle_pic": "http://ww2.sinaimg.cn/bmiddle/005yfBQ0tw1elld01wn1sj30ir0j4q62.jpg",
"id": 3793732287449181,
"thumbnail_pic": "http://ww2.sinaimg.cn/thumbnail/005yfBQ0tw1elld01wn1sj30ir0j4q62.jpg",
"mid": "3793732287449181",
"source": "<a href=\"http://app.weibo.com/t/feed/6pwitf\" rel=\"nofollow\">360安全平台</a>",
"attitudes_count": 0,
"in_reply_to_screen_name": "",
"pic_urls": [
{
"thumbnail_pic": "http://ww2.sinaimg.cn/thumbnail/005yfBQ0tw1elld01wn1sj30ir0j4q62.jpg"
},
{
"thumbnail_pic": "http://ww3.sinaimg.cn/thumbnail/005yfBQ0tw1elld02bb3gj30iy0jbwim.jpg"
},
{
"thumbnail_pic": "http://ww2.sinaimg.cn/thumbnail/005yfBQ0tw1elld031ebej30ia0jaaej.jpg"
},
{
"thumbnail_pic": "http://ww4.sinaimg.cn/thumbnail/005yfBQ0tw1elld03d7c3j30gs0gv0uy.jpg"
},
{
"thumbnail_pic": "http://ww2.sinaimg.cn/thumbnail/005yfBQ0tw1elld03pfohj30il0jcjuw.jpg"
},
{
"thumbnail_pic": "http://ww2.sinaimg.cn/thumbnail/005yfBQ0tw1elld047lvnj30ja0j977m.jpg"
},
{
"thumbnail_pic": "http://ww1.sinaimg.cn/thumbnail/005yfBQ0tw1elld04lymcj30k10jpjui.jpg"
},
{
"thumbnail_pic": "http://ww3.sinaimg.cn/thumbnail/005yfBQ0tw1elld04z7dqj30je0jdjug.jpg"
},
{
"thumbnail_pic": "http://ww2.sinaimg.cn/thumbnail/005yfBQ0tw1elld05f1arj30f50ju42o.jpg"
}
],
"in_reply_to_user_id": "",
"darwin_tags": [],
"favorited": false,
"original_pic": "http://ww2.sinaimg.cn/large/005yfBQ0tw1elld01wn1sj30ir0j4q62.jpg",
"idstr": "3793732287449181",
"source_type": 1,
"user": {
"bi_followers_count": 166,
"domain": "",
"avatar_large": "http://tp1.sinaimg.cn/5090794692/180/5691298848/0",
"verified_source": "",
"ptype": 0,
"statuses_count": 4925,
"allow_all_comment": true,
"id": 5090794692,
"verified_reason_url": "",
"city": "10",
"province": "36",
"credit_score": 80,
"block_app": 0,
"follow_me": false,
"verified_reason": "",
"followers_count": 261,
"location": "江西 抚州",
"verified_trade": "",
"mbtype": 0,
"verified_source_url": "",
"profile_url": "u/5090794692",
"block_word": 0,
"avatar_hd": "http://ww3.sinaimg.cn/crop.0.0.200.200.1024/005ywsfOjw1ef01pe98t3j305k05kgm5.jpg",
"star": 0,
"description": "",
"friends_count": 1884,
"online_status": 0,
"mbrank": 0,
"idstr": "5090794692",
"profile_image_url": "http://tp1.sinaimg.cn/5090794692/50/5691298848/0",
"allow_all_act_msg": false,
"verified": false,
"geo_enabled": true,
"class": 1,
"screen_name": "_癲宅師妹_",
"lang": "zh-cn",
"weihao": "",
"remark": "",
"favourites_count": 0,
"name": "_癲宅師妹_",
"url": "",
"gender": "f",
"created_at": "Thu Mar 27 22:36:54 +0800 2014",
"verified_type": -1,
"following": false,
"pagefriends_count": 0,
"urank": 9
},
"geo": null,
"created_at": "Wed Dec 31 06:48:43 +0800 2014",
"mlevel": 0,
"comments_count": 0
},
{
"darwin_tags": [],
"favorited": false,
"source_type": 1,
"mid": "3793732287170614",
"in_reply_to_user_id": "",
"source": "<a href=\"http://app.weibo.com/t/feed/e0WUS\" rel=\"nofollow\">微博桌面</a>",
"text": "当面对两个选择时,抛硬币总能奏效,并不是因为它总能给出对的答案,而是在你把它抛在空中的那一秒里,你突然知道你希望它是什么……",
"created_at": "Wed Dec 31 06:48:44 +0800 2014",
"truncated": false,
"reposts_count": 0,
"idstr": "3793732287170614",
"visible": {
"type": 0,
"list_id": 0
},
"attitudes_count": 0,
"pic_urls": [],
"in_reply_to_screen_name": "",
"user": {
"bi_followers_count": 34,
"domain": "",
"avatar_large": "http://tp4.sinaimg.cn/1780921711/180/40015781273/0",
"verified_source": "",
"ptype": 0,
"statuses_count": 1846,
"allow_all_comment": true,
"id": 1780921711,
"verified_reason_url": "",
"city": "1",
"province": "32",
"credit_score": 80,
"block_app": 0,
"follow_me": false,
"verified_reason": "",
"followers_count": 159,
"location": "江苏 南京",
"verified_trade": "",
"mbtype": 0,
"verified_source_url": "",
"profile_url": "u/1780921711",
"block_word": 0,
"avatar_hd": "http://tp4.sinaimg.cn/1780921711/180/40015781273/0",
"star": 0,
"description": "我是希瑞~瘦瘦的希瑞~~",
"friends_count": 789,
"online_status": 1,
"mbrank": 0,
"idstr": "1780921711",
"profile_image_url": "http://tp4.sinaimg.cn/1780921711/50/40015781273/0",
"allow_all_act_msg": true,
"verified": false,
"geo_enabled": true,
"class": 1,
"screen_name": "frandasusu",
"lang": "zh-cn",
"weihao": "",
"remark": "",
"favourites_count": 0,
"name": "frandasusu",
"url": "",
"gender": "f",
"created_at": "Wed Jul 21 17:18:23 +0800 2010",
"verified_type": -1,
"following": false,
"pagefriends_count": 0,
"urank": 13
},
"in_reply_to_status_id": "",
"comments_count": 0,
"geo": null,
"id": 3793732287170614,
"mlevel": 0
},
{
"reposts_count": 0,
"truncated": false,
"text": "我们有时会错误地以为,得不到的,才是珍贵的,已经拥有的,都是廉价的。得不到的,因为缺少深入的了解,它只是一种美好的假象,展示给我们一个绚丽的外表。如果有那么一天,你距离它近了,知道了它的真相,你才发现,它和我们拥有的,竟是那么的相似。别把眼光停留在想象中,你拥有的都是你的幸福。",
"visible": {
"type": 0,
"list_id": 0
},
"in_reply_to_status_id": "",
"bmiddle_pic": "http://ww3.sinaimg.cn/bmiddle/5de52038tw1drgwukzbi9g.gif",
"id": 3793732287170384,
"thumbnail_pic": "http://ww3.sinaimg.cn/thumbnail/5de52038tw1drgwukzbi9g.gif",
"mid": "3793732287170384",
"source": "<a href=\"http://weibo.com/\" rel=\"nofollow\">微博 weibo.com</a>",
"attitudes_count": 0,
"in_reply_to_screen_name": "",
"pic_urls": [
{
"thumbnail_pic": "http://ww3.sinaimg.cn/thumbnail/5de52038tw1drgwukzbi9g.gif"
}
],
"in_reply_to_user_id": "",
"darwin_tags": [],
"favorited": false,
"original_pic": "http://ww3.sinaimg.cn/large/5de52038tw1drgwukzbi9g.gif",
"idstr": "3793732287170384",
"source_type": 1,
"user": {
"bi_followers_count": 2,
"domain": "",
"avatar_large": "http://tp3.sinaimg.cn/2577836174/180/5714946997/1",
"verified_source": "",
"ptype": 0,
"cover_image_phone": "http://ww3.sinaimg.cn/crop.0.0.640.640.640/a1d3feabjw1eca1ktsx9tj20hs0hsjtk.jpg",
"statuses_count": 27,
"id": 2577836174,
"verified_reason_url": "",
"city": "1",
"verified": false,
"credit_score": 80,
"block_app": 0,
"follow_me": false,
"verified_reason": "",
"followers_count": 25,
"location": "浙江 杭州",
"verified_trade": "",
"mbtype": 0,
"verified_source_url": "",
"profile_url": "u/2577836174",
"block_word": 0,
"avatar_hd": "http://ww1.sinaimg.cn/crop.0.0.200.200.1024/99a6a88ejw1ensh8gv23uj205k05k3yw.jpg",
"star": 0,
"description": "为了追老袁围脖而来",
"friends_count": 1276,
"online_status": 0,
"mbrank": 0,
"idstr": "2577836174",
"profile_image_url": "http://tp3.sinaimg.cn/2577836174/50/5714946997/1",
"allow_all_act_msg": false,
"allow_all_comment": true,
"geo_enabled": true,
"class": 1,
"screen_name": "白米饭的小屋Gary",
"lang": "zh-cn",
"weihao": "",
"remark": "",
"favourites_count": 0,
"name": "白米饭的小屋Gary",
"url": "",
"province": "33",
"created_at": "Thu Dec 01 21:48:05 +0800 2011",
"verified_type": -1,
"gender": "m",
"following": false,
"pagefriends_count": 0,
"urank": 4
},
"geo": null,
"created_at": "Wed Dec 31 06:48:44 +0800 2014",
"mlevel": 0,
"comments_count": 0
},
{
"darwin_tags": [],
"favorited": false,
"source_type": 1,
"mid": "3793732287170326",
"in_reply_to_user_id": "",
"source": "<a href=\"http://weibo.com/\" rel=\"nofollow\">微博 weibo.com</a>",
"text": "【日式照烧鸡排】原料:鸡腿,盐 日式米酒(清酒) 味霖、日式酱油 糖。做法:1、 鸡腿剔去骨头。2、 鸡腿内加入一点点盐抓匀,腌制一会儿。3、锅内加热少许油,放入鸡腿煎至两面金黄。4、调入一勺味霖和一勺米酒。5、调入一勺酱油。6、调入一勺糖,加入适量水焖煮至汤汁浓稠即可。",
"created_at": "Wed Dec 31 06:48:44 +0800 2014",
"truncated": false,
"reposts_count": 0,
"idstr": "3793732287170326",
"visible": {
"type": 0,
"list_id": 0
},
"attitudes_count": 0,
"pic_urls": [],
"in_reply_to_screen_name": "",
"user": {
"bi_followers_count": 2,
"domain": "",
"avatar_large": "http://tp2.sinaimg.cn/2719159921/180/5630592615/1",
"verified_source": "",
"ptype": 0,
"statuses_count": 139,
"allow_all_comment": true,
"id": 2719159921,
"verified_reason_url": "",
"city": "2",
"province": "400",
"credit_score": 80,
"block_app": 0,
"follow_me": false,
"verified_reason": "",
"followers_count": 226,
"location": "海外 英国",
"verified_trade": "",
"mbtype": 0,
"verified_source_url": "",
"profile_url": "u/2719159921",
"block_word": 0,
"avatar_hd": "http://tp2.sinaimg.cn/2719159921/180/5630592615/1",
"star": 0,
"description": "时间是世界上的一切成就的土壤时间给空想者痛苦,给创造者幸福",
"friends_count": 1660,
"online_status": 0,
"mbrank": 0,
"idstr": "2719159921",
"profile_image_url": "http://tp2.sinaimg.cn/2719159921/50/5630592615/1",
"allow_all_act_msg": false,
"verified": false,
"geo_enabled": true,
"class": 1,
"screen_name": "淘气巍巍wan",
"lang": "zh-cn",
"weihao": "",
"remark": "",
"favourites_count": 0,
"name": "淘气巍巍wan",
"url": "",
"gender": "m",
"created_at": "Tue Apr 24 06:09:03 +0800 2012",
"verified_type": -1,
"following": false,
"pagefriends_count": 0,
"urank": 2
},
"in_reply_to_status_id": "",
"comments_count": 0,
"geo": null,
"id": 3793732287170326,
"mlevel": 0
},
{
"reposts_count": 0,
"truncated": false,
"text": "#奔跑吧2015# 看@浙江卫视跨年演唱会 ,送@快的打车 #一亿跨年红包#!要的点这里:http://t.cn/RZyixKw ",
"visible": {
"type": 0,
"list_id": 0
},
"in_reply_to_status_id": "",
"bmiddle_pic": "http://ww3.sinaimg.cn/bmiddle/9e5bfd15jw1ensh8ut1umj20hs08wdiy.jpg",
"id": 3793732283736263,
"thumbnail_pic": "http://ww3.sinaimg.cn/thumbnail/9e5bfd15jw1ensh8ut1umj20hs08wdiy.jpg",
"mid": "3793732283736263",
"source": "<a href=\"http://app.weibo.com/t/feed/161rFY\" rel=\"nofollow\">快的打车</a>",
"attitudes_count": 0,
"in_reply_to_screen_name": "",
"pic_urls": [
{
"thumbnail_pic": "http://ww3.sinaimg.cn/thumbnail/9e5bfd15jw1ensh8ut1umj20hs08wdiy.jpg"
}
],
"in_reply_to_user_id": "",
"darwin_tags": [],
"favorited": false,
"original_pic": "http://ww3.sinaimg.cn/large/9e5bfd15jw1ensh8ut1umj20hs08wdiy.jpg",
"idstr": "3793732283736263",
"source_type": 1,
"user": {
"bi_followers_count": 13,
"domain": "",
"avatar_large": "http://tp2.sinaimg.cn/2656828693/180/5697984980/0",
"verified_source": "",
"ptype": 0,
"cover_image_phone": "http://ww4.sinaimg.cn/crop.0.0.640.640.640/6ce2240djw1e9h12z57plj20hs0hsadi.jpg",
"statuses_count": 362,
"id": 2656828693,
"verified_reason_url": "",
"city": "1000",
"verified": false,
"credit_score": 80,
"block_app": 1,
"follow_me": false,
"verified_reason": "",
"followers_count": 107,
"location": "上海",
"verified_trade": "",
"mbtype": 13,
"verified_source_url": "",
"profile_url": "u/2656828693",
"block_word": 0,
"avatar_hd": "http://ww4.sinaimg.cn/crop.0.0.641.641.1024/9e5bfd15jw8ehhih5joi2j20ht0ht3ze.jpg",
"star": 0,
"description": "",
"friends_count": 722,
"online_status": 1,
"mbrank": 5,
"idstr": "2656828693",
"profile_image_url": "http://tp2.sinaimg.cn/2656828693/50/5697984980/0",
"allow_all_act_msg": false,
"allow_all_comment": true,
"geo_enabled": true,
"class": 1,
"screen_name": "梦歌哥",
"lang": "zh-cn",
"weihao": "",
"remark": "",
"favourites_count": 161,
"name": "梦歌哥",
"url": &