Skip to content
This repository has been archived by the owner on Aug 24, 2021. It is now read-only.

Commit

Permalink
wip lernhilfen, mensa date
Browse files Browse the repository at this point in the history
  • Loading branch information
baracoder committed Jul 25, 2015
1 parent 915c968 commit 6688029
Show file tree
Hide file tree
Showing 15 changed files with 204 additions and 150 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
node_modules/
config.coffee
/config.coffee
uploads/
archive/
config.yaml
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

TODO
----

- pdfjoin --a4paper --fitpaper false --rotateoversize false scan01.png
scan02.png
- https://www.npmjs.com/package/textract
- indexing of directories and files using inictl
- provide command to merge images to pdfs
- provide command for creating searchable pdfs (using tessareact)
- include textract for extracting text from files
- refactor dir/file to be created from index
- search interface, allowing autocompletion
- http://stackoverflow.com/questions/20789224/elasticsearch-autocomplete-search-on-array-field
-
8 changes: 8 additions & 0 deletions bin/inictl.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ program
.action (dir, options) ->
logger.setLevel(program)
logger.info 'index', dir
process.exit()

program
.command 'merge-pdf <files...>'
.description 'merge images to one pdf using pdfjam'
.action ->
logger.setLevel(program)
logger.info 'merge-pdf'

program
.command 'list-uploads'
Expand Down
14 changes: 14 additions & 0 deletions config.example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# uncomment to change
#httpPort: 3000
#lhRoot: ./archive
#lhUploads: ./uploads
#fileZuendstoff: http://infoini.de/redmine/attachments/download/422/zs-ss2015.pdf
#refreshIntervalCafe: 1000
#refreshIntervalTuer: 1000
#refreshIntervalMensa: 180000
#tuerHost: localhost
#tuerPort: 51966
#cafeHost: iniwlan.beuth-hochschule.de
#cafePort: 4000
#mensaUrl: http://www.studentenwerk-berlin.de/speiseplan/rss/beuth/woche/kurz/0
#redmineAuthKey: ''
13 changes: 7 additions & 6 deletions lib/app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ app.get '/api/status.xml', (req, res) ->
, (e) -> res.status(500).send e

app.get '/api/combined.json', (req, res) ->
coffeeStatus.get().then (data) ->
combined = {}
combined.pots = data.pots
combined.status = tuerStatus.status
res.json combined
coffeeStatus.get().then (cafeStatus) ->
doorStatus.get().then (tuerStatus) ->
combined = {}
combined.pots = cafeStatus.pots
combined.status = tuerStatus.status
res.json combined
, (e) -> res.status(500).send e


Expand Down Expand Up @@ -95,6 +96,6 @@ app.get '/api/mensa.json', (req, res) ->



app.use('/api', express.static(__dirname + '/static'))
app.use('/api', express.static(__dirname + '/../static'))
app.listen(config.httpPort)

22 changes: 22 additions & 0 deletions lib/config.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
yaml = require 'js-yaml'
fs = require 'fs'

defaults = require './config.defaults'


config = {
# function to load other configs
load: (path = '/etc/inid.yaml') ->
text = fs.readFileSync(path)
userConfig = yaml.safeLoad text
for k, v of userConfig
if k == 'load'
console.warn '"load" not allowed as config key'
else
config[k] = v
}

for k,v of defaults
config[k] = v

module.exports = config
117 changes: 87 additions & 30 deletions lib/lh/dir.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,115 @@ Q = require 'q'

config = require '../config'
logger = require '../logger'
File = require './file'
Paths = require './paths'
Search = require './search'


class Dir
@create: (_path) ->
devider = '\n---\n'
@indexMapping:
properties:
availible:
type: 'boolean'
subdirs:
type: 'string'
files:
type: 'string'
tags: # array of strings
type: 'string'
description:
type: 'string'

@readReadme: (_path) ->
d = Q.defer()
devider = '\n---\n'
fullPath = Paths.getFullPath(path.join(_path, 'README.md'))
name = path.basename(_path)
text = ''
meta = {}
body = ''
# todo sync

fs.readFile fullPath, (err, data) ->
return if err
if err
d.reject err
return
text = data.toString()
text = text.replace(/(\r\n|\n|\r)/gm,"\n")
split = text.indexOf devider
meta = yaml.safeLoad text.substring(0, split)
body = text.substring split + devider.length
numFiles = 0
numDirs = 0
d.resolve [meta, body]
return d.promise

