def page_body(self, parameters, query_string): if 'id' in query_string: # Create an instance of the Stack Overflow site so = Site('stackoverflow') # Try to get the user with the ID users = so.users(query_string['id']) if len(users): return 'Your username is %s.' % users[0].display_name else: return 'Sorry, but the ID you specified was invalid.' else: return '<form>Enter a user ID on Stack Overflow: <input type="text" name="id" /> <input type="submit" /></form>'
def onMessage(self, msg, binary): if binary: log.warning('Binary message ignored {!r}'.format(msg)) return jd = json.loads(msg) jd['data'] = json.loads(jd['data']) if jd['action'].startswith('1-questions-active'): qid = do_something(jd) if qid not in self.seen: self.sendMessage('1-question-{}'.format(qid)) try: qinfo = Site('stackoverflow').questions(qid).filter('withbody')[0]._data qinfo['_id'] = qid qinfo['datetime_seen'] = datetime.now() posts.insert(qinfo) self.seen.add(qid) except Exception: pass
from bs4 import BeautifulSoup import requests import re from stackpy import Site from pymongo import MongoClient common = requests.get('http://sopython.com/CommonQuestions').text soup = BeautifulSoup(common) db = MongoClient().stackoverflow.common q_re = re.compile('q(?:uestions)?/(\d+)') hrefs = soup.find_all('a', href=q_re) q_ids = [q_re.search(tag['href']).group(1) for tag in hrefs] questions = list(Site('stackoverflow').questions(q_ids)) for question in questions: question._data['category'] = [] db.insert(question._data)
# Licensed under MIT license import sys import os from pprint import pprint from stackpy import Site from optparse import OptionParser from pystache import render if __name__ == "__main__": parser = OptionParser() parser.add_option("-f", "--format", type="string", dest="format", default="html", help="Output format") parser.add_option("-t", "--template_dir", type="string", dest="template_dir", default="./template", help="Template Directory") (options, args) = parser.parse_args() site = Site('stackoverflow') #site.be_inclusive() if len(args) == 0: id = int(raw_input("Enter a question ID: ")) else: id = int(args[0]) question = site.questions(id).filter('withbody')[0] owner = site.users(question.owner.user_id)[0] answer = site.answers(question.accepted_answer_id).filter('withbody')[0] answerer = site.users(answer.owner.user_id)[0] data = { 'question': { 'title': question.title,
def __init__(self): self.nickname = StackIRCConfig.nick self.password = None if StackIRCConfig.password == '' else StackIRCConfig.password self.last_request = int(time()) self.site = Site(StackIRCConfig.site)