def getComments(self):
        user_id = 41983 if len(sys.argv) < 2 else int(sys.argv[1])
        print('StackOverflow user %d\'s accounts:' % user_id)

        stack_auth = StackAuth()
        so = Site(StackOverflow)
        accounts = stack_auth.associated(so, user_id)
        reputation = {}

        for q in so.questions(tagged=['java', 'javascript', 'python', 'html'],
                              pagesize=50):
            print(q.tags)

        print(so.all_tag_badges().items)
Beispiel #2
0
def GetQuestion():
    qid = vim.eval('a:question_id')
    site = Site(StackOverflow, None, impose_throttling=True)
    site.be_inclusive()
    vob = GetVOBuffer()
    question = site.question(qid)
    if vob:
        vob.options["textwidth"] = 0
        GetQuestionTitle(site, question, vob)
        vob.append("\n")
        GetQuestionBody(site, question, vob)
        vob.options["readonly"] = True
        vob.append("\n")
        vob.append("«")
        vob.append("\n")
Beispiel #3
0
def get_accept_rate(user_id=246246):

    #print 'StackOverflow user %d\'s experience:' % user_id

    so = Site(StackOverflow)
    user = so.user(user_id)

    #print 'Total badge count : %s'% user.badge_total
    global_sof_json['badges'] = user.badge_total
    global_sof_json['age'] = user.age
    global_sof_json['location'] = user.location
    global_sof_json['website'] = user.webiste_url

    if len(user.top_answer_tags.fetch()) > 0:
        global_sof_json['experienced'] = user.top_answer_tags.fetch()[0].tag_name

    #print 'Most experienced on %s.' % user.top_answer_tags.fetch()[0].tag_name
    #print 'Most curious about %s.' % user.top_question_tags.fetch()[0].tag_name

    total_questions = len(user.questions.fetch())
    unaccepted_questions = len(user.unaccepted_questions.fetch())
    accepted = total_questions - unaccepted_questions
    rate = accepted / float(total_questions) * 100
    global_sof_json['accept_rate'] = format(rate, '.2f')
Beispiel #4
0
def get_reputation(user_id=1537881):
    '''
    :param user_id:
    :return:
    '''

    #print 'StackOverflow user %d\'s accounts:' % user_id
    global_sof_json['uid'] = user_id

    stack_auth = StackAuth()
    so = Site(StackOverflow)
    accounts = stack_auth.associated(so, user_id)
    reputation = {}

    for account in accounts:
        #print '%s / %d reputation' % ( account.on_site.name, account.reputation)
        reputation[account.reputation] = account.on_site.name

    global_sof_json['reputated_on'] = reputation[max(reputation)]
    global_sof_json['reputation'] = max(reputation)
Beispiel #5
0
try:
    import config
    se_key = config.stackexchange['api_key']
except:
    se_key = os.environ.get('SE_KEY')

if not se_key:
    import sys
    print 'No config.py file found. Exiting...'
    sys.exit(0)

MAX_QUESTIONS = 10

app = Flask(__name__)
so = Site(StackOverflow, se_key)


def get_response_string(q):
    q_data = q.json
    check = ' :white_check_mark:' if q.json['is_answered'] else ''
    return "|%d|%s <%s|%s> (%d answers)" % (q_data['score'], check, q.url,
                                            q.title, q_data['answer_count'])


@app.route('/overflow', methods=['post'])
def overflow():
    '''
    Example:
        /overflow python list comprehension
    '''
# Chap06/stack_search_keyword.py
import os
import json
from argparse import ArgumentParser
from stackexchange import Site
from stackexchange import StackOverflow


def get_parser():
    parser = ArgumentParser()
    parser.add_argument('--tags')
    parser.add_argument('--n', type=int, default=20)
    return parser

if __name__ == '__main__':
    parser = get_parser()
    args = parser.parse_args()
    my_key = os.environ.get('STACK_KEY')
    
    so = Site(StackOverflow, my_key)
    questions = so.questions(tagged=args.tags, pagesize=20)[:args.n]

    for i, item in enumerate(questions):
        print("{}) {} by {}".format(i,
                                    item.title,
                                    item.owner.display_name))
#!/usr/bin/env python
from __future__ import print_function

# a hack so you can run it 'python demo/highest_voted.py'
import sys
sys.path.append('.')
sys.path.append('..')
from stackauth import StackAuth
from stackexchange import Site, StackOverflow, Sort, DESC

