This repository has been archived by the owner on Jul 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
_utils_load_single.coffee
85 lines (61 loc) · 2.68 KB
/
_utils_load_single.coffee
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
"use strict"
fs = require "fs"
orient = require "orientdb"
assert = require "assert"
filename = process.argv[2]
catalog = process.argv[3]
server = new orient.Server
host: "localhost"
port: 2424
db = new orient.GraphDb "presentz", server,
user_name: "admin"
user_password: "admin"
db.open (err) ->
assert(!err, err)
db.command "select from V where _type = 'catalog' and id = '#{catalog}'", (err, results) ->
assert(!err, err)
catalog = results[0]
db.command "select from V where _type = 'user' and twitter_id = '1861911'", (err, results) ->
assert(!err, err)
user = results[0]
fs.readFile filename, "utf-8", (err, presentation) ->
assert(!err, err)
presentation = JSON.parse presentation
presentation._type = "presentation"
presentation.published = true
presentation.id = filename.substr(0, filename.indexOf(".json"))
chapters = presentation.chapters
delete presentation.chapters
for chapter, chapter_index in chapters
chapter._type = "chapter"
chapter._index = chapter_index
for slide in chapter.media.slides
slide._type = "slide"
db.createVertex presentation, (err, presentation) ->
assert(!err, err)
db.createEdge user, presentation, { label: "authored" }, (err) ->
assert(!err, err)
db.createEdge presentation, catalog, { label: "part_of" }, (err) ->
assert(!err, err)
link_chapters_to_pres= (chapters, presentation) ->
if chapters.length is 0
db.close()
return
chapter = chapters.pop()
chapter.video = chapter.media.video
slides = chapter.media.slides
delete chapter.media
db.createVertex chapter, (err, chapter) ->
assert(!err, err)
db.createEdge chapter, presentation, { label: "chapter_of" }, (err) ->
assert(!err, err)
link_slides_to_chapter= (slides, chapter) ->
return link_chapters_to_pres chapters, presentation if slides.length is 0
slide = slides.pop()
db.createVertex slide, (err, slide) ->
assert(!err, err)
db.createEdge slide, chapter, { label: "slide_of" }, (err) ->
assert(!err, err)
link_slides_to_chapter slides, chapter
link_slides_to_chapter slides, chapter
link_chapters_to_pres chapters, presentation