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
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
27 ####
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
28 # Facebook
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
29 try
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
30 Usermap.scan ((user) ->
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
31 if user.id.indexOf('@facebook') isnt -1
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
32 console.log "start sync for facebook user"
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
33 Facebook.sync(user)
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
34 ), (err) ->
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
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
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
37
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
38 # Twitter
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
39 try
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
40 Usermap.scan ((user) ->
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
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
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
50 ), (err) ->
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
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
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
53
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
54 # Google
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
55 try
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
56 Usermap.scan ((user) ->
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
57 if user.id.indexOf('@google') isnt -1
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
58 console.log "start sync for google user"
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
59 Google.sync(user)
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
60 ), (err) ->
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
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
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
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
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
75 async.waterfall [
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
76 (callback) ->
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
77 db.connect(config.params, callback)
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
78 ], (err, result) ->
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
79 setInterval syncFromESN, interval
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
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()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)