so = Site(StackOverflow)

print('The highest voted question on StackOverflow is:')
question = so.questions(sort=Sort.Votes, order=DESC)[0]
print('\t%s\t%d' % (question.title, question.score))
print()
print('Look, see:', question.url)
Beispiel #8
0
#!/usr/bin/env python
from __future__ import print_function

# a hack so you can run it 'python demo/narcissism.py'
import sys
sys.path.append('.')
sys.path.append('..')
from stackauth import StackAuth
from stackexchange import Site, StackOverflow

user_id = 41981 if len(sys.argv) < 2 else int(sys.argv[1])
print('StackOverflow user %d\'s accounts:' % user_id)

stack_auth = StackAuth()
so = Site(StackOverflow, impose_throttling=True)
accounts = stack_auth.api_associated(so, user_id)
reputation = {}

for account in accounts:
    print('  %s / %d reputation' % (account.on_site.name, account.reputation))

    # This may seem a slightly backwards way of storing it, but it's easier for finding the max
    reputation[account.reputation] = account.on_site.name

print('Most reputation on: %s' % reputation[max(reputation)])
#!/usr/bin/env python

# a hack so you can run it 'python demo/stats.py'
import sys
from stackauth import StackAuth
from stackexchange import Site, StackOverflow

user_id = 41981 if len(sys.argv) < 2 else int(sys.argv[1])
print 'StackOverflow user %d\'s accounts:' % user_id

stack_auth = StackAuth()
so = Site(StackOverflow)
accounts = stack_auth.associated(so, user_id)
reputation = {}

for account in accounts:
    print '  %s: %s / %d reputation' % (
        account.display_name, account.on_site.name, account.reputation)
    reputation[account.reputation] = account.on_site.name

print 'Most reputation on: %s' % reputation[max(reputation)]
from cassandra.cqlengine.models import Model
from cassandra.cluster import Cluster
import time
cluster = Cluster()
session = cluster.connect('stackoverflow')

f = open('finalUSERS.txt', 'r')
idlist = f.read().split(',')

combinedStats = []

i=1

with open('SOoutput.txt','a') as op:
	for id in idlist:
		user_stat = {}
		so = Site(StackOverflow)
		user = so.user(id)
		total_questions = user.questions.fetch()
		user_stat['userID'] = id
		questions_text = []
		for q in total_questions:
			questions_text.append(unicode(q).split("'")[1])
		user_stat['questions'] = questions_text
		combinedStats.append(user_stat)
		combined_questions = " ".join(questions_text)
		'''op.write('==='.encode('utf-8') + str(id).encode('utf-8') + ' '.encode('utf-8') + '<<< '.encode('utf-8') + combined_questions.encode('utf-8') + ' >>>'.encode('utf-8'))'''
		time.sleep(3)
		session.execute("INSERT INTO stackdata(id,questions) VALUES(%s,%s)", (int(id), combined_questions.encode('utf-8')))
		print 'finished inserting ' + str(i)
		i=i+1
Beispiel #11
0
from __future__ import print_function
import sys
sys.path.append('.')
sys.path.append('..')
from stackexchange import Site, StackOverflow

user_id = 41981 if len(sys.argv) < 2 else int(sys.argv[1])
print('StackOverflow user %d\'s experience:' % user_id)

so = Site(StackOverflow)
user = so.user(user_id)

print('Most experienced on %s.' % user.top_answer_tags.fetch()[0].tag_name)
print('Most curious about %s.' % user.top_question_tags.fetch()[0].tag_name)

total_questions = len(user.questions.fetch())
unaccepted_questions = len(user.unaccepted_questions.fetch())
accepted = total_questions - unaccepted_questions
rate = accepted / float(total_questions) * 100
print('Accept rate is %.2f%%.' % rate)
#!/usr/bin/env python

# a hack so you can run it 'python demo/stats.py'
import sys
sys.path.append('.')
sys.path.append('..')
from stackauth import StackAuth
from stackexchange import Site, StackOverflow, Sort, DESC

so = Site(StackOverflow)

print 'The highest voted question on StackOverflow is:'
question = so.questions(sort=Sort.Votes, order=DESC)[0]
print '\t%s\t%d' % (question.title, question.score)
print
print 'Look, see:', question.url
Beispiel #13
0
#!/usr/bin/env python

# a hack so you can run it 'python demo/stats.py'
import sys

sys.path.append(".")
sys.path.append("..")
from stackexchange import Site, StackOverflow

