Commit 0bed468ddc8682a39b1a3c0ad3d77d6cbe455b7a
add feed sequence data to export
mix irving committed on 6/28/2018, 8:59:28 AMParent: 14ed1d15bd344062047e7d73def69d568f4bb91f
Files changed
.gitignore | changed |
index.js | changed |
index.js | |||
---|---|---|---|
@@ -27,32 +27,43 @@ | |||
27 | 27 … | } catch (error) { | |
28 | 28 … | nodeLabels[key] = ''; | |
29 | 29 … | } | |
30 | 30 … | } | |
31 … | + const nodeSeqs = {}; | ||
32 … | + for (let key of nodes) { | ||
33 … | + try { | ||
34 … | + nodeSeqs[key] = await pify(sbot.latestSequence)(key); | ||
35 … | + } catch (error) { | ||
36 … | + nodeSeqs[key] = 0; | ||
37 … | + } | ||
38 … | + } | ||
31 | 39 … | const follows = await pify(sbot.friends.get)(); | |
32 | 40 … | const edges = Object.keys(follows) | |
33 | 41 … | .map(orig => | |
34 | 42 … | Object.keys(follows[orig]) | |
35 | 43 … | .filter(dest => follows[orig][dest] === true) | |
36 | 44 … | .map(dest => [orig, dest]), | |
37 | 45 … | ) | |
38 | 46 … | .reduce((accumulated, current) => accumulated.concat(current), []); | |
39 | - return {nodes, edges, nodeLabels}; | ||
47 … | + return {nodes, edges, nodeLabels, nodeSeqs}; | ||
40 | 48 … | } | |
41 | 49 … | ||
42 | -function* toGraphml({nodes, edges, nodeLabels}) { | ||
50 … | +function* toGraphml({nodes, edges, nodeLabels, nodeSeqs}) { | ||
43 | 51 … | yield '<?xml version="1.0" encoding="UTF-8"?>\n'; | |
44 | 52 … | yield `<graphml xmlns="http://graphml.graphdrawing.org/xmlns" | |
45 | 53 … | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
46 | 54 … | xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns | |
47 | 55 … | http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">\n`; | |
48 | 56 … | yield ' <graph id="G" edgedefault="directed">\n'; | |
49 | 57 … | yield ' <key id="d0" for="node" attr.name="label" attr.type="string"/>\n'; | |
58 … | + yield ' <key id="d1" for="node" attr.name="seq" attr.type="int"/>\n'; | ||
50 | 59 … | for (let id of nodes) { | |
51 | 60 … | const name = nodeLabels[id]; | |
52 | - if (name) { | ||
61 … | + const seq = nodeSeqs[id]; | ||
62 … | + if (name && seq) { | ||
53 | 63 … | yield ` <node id="${id}">\n`; | |
54 | 64 … | yield ` <data key="d0">${encodeURIComponent(name)}</data>\n`; | |
65 … | + yield ` <data key="d1">${seq}</data>\n`; | ||
55 | 66 … | yield ` </node>\n`; | |
56 | 67 … | } else { | |
57 | 68 … | yield ` <node id="${id}"/>\n`; | |
58 | 69 … | } | |
Built with git-ssb-web