def get_all_capitals():
    """Get all capitals"""

    query = request.args.get('query')
    if query is not None:
        print 'GET-query request received'
        query_attr, query_value = query.split(":")
        print 'query_attr:', query_attr, ', query_value:', query_value
        return query_capitals(query_attr, query_value)

    search = request.args.get('search')
    if search is not None:
        print 'GET-search request received'
        search_value = search
        print 'search_value:', search_value
        return search_capitals(search_value)

    qstr = request.query_string
    if qstr is None or len(qstr) == 0:
        print 'GET request received: '
        book = notebook.NoteBook()
        results = book.fetch_all()
        return jsonify(results)

    print '*** unexpected GET request received: ', qstr
    return error(404, 'Unexpected error')
Ejemplo n.º 2
0
    def __init__(self, parent):
        Frame.__init__(self, parent, background="white")
        self.root = parent

        self.root.title("Visual Python")
        self.pack(fill=BOTH, expand=1)
        self.maximize()

        self.mainframe = self
        self.texthelper = texthelper

        self.menu = Menu(self)
        self.root.config(menu=self.menu)
        self.filemenu = filemenu.FileMenu(self)

        self.notebook = notebook.NoteBook(self)
        self.notebook.pack(side=LEFT, fill=BOTH, expand=True)

        self.root.protocol("WM_DELETE_WINDOW", self.filemenu.before_exit)

        import sys
        if len(sys.argv) > 1:
            # auto-open file at startup (after inits)
            # something is not ready when auto-opening, resulting in for example multiline-counter being messed up
            # though fixed with update
            self.root.update()
            self.notebook.new_editor(sys.argv[1])
        else:
            self.notebook.new_editor()
def hello_world():
    """hello world"""

    book = notebook.NoteBook()
    results = book.fetch_all_unique()
    result_url = "https://www.google.com/#q="
    return render_template('index.html', comment=None, results=results)
def publish(id=-1):
    """Publish to global topic specified in body"""

    try:
        book = notebook.NoteBook()
        results = book.fetch_notes(id)
        if len(results) == 0:
            return jsonify({
                'code': str(id),
                'message': 'Capital not found'
            }), 404

        body = request.get_json()
        topic_name = body[u'topic']
        print "topic name", str(topic_name)
        j_result = json.dumps(results[0], ensure_ascii=True)
        print "dump", j_result
        data = str(j_result).encode('utf-8')

        a, project_name, c, topic_name_from_body = str(topic_name).split("/")
        client = pubsub.Client(project_name, None, None, None)
        print "pubsub client", client

        topic = client.topic(topic_name_from_body)
        message_id = topic.publish(data)
        return jsonify({'messageId': int(message_id)}), 200
    except Exception as e:
        server_error(e)
def fetch_and_store_in_bucket(id=-1):
    """retrieves notes from datastore and store in bucket"""

    book = notebook.NoteBook()
    try:
        results = book.fetch_notes(id)
        if len(results) == 0:
            return jsonify({
                'code': str(id),
                'message': 'Capital record not found'
            }), 404
        body = request.get_json()
        bucket_name = body[u'bucket']
        print "results", results[0]
        j_result = json.dumps(results[0], ensure_ascii=True)
        print "dump", j_result
        store_to_gcs = gcs.store_file_to_gcs(str(bucket_name), str(id),
                                             str(j_result))
        if store_to_gcs:
            return "", 200
        else:
            return jsonify({
                'code': str(id),
                'message': 'Bucket not found'
            }), 404
    except:
        return 500
def query_capitals(attr, value):
    book = notebook.NoteBook()
    if attr == "location.latitude" or attr == "location.longitude":
        results = book.fetch_notes_by_attribute(attr, float(value))
        return jsonify(results)
    if attr == "id" or attr == "country" or attr == "name" or attr == "countryCode" or attr == "continent":
        results = book.fetch_notes_by_attribute(attr, value)
        return jsonify(results)
    else:
        return error(404, 'Invalid attriute name: ' + attr)
Ejemplo n.º 7
0
def access_notes():
    """inserts and retrieves notes from datastore"""

    book = notebook.NoteBook()
    if request.method == 'GET':
        results = book.fetch_notes()
        result = [notebook.parse_note_time(obj) for obj in results]
        return jsonify(result)
    elif request.method == 'POST':
        print json.dumps(request.get_json())
        text = request.get_json()['text']
        book.store_note(text)
        return "done"
def access_notes(id=-1):
    """inserts and retrieves notes from datastore"""

    book = notebook.NoteBook()
    integer_id = int(id)
    try:
        if request.method == 'GET':
            results = book.fetch_notes(integer_id)
            if len(results) == 0:
                return jsonify({
                    'code': integer_id,
                    'message': 'Capital record not found'
                }), 404
            print type(results[0])
            return jsonify(results[0]), 200
        elif request.method == 'PUT':
            print json.dumps(request.get_json())
            request_json = request.get_json()
            book.store_note(request_json, integer_id)
            return "", 200
        elif request.method == 'DELETE':
            return book.delete_notes(integer_id)
    except Exception as e:
        return server_error(e)
def task1_world():
    """hello world"""

    book = notebook.NoteBook()
    results = book.fetch_all_unique()
    return render_template('main.html', comment=None, results=results)
def search_capitals(search_value):
    book = notebook.NoteBook()
    results = book.fetch_notes_any_attribute(search_value)
    return jsonify(results)