File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -51,6 +51,10 @@ Python API provides access to @wiki features.
5151
5252 api = AtWikiAPI(AtWikiURI(' http://www65.atwiki.jp/python-client/' ))
5353
54+ # Show list of tags.
55+ for page in api.get_tags():
56+ print (page[' name' ])
57+
5458 # Show list of pages.
5559 for page in api.get_list():
5660 print (page[' name' ])
Original file line number Diff line number Diff line change @@ -54,6 +54,25 @@ def get_list(self, tag=None):
5454 index += 1
5555 time .sleep (self ._sleep )
5656
57+ def get_tags (self ):
58+ index = 0
59+ while True :
60+ count = 0
61+ soup = self ._request (self ._uri .tag ('' , index ))
62+ links = soup .find ('div' , attrs = {'class' : 'cmd_tag' }).select ('a.tag' )
63+ for link in links :
64+ tag_name = link .text
65+ tag_weight = 0
66+ for clazz in link .attrs ['class' ]:
67+ if clazz .startswith ('weight' ):
68+ tag_weight = int (clazz [6 :])
69+ break
70+ count += 1
71+ yield {'name' : tag_name , 'weight' : tag_weight }
72+ if count == 0 : break
73+ index += 1
74+ time .sleep (self ._sleep )
75+
5776 def get_source (self , page_id , generation = 0 ):
5877 soup = self ._request (self ._uri .backup_source (page_id , generation ))
5978 pre = soup .find ('pre' , attrs = {'class' : 'cmd_backup' })
Original file line number Diff line number Diff line change @@ -23,6 +23,12 @@ def test_get_list_tag(self):
2323 self .assertEqual (results [0 ]['id' ], 18 )
2424 self .assertEqual (results [0 ]['name' ], 'Test_atwiki.test.test_core:AtWikiAPITest:test_get_list_tag' )
2525
26+ def test_get_tags (self ):
27+ results = list (self ._api .get_tags ())
28+ self .assertEqual (len (results ), 1 )
29+ self .assertEqual (results [0 ]['name' ], 'tag01' )
30+ self .assertEqual (results [0 ]['weight' ], 3 )
31+
2632 def test_get_source (self ):
2733 self .assertEqual (self ._api .get_source (14 , 0 ),
2834 'テスト1\n テスト2\n \n テスト3\n テスト4\n \n \n テスト5' )
You can’t perform that action at this time.
0 commit comments