コード例 #1
0
def index():
    db = connect_db().message
    items = list(db.find({ '$or' : [ {'urls':{'$exists':True}}, {'imgs':{'$exists':True}}] }, sort=[('time', -1)], limit=15))
    for i in items:
        if "tags" in i:
            i["tags"] = ", ".join(["#%s" % (x) for x in i["tags"]])
    return render_template("index.html", title="Home", items=items, items_len=len(items))
コード例 #2
0
PARTYCHAT_ROOM = environ["PARTYCHAT_ROOM"]
GMAIL_USERNAME = environ["GMAIL_USERNAME"]
GMAIL_PASSWORD = environ["GMAIL_PASSWORD"]

PARTYCHAT_ROOM = PARTYCHAT_ROOM + "@im.partych.at"

reload(sys)
sys.setdefaultencoding('utf8')

# http://mathiasbynens.be/demo/url-regex
url_regex = re.compile(r'(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:/[^\s]*)?', re.IGNORECASE)
img_regex = re.compile(r'.*(gif|jpg|jpeg|png|bmp)$')
tag_regex = re.compile(r'(?:^|\s)#(\w+)')

db = connect_db().message
fs = connect_db()
fs["thumbnail.chunks"].ensure_index([("files_id", 1), ("n", 1)])

fs = GridFS(fs, "thumbnail")


class LolBot(sleekxmpp.ClientXMPP):

    def __init__(self, jid, password):
        sleekxmpp.ClientXMPP.__init__(self, jid, password)
        self.add_event_handler("session_start", self.start)
        self.add_event_handler("message", self.message)

    def start(self, event):
        self.send_presence()
コード例 #3
0
def thumb(thumb_id):
    fs = connect_db()
    fs = GridFS(fs, "thumbnail")
    f = fs.get(objectid.ObjectId(thumb_id))
    f = f.read()
    return app.response_class(f, mimetype="image/png")