データはpythonを使用してweibo apiを呼び出す
15989 ワード
この文章では、主にデータが戻ってきた内容を紹介します.
参照コードソース:https://github.com/michaelliao/sinaweibopy/blob/master/weibo.py
毎日同じ理屈
過ぎ去った日は枯れた枯れ葉と花びらのように、だんだん遠くなっていくのは青春の純情とロマンだ.どれだけの雨が胸の前に漂って風が耳元に鳴ったか覚えていないが、世の移り変わりがとっくに私の心に入って私の顔に登ったことを知っているだけだ.一人で同業者を追求すると、数奇なのは伴で、苦難も伴である.
女性編にはWindowsが優れているが、セキュリティ上の危険性が大きすぎる女性もいる.MFCの女の人がいます.彼女は条件がいいですが、誰でも游ぶことができるわけではありません.ある女性はC#がきれいですが、家事ができません.ある女性はC++で、彼女は黙ってあなたのために多くのことをします.ある女性はアセンブリが面倒だが、時にはそれを求めなければならない.ある女性はSQLで、彼女はあなたの発展に大きな助けをもたらします.
参照コードソース:https://github.com/michaelliao/sinaweibopy/blob/master/weibo.py
毎日同じ理屈
過ぎ去った日は枯れた枯れ葉と花びらのように、だんだん遠くなっていくのは青春の純情とロマンだ.どれだけの雨が胸の前に漂って風が耳元に鳴ったか覚えていないが、世の移り変わりがとっくに私の心に入って私の顔に登ったことを知っているだけだ.一人で同業者を追求すると、数奇なのは伴で、苦難も伴である.
1 python weibo api
2
3 # url api http://open.weibo.com/wiki/2/users/show
4 the_url = 'https://api.weibo.com/2/users/show.json?uid=105729xxxx&access_token=2.xxx__YJBzk8g4Ddfd33f10237XXXXX'
5
6 http_body = None
7
8 # html , json , repr()
9 req = urllib2.Request(the_url, data=http_body)
10
11 # , html , repr()
12 req = urllib2.Request("http://www.baidu.com", data=http_body)
13
14 resp = urllib2.urlopen(req)
15 print repr(resp.read())
16
17
18
19 import json
20 # json
21 json.loads(resp.read(), object_hook=_obj_hook)
22
23
24 io = StringIO('["streaming API"]')
25 print io.getvalue()
26 # ["streaming API"] io StringIO <cStringIO.StringI object at 0x1006aed80>
27
28 # json load loads2
29 json.load(fp[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, object_pairs_hook[, **kw]]]]]]]])
30
31 json.loads(s[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, object_pairs_hook[, **kw]]]]]]]])
32
33 fp [http://docs.python.org/2/glossary.html#term-file-object] , .read(),.write() , StringIO
34 s str unicode, json python
35
36 [http://docs.python.org/2/library/json.html?highlight=object_hook#json-to-py-table]
37 JSON Python
38 object dict
39 array list
40 string unicode
41 number (int) int, long
42 number (real) float
43 true True
44 false False
45 null None
46
47 # json
48 json
49 {
50 "ip_limit": 1000,
51 "limit_time_unit": "HOURS",
52 "remaining_ip_hits": 1000,
53 "remaining_user_hits": 146,
54 "reset_time": "2013-04-19 15:00:00",
55 "reset_time_in_seconds": 3286,
56 "user_limit": 150
57 }
58 # object_hook json.loads dict,
59 # json.loads dict "abc" ,
60 # object_hook dict "abc"
61 # try catch None
62
63 def _parse_json(s):
64 ' parse str into JsonDict '
65
66 def _obj_hook(pairs):
67 ' convert json object to python object '
68 o = JsonDict()
69 # print pairs['list_id']
70 print 'text' in pairs
71 if 'text' in pairs:
72 # it can output utf8
73 print pairs['text']
74 # ---
75 for k, v in pairs.iteritems():
76 o[str(k)] = v
77 return o
78 #loads is different from load
79 return json.loads(s, object_hook=_obj_hook)
80
81 class JsonDict(dict):
82 ' general json object that allows attributes to be bound to and also behaves like a dict '
83
84 def __getattr__(self, attr):
85 try:
86 return self[attr]
87 except KeyError:
88 raise AttributeError(r"'JsonDict' object has no attribute '%s'" % attr)
89
90 def __setattr__(self, attr, value):
91 self[attr] = value
92
93 # JsonDict dict( ) __getattr__ __setattr__
94
95 # dict JsonDict 2
96 d1 = JsonDict();
97
98 d1['a'] = 'strra'
99 print d1['a']
100 print d1.get('a')
101 # aaaa dict
102 print d1.get('aaaa') # None
103 print d1['aaaa'] # key error~
104
105 # get dict error None
女性編にはWindowsが優れているが、セキュリティ上の危険性が大きすぎる女性もいる.MFCの女の人がいます.彼女は条件がいいですが、誰でも游ぶことができるわけではありません.ある女性はC#がきれいですが、家事ができません.ある女性はC++で、彼女は黙ってあなたのために多くのことをします.ある女性はアセンブリが面倒だが、時にはそれを求めなければならない.ある女性はSQLで、彼女はあなたの発展に大きな助けをもたらします.