Mercurial > pumpbridge
diff src/sync.coffee @ 0:b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
author | Mathias Gebbe <mgebbe@intevation.de> |
---|---|
date | Thu, 05 Jun 2014 10:35:15 +0200 |
parents | |
children | 98a070c98982 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/sync.coffee Thu Jun 05 10:35:15 2014 +0200 @@ -0,0 +1,122 @@ +# Copyright (C) 2014 by Intevation GmbH +# Author: Mathias Gebbe <mgebbe@intevation.de> +# +# This file is Free Software under the Apache License, Version 2.0 +# (the "License"); and comes with ABSOLUTELY NO WARRANTY! +# You may not use this file except in compliance with the License. +# See LICENSE for details. + +_ = require("underscore") +async = require("async") +Facebook = require("./facebook") +Usermap = require("./usermap") +Google = require("./google") + +syncFromESN = () -> + console.log 'syncFromESN' + + # STEP1: get all from usermap *network (3) "usermap:mgebbe@io.intevation.de_to_100002056487693@facebook" + # STEP2: for each user in network do sync + # STEP 2.1 (do the network sync) + # get all new POSTS from ESN + # post all new POSTS to ESN + # check all FROMESN and update them + # check all toESN and update them + + #### + # Facebook + try + Usermap.scan ((user) -> + if user.id.indexOf('facebook') isnt -1 + console.log "start sync for facebook user" + Facebook.sync(user) + return + ), (err) -> + return + catch err + console.log 'Error!' + return + + # Google + try + Usermap.scan ((user) -> + if user.id.indexOf('google') isnt -1 + console.log "start sync for google user" + Google.sync(user) + return + ), (err) -> + return + catch err + console.log 'Error!' + return + #### + return + + +postParser = (post, user, network, callback) -> + parsed = "" + #console.log "\n" + post.id + "\n" + user.id + user.displayName + #PROFILE_LINK PROFILE_NAME PROFILE_PIC_LINK_80x80=$3 POST_LINK POST_TIME CONTENT + #text='<img src='$PROFILE_PIC_LINK_80x80'></img> <a href='$PROFILE_LINK'>'$PROFILE_NAME'</a> <a href='$POST_LINK'>schreibt</a> am '$POST_TIME':<br><br>'$CONTENT'' + + if network is 'facebook' + if (user.profilePicLink?) + profilePicLink = user.profilePicLink.replace("50x50", "80x80") + else + profilePicLink = 'http://upload.wikimedia.org/wikipedia/commons/thumb/c/c2/F_icon.svg/80px-F_icon.svg.png' + + if post.type is 'status' + parsed = "<img src='" + profilePicLink + "'></img> <a href='" + user.profileLink + "'>" + user.displayName + "</a> <a href='https://www.facebook.com/" + post.id + "'> schreibt</a> via " + network + " am " + post.updated_time + ":<br><br>" + post.message + + if post.type is 'photo' + parsed = "<img src='" + profilePicLink + "'></img> <a href='" + user.profileLink + "'>" + user.displayName + "</a> <a href='"+ post.link + "'> schreibt</a> via " + network + " am " + post.updated_time + ":<br>" + parsed += "<br>" + post.message if typeof post.message isnt "undefined" + parsed += "<br><img src='" + post.picture + "'></img>" + + if post.type is 'link' or post.type is 'video' + parsed = "<img src='" + profilePicLink + "'></img> <a href='" + user.profileLink + "'>" + user.displayName + "</a> <a href='https://www.facebook.com/" + post.id + "'> schreibt</a> via " + network + " am " + post.updated_time + ":<br>" + parsed += "<br>" + post.message if typeof post.message isnt "undefined" + parsed += "<br>" + post.description if typeof post.description isnt "undefined" + parsed += "<br><a href='" + post.link + "'>"+ post.link + "</a>" if typeof post.link isnt "undefined" + parsed += "<br><img src='" + post.picture + "'></img>" if typeof post.picture isnt "undefined" + + + callback null, parsed + + if network is 'google' + parsed = "<img src='" + post.actor.image.url + "'></img> <a href='" + post.actor.url + "'>" + post.actor.displayName + "</a> <a href='"+ post.object.url + "'> schreibt</a> via " + network + " am " + post.updated + ":<br><br>" + post.object.content + if typeof post.object.attachments isnt "undefined" + _.each post.object.attachments, (attachment) -> + + if attachment.objectType == "photo" + parsed += "<br><img src='" + attachment.image.url + "'></img>" + + if attachment.objectType == "article" + parsed += "<br><a href='" + attachment.url + "'>"+ attachment.displayName + "</a>" + if typeof attachment.image isnt "undefined" + parsed += "<br><img src='" + attachment.image.url + "'></img>" + + if attachment.objectType == "video" + parsed += "<br><a href='" + attachment.url + "'>"+ attachment.displayName + "</a>" + if typeof attachment.image isnt "undefined" + parsed += "<br><img src='" + attachment.image.url + "'></img>" + + callback null, parsed + + return + + +sync = () -> + + # Do this every 5 minutes + console.log '\n\n\n' + "starting sync deamon" + interval = 15 * 60 * 1000 + setInterval syncFromESN, interval + + syncFromESN() + + return + + +exports.postParser = postParser +exports.sync = sync