0

I am attempting to get a list to TOP n tags and its usage so far using python.

I can run this query on stackexchange site as below,

SELECT *
FROM Tags
WHERE ExcerptPostId is not NULL
order by Count
Desc

That gives me result as below,

Id  TagName Count   ExcerptPostId   WikiPostId
3   javascript  1538133 3624960 3607052
17  java    1360163 3624966 3607018
9   c#  1169923 3624962 3607007
5   php 1157178 3624936 3607050
1386    android 1063197 3625001 3607484
820 jquery  890140  3625262 3607053
16  python  877784  3624965 3607014
2   html    717700  3673183 3673182
10  c++ 549953  3624963 3606997
58338   ios 545753  4536664 4536663
 .......
 ....... and so on.

However, is there a way to get exact same data using python? Probably run same query using API,

I looked at stack.py , py-stackexchange , but couldnt find documantion. Any ideas?

Community
  • 1
  • 1
Anil_M
  • 10,893
  • 6
  • 47
  • 74

1 Answers1

0

Got it.

Looks like there is a tags() method available. Although looking at code , i couldnt understand attributes. However, I was able to deduce available attributes for tags() method using dir.

>>> dir(tag)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__',   
'__getattribute__', '__hash__', '__init__', '__module__', '__new__', 
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__',_sizeof__',
 '__str__', '__subclasshook__', '__weakref__', '_extend', '_up',
  'count', 'fetch', 'id', 'json', 'json_ob', 'name', 'partial', 'site',
 'synonyms', 'top_answerers', 'top_askers', 'transfer', 'wiki']
>>> 

After that it was just a matter of selecting proper attributes.
Here is the code.

import stackexchange

so = stackexchange.Site(stackexchange.StackOverflow)

#Print top 10 tags and their count
for  idx, tag in enumerate(so.tags()):
    if idx >= 10:
        break
    print("{},{}".format(tag.name , tag.count))

Result

>>> 
javascript,1540896
java,1361964
c#,1171336
php,1158685
android,1064757
jquery,891031
python,880103
html,718747
c++,550622
ios,546498
Anil_M
  • 10,893
  • 6
  • 47
  • 74