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?

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.