Mercurial > pumpbridge > pumpbridge
comparison src/syncALONE.coffee @ 22:b90e6df48d2d
eachLimit instead of each
author | Mathias Gebbe <mgebbe@intevation.de> |
---|---|
date | Mon, 16 Jun 2014 17:31:05 +0200 |
parents | dbe2232af20f |
children | f27ddfa42e94 |
comparison
equal
deleted
inserted
replaced
21:dbe2232af20f | 22:b90e6df48d2d |
---|---|
38 # Twitter | 38 # Twitter |
39 try | 39 try |
40 Usermap.scan ((user) -> | 40 Usermap.scan ((user) -> |
41 if user.id.indexOf('@twitter') isnt -1 | 41 if user.id.indexOf('@twitter') isnt -1 |
42 console.log "start sync for twitter user" | 42 console.log "start sync for twitter user" |
43 Twitter.sync(user) | 43 Twitter.syncToESN(user) |
44 Twitter.syncFromESN(user) | |
44 ), (err) -> | 45 ), (err) -> |
45 catch err | 46 catch err |
46 console.log 'Error!' + err | 47 console.log 'Error!' + err |
47 | 48 |
48 # Google | 49 # Google |
56 console.log 'Error!' + err | 57 console.log 'Error!' + err |
57 #### | 58 #### |
58 | 59 |
59 return | 60 return |
60 | 61 |
61 postParser = (post, user, network, callback) -> | |
62 parsed = "" | |
63 #console.log "\n" + post.id + "\n" + user.id + user.displayName | |
64 #PROFILE_LINK PROFILE_NAME PROFILE_PIC_LINK_80x80=$3 POST_LINK POST_TIME CONTENT | |
65 #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'' | |
66 | |
67 if network is 'facebook' | |
68 if user? and user.profilePicLink? | |
69 profilePicLink = user.profilePicLink.replace("50x50", "80x80") | |
70 else | |
71 profilePicLink = 'http://upload.wikimedia.org/wikipedia/commons/thumb/c/c2/F_icon.svg/80px-F_icon.svg.png' | |
72 | |
73 if post.type is 'status' | |
74 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 | |
75 | |
76 if post.type is 'photo' | |
77 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>" | |
78 parsed += "<br>" + post.message if post.message? and post.message isnt "" | |
79 parsed += "<br><img src='" + post.picture + "'></img>" | |
80 | |
81 if post.type is 'link' or post.type is 'video' | |
82 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>" | |
83 parsed += "<br>" + post.message if post.message? and post.message isnt "" | |
84 parsed += "<br>" + post.description if post.description? | |
85 parsed += "<br><a href='" + post.link + "'>"+ post.link + "</a>" if post.link? | |
86 parsed += "<br><img src='" + post.picture + "'></img>" if post.picture? | |
87 | |
88 callback null, parsed | |
89 | |
90 if network is 'google' | |
91 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 | |
92 if not post.object.attachments? | |
93 _.each post.object.attachments, (attachment) -> | |
94 | |
95 if attachment.objectType == "photo" | |
96 parsed += "<br><img src='" + attachment.image.url + "'></img>" | |
97 | |
98 if attachment.objectType == "article" | |
99 parsed += "<br><a href='" + attachment.url + "'>"+ attachment.displayName + "</a>" | |
100 if not attachment.image? | |
101 parsed += "<br><img src='" + attachment.image.url + "'></img>" | |
102 | |
103 if attachment.objectType == "video" | |
104 parsed += "<br><a href='" + attachment.url + "'>"+ attachment.displayName + "</a>" | |
105 if not attachment.image? | |
106 parsed += "<br><img src='" + attachment.image.url + "'></img>" | |
107 | |
108 callback null, parsed | |
109 | |
110 if network is 'twitter' | |
111 | |
112 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 | |
113 _.each post.entities.media, (attachment) -> | |
114 parsed += "<br><img src='" + attachment.media_url + "'></img>" | |
115 callback null, parsed | |
116 | |
117 return | |
118 | |
119 | |
120 sync = () -> | 62 sync = () -> |
121 | 63 |
122 # Do this every xx minutes | 64 # Do this every xx minutes |
123 console.log '\n\n\n' + "starting sync deamon" | 65 console.log '\n\n\n' + "starting sync deamon" |
124 interval = config.interval | 66 interval = config.interval |
125 if not (interval?) | 67 if not (interval?) |
126 interval = 15 * 60 * 1000 # 900 000 ms (15min) | 68 interval = 15 * 60 * 1000 # 900 000 ms (15min) |
127 | 69 |
128 async.waterfall [ | 70 async.waterfall [ |
129 (callback) -> | 71 (callback) -> |
130 db.connect(config.params, callback) | 72 db.connect(config.params, callback) |
131 ], (err, result) -> | 73 ], (err, result) -> |
132 setInterval syncFromESN, interval | 74 setInterval syncFromESN, interval |
133 syncFromESN() | 75 syncFromESN() |
134 | 76 |
135 return | 77 return |
136 | 78 |
137 sync() | 79 sync() |
138 | |
139 exports.postParser = postParser | |
140 exports.sync = sync |