def main(): op = optparse.OptionParser() op.add_option('--host', default='http://localhost:4000') op.add_option('--api-user', default='system') op.add_option('-v', '--verbose', action='store_true') options, args = op.parse_args() if not options.host.startswith('http'): op.error('host must include protocol, eg http://') api_key = os.environ.get('DISCOURSE_API_KEY') if not api_key: op.error('please set DISCOURSE_API_KEY') client = DiscourseClient(options.host, options.api_user, api_key) if options.verbose: logging.basicConfig() logging.getLogger().setLevel(logging.DEBUG) c = DiscourseCmd(client) if args: line = ' '.join(args) result = c.onecmd(line) c.postcmd(result, line) else: c.cmdloop()
def main(): op = optparse.OptionParser() op.add_option("--host", default="http://localhost:4000") op.add_option("--api-user", default="system") op.add_option("-v", "--verbose", action="store_true") options, args = op.parse_args() if not options.host.startswith("http"): op.error("host must include protocol, eg http://") api_key = os.environ.get("DISCOURSE_API_KEY") if not api_key: op.error("please set DISCOURSE_API_KEY") client = DiscourseClient(options.host, options.api_user, api_key) if options.verbose: logging.basicConfig() logging.getLogger().setLevel(logging.DEBUG) c = DiscourseCmd(client) if args: line = " ".join(args) result = c.onecmd(line) c.postcmd(result, line) else: c.cmdloop()
def __init__(self, settings): self.settings = settings self.timeout = int(settings['url.timeout']) self.discourse_base_url = settings['discourse.url'] self.discourse_public_url = settings['discourse.public_url'] self.api_key = settings['discourse.api_key'] self.sso_key = str(settings.get('discourse.sso_secret')) # no unicode self.discourse_userid_cache = {} # FIXME: are we guaranteed usernames can never change? -> no! self.discourse_username_cache = {} self.client = DiscourseClient( self.discourse_base_url, api_username='******', # the built-in Discourse user api_key=self.api_key, timeout=self.timeout)
def get_discourse_data(email): client = DiscourseClient('http://meta.mangaki.fr', api_username=DISCOURSE_API_USERNAME, api_key=DISCOURSE_API_KEY) try: users = client._get('/admin/users/list/active.json?show_emails=true') for user in users: if user['email'] == email: return { 'avatar': 'http://meta.mangaki.fr' + user['avatar_template'], 'created_at': user['created_at'] } return { 'avatar': '/static/img/unknown.png', 'created_at': datetime.datetime.now().isoformat() + 'Z' } except: return { 'avatar': '/static/img/unknown.png', 'created_at': datetime.datetime.now().isoformat() + 'Z' }
def post(self, user, title, content): client = DiscourseClient( 'https://community.bigquant.com/', api_username=user, api_key= 'ceaa79d2386bfbe83cdd1b71f6e7be3861c26dfb9d1c1982614aed7176db03a8') for i in range(0, 3): try: client.create_post(content=content, category=u"AI量化百科", skip_validations=True, auto_track=False, title=title) path = self._posted_path(title) print(title, path) with codecs.open(path, 'w', 'utf-8') as writer: writer.write(title + '\n') writer.write('\n\n') writer.write(content) return except Exception as e: print(e) print(exception_trace(single_line=False)) time.sleep(1 << i)
import Legobot import subprocess import time from creds import Creds from bs4 import BeautifulSoup from pydiscourse.client import DiscourseClient creds = Creds() HOST = creds.HOST PORT = creds.PORT NICK = creds.NICK PASS = creds.PASS CHANS = creds.CHANS myBot = Legobot.legoBot(host=HOST,port=PORT,nick=NICK,nickpass=PASS,chans=CHANS) client = DiscourseClient('https://0x00sec.org', api_username='******', api_key=creds.API_KEY) def NickfromMsg(msg): return msg.splitMessage[0].split("!")[0][1:] def UrlFromID(id): data = client.topic_posts(id)["post_stream"]["posts"][0] return "https://0x00sec.org/t/%s/%s" % (data["topic_slug"], data["topic_id"]) def Reconnect(): def join(msg): myBot.sendMsg("JOIN " + msg.arg1 + "\r\n")