fullPath = Paths.getFullPath(_path)
walk.walk fullPath, { filters: [ '.' ], followLinks: true }
.on 'files', (root, fileStats, next) ->
numFiles = fileStats.filter (stat) ->
stat.name != 'README.md'
.length
next()
@createContent: (_path, recursion) ->
fullPath = Paths.getFullPath _path
d = Q.defer()
files = []
dirs = []
walker = walk.walk fullPath, { filters: [ '.' ], followLinks: true }
walker.on 'file', (root, stat, next) ->
return next() if stat.name == 'README.md'
File.create(path.join(_path, stat.name)).then (file) ->
files.push(file)
next()
, (e) ->
logger.warn 'failed to create file', e.toString()
next()
.done()

.on 'directories', (root, dirStats, next) ->
numDirs = dirStats.length
next()
walker.on 'directory', (root, stat, next) ->
Dir.create(path.join(_path, stat.name), recursion).then (dir) ->
dirs.push(dir)
next()
, (e) ->
logger.warn 'failed to create dir', e.toString()
next()
.done()

.on 'end', ->
d.resolve new Dir(name, meta, body, numFiles, numDirs)
walker.on 'end', ->
d.resolve([dirs, files])

return d.promise

@create: (_path, recursion = 0) ->
logger.debug 'creating dir object', _path
name = path.basename(_path)
dirs = []
files = []
promise = null
if recursion > 0
promise = Q(_path).then =>
@createContent(_path, recursion - 1).then ([d, f]) ->
dirs = d
files = f
else
promise = Q()

promise.then ->
Dir.readReadme(_path).then ([meta, body]) ->
new Dir(_path, name, meta, body, files, dirs)
, ->
new Dir(_path, name, {}, '', files, dirs)
.fail (e) ->
logger.info 'failed to create dir', e.toString()
return e



constructor: (
@name,
@meta = {},
@text = '',
@files = 0,
@dirs = 0
) ->
constructor: (@path, @name, @meta, @text = '', @files = [], @dirs = []) ->
@meta ?= {}
@meta.tags ?= []

toJSON: ->
path: @path
name: @name
meta: @meta
text: @text
files: @files
dirs: @dirs

# add update dir in index
index: ->
index: (recurse = 0) ->



Search.registerType Dir


module.exports = Dir
17 changes: 17 additions & 0 deletions lib/lh/file.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ path = require 'path'
mmm = require 'mmmagic'
fs = require 'fs'

Search = require './search'
Paths = require './paths'
config = require '../config'
logger = require '../logger'
Expand All @@ -11,6 +12,22 @@ logger = require '../logger'
magic = new mmm.Magic(mmm.MAGIC_MIME_TYPE)

class File
@indexMapping:
properties:
availible:
type: 'boolean'
title:
type: 'string'
checksum:
type: 'string'
text:
type: 'string'
tags: # array of strings
type: 'string'
mime:
type: 'string'
size:
type: 'long'
@create: (_path) ->
name = path.basename(_path)
fullPath = Paths.getFullPath(_path)
Expand Down
26 changes: 14 additions & 12 deletions lib/lh/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ config = require '../config'
logger = require '../logger'

Dir = require './dir'
Page = require './page'
Paths = require './paths'
File = require './file'

Expand Down Expand Up @@ -79,24 +78,27 @@ router.get '/file/*', (req, res) ->

router.get '/list/*', (req, res) ->
pathParam = req.params[0]
Page.create(pathParam).then (page) ->
res.json page.toJSON()
Dir.create(pathParam, 1).then (dir) ->
try
res.json dir.toJSON()
catch e
res.status(500).end(e.toString())
, (e) ->
res.status(500).end(e.toString())
res.status(500).send(e.toString())
.done()


router.get '/listhtml/*', (req, res) ->
pathParam = req.params[0]
Page.create(pathParam).then (page) ->
Dir.create(pathParam, 2).then (dir) ->
res.render('page', (
title: 'LH: ' + page.path
path: page.path
files: page.files
dirs: page.subdirs
description: markdown.markdown.toHTML(page.dir.text)
meta: JSON.stringify(page.meta, null, 2)
title: 'LH: ' + dir.path
path: dir.path
files: dir.files
dirs: dir.dirs
description: markdown.markdown.toHTML(dir.text)
meta: JSON.stringify(dir.meta, null, 2)
))
console.log page.dir.text
, (e) ->
res.status(500).end(e.toString())

Expand Down
65 changes: 0 additions & 65 deletions lib/lh/page.coffee

This file was deleted.

Loading

0 comments on commit 6688029

Please sign in to comment.