             fs.writeFileSync filename, JSON.stringify postedPets
             f notPostedPet
 
-
-get_tierschutzUrls(tierschutz_url).then (values) ->
-    console.log values
 ###
+get_data().then (values) ->
+    console.log values.length
 get_notPostedPet().then (pet) ->
     console.log pet
 ###
-###
+
 # Return all pets
 app.get '/', (req, res) ->
     get_data()

express = require 'express'
NodeCache = require 'node-cache'
fs = require 'fs'

app = express()
cache = new NodeCache()

                urls.push detail_url
            f urls

get_tierschutz = (url) ->
    new Promise (f, r) ->
        request url, (err, response, body) ->
            if err
                r err
            $ = cheerio.load body
            content = $('table')
            name = content.find('.Stil2').text().replace /"/g, ''
            img = content.find('img').attr('src')
            pic = tierschutz_base_url + content.find('img').attr('src')
            id = img.split '.', 1
            id = id[0].split '/'
            content.find('.Stil2').remove()
            content.find('p').first().remove()
            content.find('p').last().remove()
            content.find('p').each ->
                elem = $(this)
                elem.remove() if elem.text().trim().split(/\s+/).length < 10
                elem.remove() if /^-/.test elem.text().trim()
            details =
                id: id[-1..][0]
                pic: pic
                name: name
                link: url
                desc: content.find('.Stil1')
                    .text().replace(/\n/g, '')
                    .replace(/\r/g, '')
                    .replace(/\t/g, '')
                    .trim()
            f details

get_tierschutzUrls = (url) ->
    new Promise (f, r) ->
        request url, (err, response, body) ->
            if err
                console.error err
                r err
            urls = []
            $ = cheerio.load body
            $('td', '#center').each ->
                elem = $(this)
                if elem.attr 'colspan' is undefined
                    href = elem.find('a').attr('href')
                    if href isnt undefined and /^vermittlung/.test href
                        detail_url = tierschutz_base_url + href
                        urls.push detail_url
            f urls

get_tierfreundedata = ->
    new Promise (f, r) ->
        get_tierfreundeUrls tierfreunde_url
            .then (urls) ->
                p = []
                for url in urls
                    p.push get_tierfreunde url
                Promise.all p
            .then (values) ->
                f values
            .catch (err) ->
                r err

get_tierschutzdata = ->
    new Promise (f, r) ->
        get_tierschutzUrls tierschutz_url
            .then (urls) ->
                p = []
                for url in urls
                    p.push get_tierschutz url
                Promise.all p
            .then (values) ->
                f values
            .catch (err) ->
                r err

get_data = ->
    new Promise (f ,r) ->
        values = cache.get('tiere')
        if not values
            Promise.all [get_tierschutzdata(), get_tierfreundedata()]
                .then (list_of_values) ->
                    values = _.union.apply null, list_of_values
                    cache.set('tiere', values, 60*60*24)
                    f values
                .catch (err) ->
