comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:b73191efc65b
1 # Copyright (C) 2014 by Intevation GmbH
2 # Author: Mathias Gebbe <mgebbe@intevation.de>
3 #
4 # This file is Free Software under the Apache License, Version 2.0
5 # (the "License"); and comes with ABSOLUTELY NO WARRANTY!
6 # You may not use this file except in compliance with the License.
7 # See LICENSE for details.
8
9 _ = require("underscore")
10 async = require("async")
11 Facebook = require("./facebook")
12 Usermap = require("./usermap")
13 Google = require("./google")
14
15 syncFromESN = () ->
16 console.log 'syncFromESN'
17
18 # STEP1: get all from usermap *network (3) "usermap:mgebbe@io.intevation.de_to_100002056487693@facebook"
19 # STEP2: for each user in network do sync
20 # STEP 2.1 (do the network sync)
21 # get all new POSTS from ESN
22 # post all new POSTS to ESN
23 # check all FROMESN and update them
24 # check all toESN and update them
25
26 ####
27 # Facebook
28 try
29 Usermap.scan ((user) ->
30 if user.id.indexOf('facebook') isnt -1
31 console.log "start sync for facebook user"
32 Facebook.sync(user)
33 return
34 ), (err) ->
35 return
36 catch err
37 console.log 'Error!'
38 return
39
40 # Google
41 try
42 Usermap.scan ((user) ->
43 if user.id.indexOf('google') isnt -1
44 console.log "start sync for google user"
45 Google.sync(user)
46 return
47 ), (err) ->
48 return
49 catch err
50 console.log 'Error!'
51 return
52 ####
53 return
54
55
56 postParser = (post, user, network, callback) ->
57 parsed = ""
58 #console.log "\n" + post.id + "\n" + user.id + user.displayName
59 #PROFILE_LINK PROFILE_NAME PROFILE_PIC_LINK_80x80=$3 POST_LINK POST_TIME CONTENT
60 #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''
61
62 if network is 'facebook'
63 if (user.profilePicLink?)
64 profilePicLink = user.profilePicLink.replace("50x50", "80x80")
65 else
66 profilePicLink = 'http://upload.wikimedia.org/wikipedia/commons/thumb/c/c2/F_icon.svg/80px-F_icon.svg.png'
67
68 if post.type is 'status'
69 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
70
71 if post.type is 'photo'
72 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>"
73 parsed += "<br>" + post.message if typeof post.message isnt "undefined"
74 parsed += "<br><img src='" + post.picture + "'></img>"
75
76 if post.type is 'link' or post.type is 'video'
77 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>"
78 parsed += "<br>" + post.message if typeof post.message isnt "undefined"
79 parsed += "<br>" + post.description if typeof post.description isnt "undefined"
80 parsed += "<br><a href='" + post.link + "'>"+ post.link + "</a>" if typeof post.link isnt "undefined"
81 parsed += "<br><img src='" + post.picture + "'></img>" if typeof post.picture isnt "undefined"
82
83
84 callback null, parsed
85
86 if network is 'google'
87 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
88 if typeof post.object.attachments isnt "undefined"
89 _.each post.object.attachments, (attachment) ->
90
91 if attachment.objectType == "photo"
92 parsed += "<br><img src='" + attachment.image.url + "'></img>"
93
94 if attachment.objectType == "article"
95 parsed += "<br><a href='" + attachment.url + "'>"+ attachment.displayName + "</a>"
96 if typeof attachment.image isnt "undefined"
97 parsed += "<br><img src='" + attachment.image.url + "'></img>"
98
99 if attachment.objectType == "video"
100 parsed += "<br><a href='" + attachment.url + "'>"+ attachment.displayName + "</a>"
101 if typeof attachment.image isnt "undefined"
102 parsed += "<br><img src='" + attachment.image.url + "'></img>"
103
104 callback null, parsed
105
106 return
107
108
109 sync = () ->
110
111 # Do this every 5 minutes
112 console.log '\n\n\n' + "starting sync deamon"
113 interval = 15 * 60 * 1000
114 setInterval syncFromESN, interval
115
116 syncFromESN()
117
118 return
119
120
121 exports.postParser = postParser
122 exports.sync = sync
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)