def onAuthenticated(self, xs): """ xmlstream.STREAM_AUTHD_EVENT handler. Calls when client authenticated on server. Setup dispatcher and any features for client """ self.dispatcher = Dispatcher(xs, self.client_jid) plugins.register(self.dispatcher, self) self.disco = Disco(self.dispatcher) self.disco.init() p = Presence(status="Use me plz!") self.roster = Roster(self.dispatcher, p) self.roster.init() self.version = ClientVersion(self.dispatcher, "XmppBot", 'v%s' % version, 'Linux') self.version.init(self.disco) #set handlers for roster's signals dispatcher.connect(self.onSubscribe, self.roster.subscribe) dispatcher.connect(self.onRosterGot, self.roster.roster_got) dispatcher.connect(self.onAvailable, self.roster.resource_available) dispatcher.connect(self.onUnvailable, self.roster.resource_unavailable)
def route_all_controllers(app_router, plugin=None, path=None): """ Called in app.routes to automatically route all controllers in the app/controllers folder """ base_directory = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')) if path is not None: path = os.path.dirname(path) path = path.replace(base_directory, "") if path.startswith(os.path.sep): path = path[1:] if path is not None and path is not '': directory = os.path.join(path) else: directory = os.path.join('application', 'controllers') if os.path.exists(directory) is False: directory = os.path.join('application') if plugin: directory = os.path.join('plugins', plugin, 'controllers') plugins.register(plugin) directory = os.path.join(base_directory, directory) base_directory_path_len = len(base_directory.split(os.path.sep)) if not os.path.exists(directory): return # walk the app/controllers directory and sub-directories for root_path, _, files in os.walk(directory): for file in files: partial_path = root_path.split(os.path.sep)[base_directory_path_len:] if file.endswith(".py") and file not in ['__init__.py', 'settings.py']: try: name = file.split('.')[0] module_path = '.'.join(partial_path) if plugin: module_path = 'plugins.%s.controllers' % plugin module = __import__('%s.%s' % (module_path, name), fromlist=['*']) try: cls = getattr(module, inflector.camelize(name)) route_controller(cls, app_router) except AttributeError: logging.debug("Controller %s not found, skipping" % inflector.camelize(name)) except AttributeError as e: logging.error('Thought %s was a controller, but was wrong (or ran into some weird error): %s' % (file, e)) raise
def _heuristicIsSeparator(self, ch): if(ch.name == "hr"): return True; if(ch.has_attr('style') and "text-align:center;" in ch['style']): t = ch.get_text("", strip=True); return len(t) < 7 or len(set(t)) < 5; # If the candidate is short or if it has few unique characters, its # likely to be a separator. return False; def _heuristicIsTitle(self, i, ch): if i == 0: self._heuristicTitleState = 0; if (ch.has_attr('style') and "text-align:center;" in ch['style']): # If we don't find a bold, then its not a title # If we find a bold and italics, then something is being emphasized # and this is unlikely to be a title. if not ch.find("strong") or ch.find("em"): return False; if i < 10 and self._heuristicTitleState == 0: self._heuristicTitleState = 1; else: self._heuristicTitleState = 2; return True; if __name__ == "plugins": plugins.register(FFNetParser());
del txt["class"]; del txt["style"]; txt["epub:type"] = "footnote"; txt["id"] = fn_id; footnotes.append(unicode(txt)); footnote_count += 1; elif type(t) == Tag and t.name == "img": path = t["src"]; path_parts = path.split("/"); img_src = path; img_dst = path_parts[-1]; s.append(u"<img src=\"" + image_prefix + img_dst + "\" title=\"" + t["title"] + "\" />\n"); rv["images"].append((img_dst, img_src)); else: s.append(unicode(t)); opentag = u"<p>"; if child.name == "div": opentag = "<p style=\"border: thin solid black; \">"; rv["data"] += opentag + u"".join(s) + "</p>\n"; rv["data"] += "\n".join(footnotes); return rv; if __name__ == "plugins": plugins.register(WhatIfXKCDParser());
"""; footer = """ </body> </html> """; return header + page + footer; def cover(self, bookmeta): # Assemble the cover page. if "cover" in bookmeta: return "<div id=\"cover_img\"><img src=\"%s\" alt=\"Cover\" /></div>" % (imagepath(True) + bookmeta['cover'][0]); else: return "<div id=\"cover\"><h1>%s</h1>\n<div>%s</div></div>" % (bookmeta["title"], bookmeta["author"]); def contents(self, inner): # Assemble the table-of-contents. return "<h1>Contents</h1>\n" + inner; def css(self): return """/* Basic CSS */ body { margin: 5px; } nav#toc ol { list-style-type: none; } #cover_img {width: 100%; height: 95%; text-align:center;} #cover { text-align: center; width: 100%; height: 90%; border: thick solid black;} #cover h1 { padding-top: 100px; font-size: 200%; } #cover div { padding-top: 50px; font-style: italic; width: 100%; } """; if __name__ == "plugins": register(DefaultStyle());
def register (cls): plugins.register(cls, cls.__name__.lower())
import logging from telegram.ext import Updater from bot import mixed_bot from plugins import register logging.basicConfig( format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.WARNING) updater = Updater(bot=mixed_bot) register(updater.dispatcher) updater.start_polling() print("運行中...") updater.idle()
@author: GauravManek """ from plugins import register; from style_default import DefaultStyle; class NookGPStyle(DefaultStyle): def __init__(self): self.name = "Nook GlowLight Plus"; self.devstr = "ngp"; def css(self): rv = super(NookGPStyle, self).css(); return rv + u""" div.sec_brk { width:100%; text-align:center; padding:0.5em; background:white; } body { padding: 0; margin: 0; } img { max-width: 100%; margin: auto; }"""; # Produce a string containing the markup for a section break: def section_break(self): return u"<div class=\"sec_brk\">\u2014\u3000\u00A7\u3000\u2014</div>"; def edit_book_metadata(self, bookmeta): # Lastname, Firstname required by NGP: if "attrib" in bookmeta: bookmeta["author"] = bookmeta["attrib"] + ", " + bookmeta["author"]; return bookmeta; if __name__ == "plugins": register(NookGPStyle());
tt = [t.strip() for t in tt]; offset = (floor(580/60) - len(tt))*20; f36 = ImageFont.truetype("verdana.ttf", 56) for l in range(min(len(tt), MAX_CHAR_LINE)): sz = f36.getsize(tt[l]); draw.text(((600 - sz[0])/2, 60*l + offset), tt[l], fill=0xFF, font=f36); poly = [(74,91.57), (26,91.57), (2,50), (26,8.43), (74,8.43), (98,50), (74,91.57)]; poly = [(x-50, y-50) for x, y in poly]; draw.polygon([(300 + x*1.1, 700 + y*1.1) for x, y in poly], fill=0xFF); draw.polygon([(300 + x, 700 + y) for x, y in poly], fill=0x99); f20i = ImageFont.truetype("verdanai.ttf", 40); sz = f20i.getsize(bookmeta["author"]); draw.text(((600-sz[0])/2, 750), bookmeta["author"], fill=0x00, font=f20i); # Attrib if "attrib" in bookmeta: f24 = ImageFont.truetype("verdana.ttf", 40); sz = f24.getsize(bookmeta["attrib"]); draw.text(((600-sz[0])/2, 1000 - 15 - sz[1]), bookmeta["attrib"], fill=0x99, font=f24); b = io.BytesIO(); im.save(b, "PNG"); return (".png", b.getvalue()); if __name__ == "plugins": plugins.register(DefaultPNGCover());
"y": "500", "font-family":"Helvetica, Arial, sans-serif", "font-style":"italic", "font-size":"32px", "stroke-width":"0", "fill":"#000" }); ln.append(bookmeta["author"]); svg.append(ln); # Attrib if "attrib" in bookmeta: ln = soup.new_tag("text", **{ "text-anchor": "middle", "x": "300", "y": "780", "font-family":"Helvetica, Arial, sans-serif", "font-size":"24px", "stroke-width":"0", "fill":"#999" }); ln.append(bookmeta["attrib"]); svg.append(ln); svg = svg.prettify(); svg = svg.encode("UTF-8"); return (".svg", svg); if __name__ == "plugins": plugins.register(DefaultSVGCover());