user_id = 41981 if len(sys.argv) < 2 else int(sys.argv[1])
print "StackOverflow user %d's experience:" % user_id

so = Site(StackOverflow)
user = so.user(user_id)

print "Most experienced on %s." % user.top_answer_tags.fetch()[0].tag_name
print "Most curious about %s." % user.top_question_tags.fetch()[0].tag_name

total_questions = len(user.questions)
unaccepted_questions = len(user.unaccepted_questions.fetch())
accepted = total_questions - unaccepted_questions
rate = accepted / float(total_questions) * 100
print "Accept rate is %.2f%%." % rate
Beispiel #14
0
 def get_site(self, **kw):
     # A bit hackish; strips off the "http://"
     domain = self.api_endpoint[7:]
     return Site(domain, **kw)
        raise ArgumentTypeError("{} is an invalid order value".format(value))
    return value


def get_parser():
    parser = ArgumentParser()
    parser.add_argument('--name')
    parser.add_argument('--sort', default='reputation', type=check_sort_value)
    parser.add_argument('--order', default='desc', type=check_order_value)
    parser.add_argument('--n', type=int, default=20)
    return parser


if __name__ == '__main__':
    parser = get_parser()
    args = parser.parse_args()
    my_key = os.environ.get('STACK_KEY')
    
    so = Site(StackOverflow, my_key)

    users = so.users(inname=args.name,
                     sort=args.sort,
                     order=args.order)
    users = users[:args.n]

    for i, user in enumerate(users):
        print("{}) {}, reputation {}, joined {}".format(i,
                                                        user.display_name,
                                                        user.reputation,
                                                        user.creation_date))
Beispiel #16
0
 def get_site(self, *a, **kw):
     return Site(self.api_site_parameter, *a, **kw)
Beispiel #17
0
__FILENAME__ = experience
#!/usr/bin/env python

# a hack so you can run it 'python demo/stats.py'
import sys
sys.path.append('.')
sys.path.append('..')
from stackexchange import Site, StackOverflow

user_id = 41981 if len(sys.argv) < 2 else int(sys.argv[1])
print 'StackOverflow user %d\'s experience:' % user_id

so = Site(StackOverflow)
user = so.user(user_id)

print 'Most experienced on %s.' % user.top_answer_tags.fetch()[0].tag_name
print 'Most curious about %s.' % user.top_question_tags.fetch()[0].tag_name

total_questions = len(user.questions.fetch())
unaccepted_questions = len(user.unaccepted_questions.fetch())
accepted = total_questions - unaccepted_questions
rate = accepted / float(total_questions) * 100
print 'Accept rate is %.2f%%.' % rate

########NEW FILE########
__FILENAME__ = highest_voted
#!/usr/bin/env python

# a hack so you can run it 'python demo/stats.py'
import sys
sys.path.append('.')
Beispiel #18
0
import json
from argparse import ArgumentParser
from stackexchange import Site
from stackexchange import StackOverflow


def get_parser():
    parser = ArgumentParser()
    parser.add_argument('--tags')
    parser.add_argument('--n', type=int, default=20)
    return parser


if __name__ == '__main__':
    parser = get_parser()
    args = parser.parse_args()
    my_key = os.environ.get('STACK_KEY')

    so = Site(StackOverflow, my_key)
    questions = so.questions(tagged=args.tags, pagesize=20)[:args.n]

    for i, item in enumerate(questions):
        print("{}) {} by {}".format(i, item.title, item.owner.display_name))
Beispiel #19
0
def check_order_value(value):
    valid_order_values = ['asc', 'desc']
    if value not in valid_order_values:
        raise ArgumentTypeError("{} is an invalid order value".format(value))
    return value


def get_parser():
    parser = ArgumentParser()
    parser.add_argument('--name')
    parser.add_argument('--sort', default='reputation', type=check_sort_value)
    parser.add_argument('--order', default='desc', type=check_order_value)
    parser.add_argument('--n', type=int, default=20)
    return parser


if __name__ == '__main__':
    parser = get_parser()
    args = parser.parse_args()
    my_key = os.environ.get('STACK_KEY')

    so = Site(StackOverflow, my_key)

    users = so.users(inname=args.name, sort=args.sort, order=args.order)
    users = users[:args.n]

    for i, user in enumerate(users):
        print("{}) {}, reputation {}, joined {}".format(
            i, user.display_name, user.reputation, user.creation_date))