Mercurial > pumpbridge
annotate src/syncALONE.coffee @ 32:ca0b44c1a870 tip
Readme: twitter in the summary, it is best working currently.
author | Bernhard Reiter <bernhard@intevation.de> |
---|---|
date | Mon, 13 Oct 2014 13:22:17 +0200 |
parents | 3e3fa35e3ce2 |
children |
rev | line source |
---|---|
19
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
1 # Copyright (C) 2014 by Intevation GmbH |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
2 # Author: Mathias Gebbe <mgebbe@intevation.de> |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
3 # |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
4 # This file is Free Software under the Apache License, Version 2.0; |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
5 # and comes with NO WARRANTY! |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
6 # See the documentation coming with pumpbridge for details. |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
7 |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
8 _ = require("underscore") |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
9 async = require("async") |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
10 Facebook = require("./facebook") |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
11 Usermap = require("./usermap") |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
12 Google = require("./google") |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
13 Config = require ("./config") |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
14 config = Config.config |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
15 Twitter = require("./twitter")(config) |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
16 |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
17 databank = require("databank") |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
18 Databank = databank.Databank |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
19 DatabankObject = databank.DatabankObject |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
20 |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
21 db = Databank.get(config.driver, config.params) |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
22 DatabankObject.bank = db |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
23 |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
24 syncFromESN = () -> |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
25 console.log 'syncFromESN' |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
26 |
21 | 27 #### |
28 # Facebook | |
29 try | |
30 Usermap.scan ((user) -> | |
31 if user.id.indexOf('@facebook') isnt -1 | |
32 console.log "start sync for facebook user" | |
33 Facebook.sync(user) | |
34 ), (err) -> | |
35 catch err | |
27
f27ddfa42e94
try/catch; From/To/-ESN changes; google probs
Mathias Gebbe <mgebbe@intevation.de>
parents:
22
diff
changeset
|
36 console.log 'Facebook Error!' + err |
21 | 37 |
38 # Twitter | |
39 try | |
40 Usermap.scan ((user) -> | |
41 if user.id.indexOf('@twitter') isnt -1 | |
30
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
27
diff
changeset
|
42 # do if true or undefined |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
27
diff
changeset
|
43 unless user.toesn is false |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
27
diff
changeset
|
44 console.log "start sync TOESN for twitter user" |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
27
diff
changeset
|
45 Twitter.syncToESN(user) |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
27
diff
changeset
|
46 unless user.fromesn is false |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
27
diff
changeset
|
47 console.log "start sync FROMESN for twitter user" |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
27
diff
changeset
|
48 Twitter.syncFromESN(user) |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
27
diff
changeset
|
49 Twitter.postLike(user) |
21 | 50 ), (err) -> |
51 catch err | |
27
f27ddfa42e94
try/catch; From/To/-ESN changes; google probs
Mathias Gebbe <mgebbe@intevation.de>
parents:
22
diff
changeset
|
52 console.log 'Twitter Error!' + err |
21 | 53 |
54 # Google | |
55 try | |
56 Usermap.scan ((user) -> | |
57 if user.id.indexOf('@google') isnt -1 | |
58 console.log "start sync for google user" | |
59 Google.sync(user) | |
60 ), (err) -> | |
61 catch err | |
27
f27ddfa42e94
try/catch; From/To/-ESN changes; google probs
Mathias Gebbe <mgebbe@intevation.de>
parents:
22
diff
changeset
|
62 console.log 'Google Error!' + err |
21 | 63 #### |
19
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
64 |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
65 return |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
66 |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
67 sync = () -> |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
68 |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
69 # Do this every xx minutes |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
70 console.log '\n\n\n' + "starting sync deamon" |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
71 interval = config.interval |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
72 if not (interval?) |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
73 interval = 15 * 60 * 1000 # 900 000 ms (15min) |
22
b90e6df48d2d
eachLimit instead of each
Mathias Gebbe <mgebbe@intevation.de>
parents:
21
diff
changeset
|
74 |
21 | 75 async.waterfall [ |
76 (callback) -> | |
77 db.connect(config.params, callback) | |
78 ], (err, result) -> | |
79 setInterval syncFromESN, interval | |
80 syncFromESN() | |
19
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
81 return |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
82 |
6b3f38af3fa4
use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
83 sync() |