-
Notifications
You must be signed in to change notification settings - Fork 0
/
inbuilt_function3.html
47 lines (37 loc) · 1.53 KB
/
inbuilt_function3.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="brython.js"></script>
<script type="text/javascript" src="brython_stdlib.js"></script>
<script src="https://github.com/RAbraham/mercylog-datascript/releases/download/v0.1.3/mercylog_datascript.brython.js"></script>
<script src="https://github.com/tonsky/datascript/releases/download/0.18.10/datascript-0.18.10.min.js"></script>
</head>
<body onload="brython(1)">
<script type="text/python">
from browser import window, alert, console
datascript = window.datascript
from mercylog_datascript import DataScriptV1
m = DataScriptV1()
import urllib.request, json
data_file_url = 'https://raw.githubusercontent.com/RAbraham/mercylog-datascript-client/master/data.json'
console.log('Loading File')
with urllib.request.urlopen(data_file_url) as url:
result = json.loads(url.read())
console.log('End loading file')
db = datascript.empty_db()
db2 = datascript.db_with(db, result)
# DataScript Query: [:find ?title :where [?movie ":movie/title" ?title] [?movie ":movie/year" ?year] [(< ?year 1984)]]
title, movie, year = m.variables('title', 'movie', 'year')
lt = m.function("<")
query = m.query(find=[title],
where=[[movie, ":movie/title", title],
[movie, ":movie/year", year],
[lt(year, 1984)]])
q = query.code()
alert(q)
result = datascript.q(q, db2)
alert(result) # [['First Blood'], ['Alien'], ['Mad Max'], ['Mad Max 2']
</script>
</body>
</html>