Mercurial > pumpbridge
comparison src/sync.coffee @ 7:2123f355ab68
go back interval or 15 min, delete credentials, layout
author | Mathias Gebbe <mgebbe@intevation.de> |
---|---|
date | Wed, 11 Jun 2014 02:32:53 +0200 |
parents | af9f5b94c019 |
children | 6fd0a307850f |
comparison
equal
deleted
inserted
replaced
6:a94ac7c3b182 | 7:2123f355ab68 |
---|---|
27 | 27 |
28 #### | 28 #### |
29 # Facebook | 29 # Facebook |
30 try | 30 try |
31 Usermap.scan ((user) -> | 31 Usermap.scan ((user) -> |
32 if user.id.indexOf('facebook') isnt -1 | 32 if user.id.indexOf('@facebook') isnt -1 |
33 console.log "start sync for facebook user" | 33 console.log "start sync for facebook user" |
34 Facebook.sync(user) | 34 Facebook.sync(user) |
35 return | 35 return |
36 ), (err) -> | 36 ), (err) -> |
37 return | 37 return |
40 return | 40 return |
41 | 41 |
42 # Twitter | 42 # Twitter |
43 try | 43 try |
44 Usermap.scan ((user) -> | 44 Usermap.scan ((user) -> |
45 if user.id.indexOf('twitter') isnt -1 | 45 if user.id.indexOf('@twitter') isnt -1 |
46 console.log "start sync for twitter user" | 46 console.log "start sync for twitter user" |
47 Twitter.sync(user) | 47 Twitter.sync(user) |
48 return | 48 return |
49 ), (err) -> | 49 ), (err) -> |
50 return | 50 return |
54 | 54 |
55 | 55 |
56 # Google | 56 # Google |
57 try | 57 try |
58 Usermap.scan ((user) -> | 58 Usermap.scan ((user) -> |
59 if user.id.indexOf('google') isnt -1 | 59 if user.id.indexOf('@google') isnt -1 |
60 console.log "start sync for google user" | 60 console.log "start sync for google user" |
61 Google.sync(user) | 61 Google.sync(user) |
62 return | 62 return |
63 ), (err) -> | 63 ), (err) -> |
64 return | 64 return |
71 | 71 |
72 postParser = (post, user, network, callback) -> | 72 postParser = (post, user, network, callback) -> |
73 parsed = "" | 73 parsed = "" |
74 #console.log "\n" + post.id + "\n" + user.id + user.displayName | 74 #console.log "\n" + post.id + "\n" + user.id + user.displayName |
75 #PROFILE_LINK PROFILE_NAME PROFILE_PIC_LINK_80x80=$3 POST_LINK POST_TIME CONTENT | 75 #PROFILE_LINK PROFILE_NAME PROFILE_PIC_LINK_80x80=$3 POST_LINK POST_TIME CONTENT |
76 #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'' | 76 #text='<img src='$PROFILE_PIC_LINK_80x80'></img> <a href='$PROFILE_LINK'>'$PROFILE_NAME'</a> <a href='$POST_LINK'>wrotes</a> at '$POST_TIME':<br><br>'$CONTENT'' |
77 | 77 |
78 if network is 'facebook' | 78 if network is 'facebook' |
79 if (user.profilePicLink?) | 79 if (user.profilePicLink?) |
80 profilePicLink = user.profilePicLink.replace("50x50", "80x80") | 80 profilePicLink = user.profilePicLink.replace("50x50", "80x80") |
81 else | 81 else |
82 profilePicLink = 'http://upload.wikimedia.org/wikipedia/commons/thumb/c/c2/F_icon.svg/80px-F_icon.svg.png' | 82 profilePicLink = 'http://upload.wikimedia.org/wikipedia/commons/thumb/c/c2/F_icon.svg/80px-F_icon.svg.png' |
83 | 83 |
84 if post.type is 'status' | 84 if post.type is 'status' |
85 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 | 85 parsed = "<img src='" + profilePicLink + "'></img> <a href='" + user.profileLink + "'>" + user.displayName + "</a> <a href='https://www.facebook.com/" + post.id + "'> wrotes</a> via " + network + " at " + post.updated_time + ":<br><br>" + post.message |
86 | 86 |
87 if post.type is 'photo' | 87 if post.type is 'photo' |
88 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>" | 88 parsed = "<img src='" + profilePicLink + "'></img> <a href='" + user.profileLink + "'>" + user.displayName + "</a> <a href='"+ post.link + "'> wrotes</a> via " + network + " at " + post.updated_time + ":<br>" |
89 parsed += "<br>" + post.message if post.message? and post.message isnt "" | 89 parsed += "<br>" + post.message if post.message? and post.message isnt "" |
90 parsed += "<br><img src='" + post.picture + "'></img>" | 90 parsed += "<br><img src='" + post.picture + "'></img>" |
91 | 91 |
92 if post.type is 'link' or post.type is 'video' | 92 if post.type is 'link' or post.type is 'video' |
93 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>" | 93 parsed = "<img src='" + profilePicLink + "'></img> <a href='" + user.profileLink + "'>" + user.displayName + "</a> <a href='https://www.facebook.com/" + post.id + "'> wrotes</a> via " + network + " at " + post.updated_time + ":<br>" |
94 parsed += "<br>" + post.message if post.message? and post.message isnt "" | 94 parsed += "<br>" + post.message if post.message? and post.message isnt "" |
95 parsed += "<br>" + post.description if post.description? | 95 parsed += "<br>" + post.description if post.description? |
96 parsed += "<br><a href='" + post.link + "'>"+ post.link + "</a>" if post.link? | 96 parsed += "<br><a href='" + post.link + "'>"+ post.link + "</a>" if post.link? |
97 parsed += "<br><img src='" + post.picture + "'></img>" if post.picture? | 97 parsed += "<br><img src='" + post.picture + "'></img>" if post.picture? |
98 | 98 |
99 callback null, parsed | 99 callback null, parsed |
100 | 100 |
101 if network is 'google' | 101 if network is 'google' |
102 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 | 102 parsed = "<img src='" + post.actor.image.url + "'></img> <a href='" + post.actor.url + "'>" + post.actor.displayName + "</a> <a href='"+ post.object.url + "'> wrotes</a> via " + network + " at " + post.updated + ":<br><br>" + post.object.content |
103 if not post.object.attachments? | 103 if not post.object.attachments? |
104 _.each post.object.attachments, (attachment) -> | 104 _.each post.object.attachments, (attachment) -> |
105 | 105 |
106 if attachment.objectType == "photo" | 106 if attachment.objectType == "photo" |
107 parsed += "<br><img src='" + attachment.image.url + "'></img>" | 107 parsed += "<br><img src='" + attachment.image.url + "'></img>" |
118 | 118 |
119 callback null, parsed | 119 callback null, parsed |
120 | 120 |
121 if network is 'twitter' | 121 if network is 'twitter' |
122 | 122 |
123 parsed = "<img src='" + post.user.profile_image_url + "'></img> <a href='https://twitter.com/account/redirect_by_id/" + post.user.id + "'>" + post.user.name + "</a> <a href='https://twitter.com/" + post.user.screen_name + "/status/" + post.id_str + "'> schreibt </a> via " + network + " am " + post.created_at + ":<br><br>" + post.text | 123 parsed = "<img src='" + post.user.profile_image_url + "'></img> <a href='https://twitter.com/account/redirect_by_id/" + post.user.id + "'>" + post.user.name + "</a> <a href='https://twitter.com/" + post.user.screen_name + "/status/" + post.id_str + "'> wrotes </a> via " + network + " at " + post.created_at + ":<br><br>" + post.text |
124 _.each post.entities.media, (attachment) -> | 124 _.each post.entities.media, (attachment) -> |
125 parsed += "<br><img src='" + attachment.media_url + "'></img>" | 125 parsed += "<br><img src='" + attachment.media_url + "'></img>" |
126 callback null, parsed | 126 callback null, parsed |
127 | 127 |
128 return | 128 return |
129 | 129 |
130 | 130 |
131 sync = () -> | 131 sync = () -> |
132 | 132 |
133 # Do this every 5 minutes | 133 # Do this every xx minutes |
134 console.log '\n\n\n' + "starting sync deamon" | 134 console.log '\n\n\n' + "starting sync deamon" |
135 interval = 15 * 60 * 1000 | 135 interval = config.interval |
136 if not (interval?) | |
137 interval = 15 * 60 * 1000 # 900 000 ms (15min) | |
136 setInterval syncFromESN, interval | 138 setInterval syncFromESN, interval |
137 | 139 |
138 syncFromESN() | 140 syncFromESN() |
139 | 141 |
140 return | 142 return |