Exemplo n.º 1
0
def load_instagram():
    access_token = Config.query(Config.name == 'instagram_access_token').order(-Config.date_added).get()

    if access_token is None:
        return Response(json.dumps({ 'error': 'instagram_access_token configuration was not found.' }), status=500, mimetype='application/json');

    client_secret = Config.query(Config.name == 'instagram_client_secret').order(-Config.date_added).get()

    if client_secret is None:
        return Response(json.dumps({ 'error': 'instagram_client_secret configuration was not found.' }), status=500, mimetype='application/json');

    return instagram_import.import_media(access_token.value, client_secret.value)
Exemplo n.º 2
0
def load_tracker():
    tracker_url = Config.query(Config.name == 'tracker_url').order(-Config.date_added).get()
    if tracker_url is None:
        return Response(json.dumps({ 'error': 'tracker_url configuration was not found.' }), status=500, mimetype='application/json');

    tracker_type = Config.query(Config.name == 'tracker_type').order(-Config.date_added).get()
    if tracker_type is None:
        return Response(json.dumps({ 'error': 'tracker_type configuration was not found.' }), status=500, mimetype='application/json');

    if tracker_type.value == 'delorme':
        return delorme.load_data(tracker_url.value)
    elif tracker_type.value == 'spot':
        return Response(json.dumps({ 'error': 'tracker not supported.' }), status=400, mimetype='application/json');
    else:
        return Response(json.dumps({ 'error': 'tracker not supported.' }), status=400, mimetype='application/json');
Exemplo n.º 3
0
def is_open_or_close():
    c = Config.query().get()
    if not c:
        c = Config()
        c.is_open = False
        c.put()
        return False
    return c.is_open
Exemplo n.º 4
0
def get_auth_secret():
    """
    Returns the secret required to update the click counter configuration.

    If no secret is configured, a random secret is generated and persisted.
    """
    from models import Config
    secret_config = Config.query(Config.key == "auth_secret").get()
    if not secret_config:
        secret_config = set_auth_secret(''.join(random.choice(string.lowercase) for i in range(10)))
    return secret_config.value
Exemplo n.º 5
0
def load_flickr():
    user_id = Config.query(Config.name == 'flickr_username').order(-Config.date_added).get()

    if user_id is None:
        return Response(json.dumps({ 'error': 'flickr_username configuration was not found.' }), status=500, mimetype='application/json');

    photoset_id = Config.query(Config.name == 'flickr_photoset_title').order(-Config.date_added).get()

    if photoset_id is None:
        return Response(json.dumps({ 'error': 'flickr_photoset_title configuration was not found.' }), status=500, mimetype='application/json');

    api_key = Config.query(Config.name == 'flickr_api_key').order(-Config.date_added).get()

    if api_key is None:
        return Response(json.dumps({ 'error': 'flickr_api_key configuration was not found.' }), status=500, mimetype='application/json');

    api_secret = Config.query(Config.name == 'flickr_api_secret').order(-Config.date_added).get()

    if api_secret is None:
        return Response(json.dumps({ 'error': 'flickr_api_secret configuration was not found.' }), status=500, mimetype='application/json');

    return flickr.import_photos(user_id.value, photoset_id.value, api_key.value, api_secret.value)
Exemplo n.º 6
0
def sendMailResult():
    # TODO: test this
    message = mail.EmailMessage(sender="MercatoLibero <*****@*****.**>",
                                subject="Risultati")
    users = User.query().fetch()
    to = ""
    for user in users:
        to += user.email + ";"
    message.to = to
    calls_open = Call.query(Call.status == "OPEN").fetch()
    status = Config.query().get()
    if not status:
        status = Config()
    status.is_open = True
    status.put()
    if len(calls_open) > 0:
        path = os.path.join(os.path.dirname(__file__), 'templates', 'mail_results.html')
        params = dict(open=[e.to_dict() for e in calls_open])
        res = template.render(path, params)
        for o in calls_open:
            o.status = "CLOSED"
            o.put()
        message.html = res
        message.send()
Exemplo n.º 7
0
def get_config(name):
    config = Config.query(Config.name == name).order(-Config.date_added).get()
    if config is not None:
        return Response(json.dumps(config.to_dict()), mimetype='application/json');
    else:
        return Response(json.dumps({ 'error': 'configuration was not found.' }), status=400, mimetype='application/json');
Exemplo n.º 8
0
 def get(self):
     status = Config.query().get()
     if not status:
         status = Config()
     status.is_open = False
     status.put()
Exemplo n.º 9
0
def set_open_or_closed(v):
    c = Config.query().get()
    if not c:
        c = Config()
    c.is_open = v
    c.put()