Ejemplo n.º 1
0
def put_property_if_not_exist(resource, obj, w, property_name, prop):
    r = api.get(resource, where=w)
#    print(r)
#    print(obj)
#    print(w)
#    print(property_name)
#    print(prop)
    if len(r['_items']) == 0:
        obj[property_name] = [prop]
        r = api.post(resource, obj)
        obj_old = r['_items'][0]
    else:
        obj_old = r['_items'][0]
        for pr in obj_old:
            if pr[0] != '_':
                try:
                    obj[pr]
                except:
                    obj[pr] = obj_old[pr]
        try:
            properties = r['_items'][0][property_name]
        except:
            properties = []
        already_in = False
        for pr in properties:
            if pr == prop:
                already_in = True
        if not already_in:
            properties.append(prop)
            obj[property_name] = properties
            r = api.put(resource + "/" + r["_items"][0]["_id"], obj)
Ejemplo n.º 2
0
def index_file(url):
    print(f'indexing {url}')
    # parse file by given URL
    resp = requests.get(url=TIKA_HOST + '/api/tika/parse',
                        params={'url': url},
                        headers=api.stdHeaders,
                        timeout=api.TIMEOUT)
    resp.raise_for_status()
    result = resp.json()

    api.login("system", os.getenv("SYSTEM_PWD"))

    meta = result['metadata']

    id = search_doc(url)
    author = meta.get('author', '')
    if author == '':
        author = meta.get('creator', '')
    author_id = search_person(author)
    if author_id is None:
        person = {'name': author}
        person = api.post('/api/data/person', person)
        author_id = person['uid']

    keyword = split_keywords(meta.get('keyword', ''))
    keyword.extend(split_keywords(meta.get('keywords', '')))
    keyword.append('book')
    keyword = list(set([k.strip() for k in keyword if len(k.strip()) > 0]))

    tags = make_tags(keyword)
    meta.pop('keyword', None)
    meta.pop('keywords', None)

    doc = meta
    doc['url'] = url
    doc['text'] = result['text']
    doc['author'] = {'uid': author_id}
    # todo fix thumbnail generation
    # doc['thumbnail_url'] = thumb(url)

    if id is None:
        doc = api.post('/api/data/document', doc)
        id = doc['uid']
    else:
        doc = api.put(f'/api/data/document/{id}', doc)

    # set tags
    edges = [[id, 'tag', t] for t in tags]
    api.update_graph(edges)
    return doc
Ejemplo n.º 3
0
def put_single_property_if_not_exist(resource, obj, w, property_name, prop):
    r = api.get(resource, where=w)
    if len(r['_items']) == 0:
        obj[property_name] = prop
        r = api.post(resource, obj) 
        obj_old = r['_items'][0]
    else:
        obj_old = r['_items'][0]
        for pr in obj_old:
            if pr[0] != '_':
                try:
                    obj[pr]
                except:
                    obj[pr] = obj_old[pr]
        try:
            properti = r['_items'][0][property_name]
        except:
            obj[property_name] = prop
            r = api.put(resource + "/" + r["_items"][0]["_id"], obj)
Ejemplo n.º 4
0
def test_crud():
    api.login("system", os.getenv("SYSTEM_PWD"))

    data = {
        'name': "bob",
        'age': 39,
    }

    print('CREATE')

    resp = api.post('/api/data/user', data)

    id = resp['uid']

    data = {
        'name': "joe",
        'age': 40,
    }

    resp = api.post('/api/data/user', data)
    id2 = resp['uid']

    print('GET LIST')

    resp = api.get('/api/data/user/list')

    print('GET BY ID')

    resp = api.get('/api/data/user/' + id)

    print('QUERY')

    query = """{
  data(func: eq(name, "bob")) @filter(has(User)) {
    uid
    name
    age
  }
}"""
    resp = api.post('/api/query', query, raw=True)

    print('search terms')

    resp = api.search_terms('abc', 'en', no_links=True)

    print('UPDATE')

    data = {
        'name': 'rob',
        'age': 42,
    }

    resp = api.put("/api/data/user/" + id, data)

    print('GET BY ID')

    resp = api.get('/api/data/user/' + id)

    print('DELETE')

    api.delete('/api/data/user/' + id)
    api.delete('/api/data/user/' + id2)
Ejemplo n.º 5
0
#variables
field = []
snake = []
size = 20
direction = 3
orb = []
temp = 0
color = "white"
bright = 1

#turn light on
payload = {
    "power": "on",
}
api.put(payload)

#create initial snake
snake.append([int(size / 2), int(size / 2)])

#create initial field
for x in range(0, size):
    field.append([])

for x in range(0, size):
    for y in range(0, size):
        if x == 0 or y == 0 or x == size - 1 or y == size - 1:
            field[x].append("#")
        else:
            field[x].append(" ")
Ejemplo n.º 6
0
def update_light(color, bright):
    payload = {
        "color": color,
        "brightness": bright,
    }
    api.put(payload)
Ejemplo n.º 7
0
def saveDataStore(dataStore):
    api.put('dataStore/dedupe/periodSettings', dataStore)
Ejemplo n.º 8
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 11 17:33:01 2019

@author: miha
"""

from api import put

put('sum', {'a': 123, 'b': 234})
Ejemplo n.º 9
0
def update_light(color, bright):
    payload = {
        "color": color,
        "brightness": bright,
    }
    api.put(payload)
Ejemplo n.º 10
0
#variables
field = []
snake = []
size = 20
direction = 3
orb = []
temp = 0
color = "white"
bright = 1

#turn light on
payload = {
    "power": "on",
}
api.put(payload)

#create initial snake
snake.append([int(size / 2), int(size / 2)])

#create initial field
for x in range(0, size):
    field.append([])

for x in range(0, size):
    for y in range(0, size):
        if x == 0 or y == 0 or x == size - 1 or y == size - 1:
            field[x].append("#")
        else:
            field[x].append(" ")
Ejemplo n.º 11
0
def crud(resource):
    api.login("system", os.getenv("SYSTEM_PWD"))

    data = {
        'name': "bob",
        'age': 39,
    }

    print('CREATE')

    base = '/api/data/' + resource
    resp = api.post(base, data)

    id = resp['uid']

    data = {
        'name': "joe",
        'age': 40,
    }

    resp = api.post(base, data)
    id2 = resp['uid']

    print('GET LIST')

    resp = api.get(f'{base}/list')

    print('GET BY ID')

    resp = api.get(f'{base}/{id}')

    print('QUERY')

    query = """{{
  data(func: eq(name, "bob")) @filter(has({0})) {{
    uid
    name
    age
  }}
}}""".format(resource.capitalize())
    resp = api.post('/api/query', query, raw=True)

    print('search terms')

    resp = api.search_terms('abc', 'en', no_links=True)

    print('UPDATE')

    data = {
        'name': 'rob',
        'age': 42,
    }

    resp = api.put(f"{base}/{id}", data)

    print('GET BY ID')

    resp = api.get(f'{base}/{id}')

    print('DELETE')

    api.delete(f'{base}/{id}')
    api.delete(f'{base}/{id2}')