Exemplo n.º 1
0
 def serialize_posts_json(pqueryset, logged_in=False):
     data = []
     for q in pqueryset:
         p = {}
         p['id'] = q.pk
         p['date'] = pretty_date(q.date)
         p['location'] = q.location
         p['school'] = q.school.name
         p['content'] = q.content.replace('\n', '<br />')
         p['author'] = q.author.firstl
         p['author_url'] = "http://" + Site.objects.get_current().domain + reverse('site_main.views.render_user_posts', args=[q.school.slug, q.author.pk])
         p['likes'] = q.likes.count()
         p['liked'] = logged_in and (q.author in q.likes.all())
         p['image'] = False
         p['url'] = "http://" + Site.objects.get_current().domain + reverse('site_main.views.render_single_post', args=[q.school.slug, q.pk])
         if q.image and q.image_thumb:
             i = {}
             i['full'] = q.image.url
             i['thumb'] = q.image_thumb.url
             p['image'] = i
         comments = q.postcomment_set.all().order_by('date')
         cl = []
         for c in comments:
             cd = {}
             cd['author'] = c.author.firstl
             cd['author_url'] = "http://" + Site.objects.get_current().domain + reverse('site_main.views.render_user_posts', args=[q.school.slug, c.author.pk])
             cd['date'] = pretty_date(c.date)
             cd['content'] = c.content
             cl.append(cd)
         p['comment_count'] = len(cl)
         p['comments'] = cl
         p['comment_post_url'] = reverse('site_main.views.post_comment', args=[q.pk])
         data.append(p)
     return json.dumps(data)
Exemplo n.º 2
0
def on_message(mosq, obj, msg):
	if msg.topic == 'door/outer/opened/username':
		ls = last_seen(msg.payload)
		if not ls:
			send_to_bot("%s opened the outer door." % msg.payload)
		else:
			send_to_bot("%s opened the outer door. Last seen %s." % (msg.payload, pretty_date(ls[0])))
	elif msg.topic == 'door/outer/buzzer':
		send_to_bot("%s" % random.choice(['Buzzer', 'Buzzer', 'Buzzer', 'Buzzer', 'Buzzer', 'Buzzer', 'Buzzer', 'Buzzer', 'Buzzer', 'rezzuB', 'Buzzard']))
	elif msg.topic == 'door/outer/invalidcard':
		send_to_bot("Unknown card at door")
	elif msg.topic == 'bot/outgoing':
		send_to_bot(msg.payload)
	elif msg.topic == 'door/shutter/opened':
		send_to_bot("Shutter Opened!")
	elif msg.topic == 'door/shutter/closed':
		send_to_bot("Shutter Closed!")
Exemplo n.º 3
0
import os
import json
import numpy
import requests
from prettydate import pretty_date
from flask import Flask, render_template, request
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.security import Security, SQLAlchemyUserDatastore, \
    UserMixin, RoleMixin, login_required
from sqlalchemy.orm import class_mapper
from flask_security.core import current_user
from flask_security.forms import RegisterForm, TextField, Required

venmo_url = 'https://api.venmo.com/oauth/authorize?client_id=1351&scope=access_profile,make_payments&response_type=code'

dthandler = lambda obj: pretty_date(obj) if isinstance(obj, datetime.datetime) else None
# Create app
app = Flask(__name__)
app.config['DEBUG'] = True
app.config['SECRET_KEY'] = 'super-secret'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///%s/app.db' % (os.path.abspath(os.path.dirname(__file__)),)
app.config['SECURITY_REGISTERABLE'] = True
app.config['SECURITY_CHANGEABLE'] = True
app.config['SECURITY_SEND_REGISTER_EMAIL'] = False
app.config['VENMO_CLIENT_ID'] = 1454
app.config['VENMO_SECRET'] = "CFELT3xea29gtWFk7ujfTcDh8bMTzJZ8"

COLUMN_BLACKLIST = ["password", "venmo_key"]

# Create database connection object
db = SQLAlchemy(app)
Exemplo n.º 4
0
 def date_pretty(self):
     return pretty_date(self.date)