{"action":"created","comment":{"url":"https://api.github.com/repos/cozy-labs/konnectors/pulls/comments/26001561","id":26001561,"diff_hunk":"@@ -0,0 +1,157 @@\n+americano = require 'americano-cozy'\n+request = require 'request'\n+moment = require 'moment'\n+crypto = require 'crypto'\n+async = require 'async'\n+xml2js = require 'xml2js'\n+\n+localization = require '../lib/localization_manager'\n+\n+# Helpers\n+\n+log = require('printit')\n+    prefix: 'currencies'\n+    date: true\n+\n+# Supported ISO 4217 currency codes\n+\n+CURRENCIES = [\n+    'EUR', 'USD', 'JPY', 'BGN', 'CZK', 'DKK', 'GBP', 'HUF', 'PLN', 'RON', 'SEK',\n+    'CHF', 'NOK', 'HRK', 'RUB', 'TRY', 'AUD', 'BRL', 'CAD', 'CNY', 'HKD', 'IDR',\n+    'ILS', 'INR', 'KRW', 'MXN', 'MYR', 'NZD', 'PHP', 'SGD', 'THB', 'ZAR'\n+]\n+\n+# URLs\n+\n+dailyUrl = 'https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'\n+recentUrl = 'http://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml'\n+histUrl = 'https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.xml'\n+\n+# Other urls\n+# http://www.global-view.com/forex-trading-tools/forex-history/index.html\n+# http://www.global-view.com/forex-trading-tools/forex-history/exchange_csv_report.html?CLOSE_1=ON&start_date=1/1/1900&stop_date=03/06/2015&Submit=Get%20Daily%20Stats\n+# http://www.global-view.com/forex-trading-tools/forex-history/exchange_csv_report.html?CLOSE_1=ON&CLOSE_2=ON&CLOSE_4=ON&start_date=1/1/1900&stop_date=03/06/2015&Submit=Get%20Daily%20Stats\n+# http://www.federalreserve.gov/datadownload/Output.aspx?rel=H10&series=a6a0113179fdeb9c6fbcdc18575ec09c&lastObs=&from=01/01/2000&to=03/07/2015&filetype=csv&label=omit&layout=seriescolumn\n+\n+# Models\n+\n+CurrencyRate = americano.getModel 'CurrencyRate',\n+    date: Date\n+    rate: Number\n+    currency: String\n+    base: String\n+\n+CurrencyRate.all = (callback) ->\n+    CurrencyRate.request 'byDate', callback\n+\n+# Konnector\n+\n+module.exports =\n+\n+    name: 'Currencies'\n+    slug: 'currencies'\n+    description: 'konnector description currencies'\n+    vendorLink: 'https://www.ecb.europa.eu/'\n+\n+    fields: # TODO Can we use the `CURRENCIES` array here?\n+        EUR: 'checkbox'\n+        USD: 'checkbox'\n+        JPY: 'checkbox'\n+        BGN: 'checkbox'\n+        CZK: 'checkbox'\n+        DKK: 'checkbox'\n+        GBP: 'checkbox'\n+        HUF: 'checkbox'\n+        PLN: 'checkbox'\n+        RON: 'checkbox'\n+        SEK: 'checkbox'\n+        CHF: 'checkbox'\n+        NOK: 'checkbox'\n+        HRK: 'checkbox'\n+        RUB: 'checkbox'\n+        TRY: 'checkbox'\n+        AUD: 'checkbox'\n+        BRL: 'checkbox'\n+        CAD: 'checkbox'\n+        CNY: 'checkbox'\n+        HKD: 'checkbox'\n+        IDR: 'checkbox'\n+        ILS: 'checkbox'\n+        INR: 'checkbox'\n+        KRW: 'checkbox'\n+        MXN: 'checkbox'\n+        MYR: 'checkbox'\n+        NZD: 'checkbox'\n+        PHP: 'checkbox'\n+        SGD: 'checkbox'\n+        THB: 'checkbox'\n+        ZAR: 'checkbox'\n+    models:\n+        currencyrate: CurrencyRate\n+\n+    # Define model requests.\n+    init: (callback) ->\n+        map = (doc) -> emit doc.date, doc\n+        CurrencyRate.defineRequest 'byDate', map, (err) ->\n+            callback err\n+\n+    # Fetch rates data from the ECB website and save them as Cozy objects.\n+    fetch: (requiredFields, callback) ->\n+        log.info 'import started'\n+\n+        # TODO Compute the last recent (max 90 days old) rates we know.\n+        lastRates = {}\n+\n+        yesterday = moment().subtract('days', 1).format('YYYY-MM-DD')\n+\n+        # Figure out how far back in time we need to fetch.\n+        url = dailyUrl\n+        for currency of CURRENCIES\n+            if !requiredFields[currency] #.checked ?\n+                # We don't care about this currency.\n+                continue\n+            date = lastRates[currency].date","path":"server/konnectors/currencies.coffee","position":null,"original_position":113,"commit_id":"97b025ca0f9ff3d8a4aff36245b7cfd5548a877e","original_commit_id":"9ee88926dac05fbd3b24eab76911efdc0342b738","user":{"login":"jankeromnes","id":599268,"avatar_url":"https://avatars.githubusercontent.com/u/599268?v=3","gravatar_id":"","url":"https://api.github.com/users/jankeromnes","html_url":"https://github.com/jankeromnes","followers_url":"https://api.github.com/users/jankeromnes/followers","following_url":"https://api.github.com/users/jankeromnes/following{/other_user}","gists_url":"https://api.github.com/users/jankeromnes/gists{/gist_id}","starred_url":"https://api.github.com/users/jankeromnes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jankeromnes/subscriptions","organizations_url":"https://api.github.com/users/jankeromnes/orgs","repos_url":"https://api.github.com/users/jankeromnes/repos","events_url":"https://api.github.com/users/jankeromnes/events{/privacy}","received_events_url":"https://api.github.com/users/jankeromnes/received_events","type":"User","site_admin":false},"body":"I hope `?.` will do the trick.","created_at":"2015-03-08T02:01:30Z","updated_at":"2015-03-08T02:01:30Z","html_url":"https://github.com/cozy-labs/konnectors/pull/44#discussion_r26001561","pull_request_url":"https://api.github.com/repos/cozy-labs/konnectors/pulls/44","_links":{"self":{"href":"https://api.github.com/repos/cozy-labs/konnectors/pulls/comments/26001561"},"html":{"href":"https://github.com/cozy-labs/konnectors/pull/44#discussion_r26001561"},"pull_request":{"href":"https://api.github.com/repos/cozy-labs/konnectors/pulls/44"}}},"pull_request":{"url":"https://api.github.com/repos/cozy-labs/konnectors/pulls/44","id":30704055,"html_url":"https://github.com/cozy-labs/konnectors/pull/44","diff_url":"https://github.com/cozy-labs/konnectors/pull/44.diff","patch_url":"https://github.com/cozy-labs/konnectors/pull/44.patch","issue_url":"https://api.github.com/repos/cozy-labs/konnectors/issues/44","number":44,"state":"open","locked":false,"title":"Add currencies konnector","user":{"login":"jankeromnes","id":599268,"avatar_url":"https://avatars.githubusercontent.com/u/599268?v=3","gravatar_id":"","url":"https://api.github.com/users/jankeromnes","html_url":"https://github.com/jankeromnes","followers_url":"https://api.github.com/users/jankeromnes/followers","following_url":"https://api.github.com/users/jankeromnes/following{/other_user}","gists_url":"https://api.github.com/users/jankeromnes/gists{/gist_id}","starred_url":"https://api.github.com/users/jankeromnes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jankeromnes/subscriptions","organizations_url":"https://api.github.com/users/jankeromnes/orgs","repos_url":"https://api.github.com/users/jankeromnes/repos","events_url":"https://api.github.com/users/jankeromnes/events{/privacy}","received_events_url":"https://api.github.com/users/jankeromnes/received_events","type":"User","site_admin":false},"body":"I'm adding a Konnector to import reference exchange rates for currencies, imported from the European Central Bank [website](https://www.ecb.europa.eu/stats/eurofxref/), because we need them for Kresus.\r\n\r\nThe Konnector is close to working, and I need some help. @frankrousseau could you please have a look?","created_at":"2015-03-07T15:16:44Z","updated_at":"2015-03-08T02:01:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"97f99ba70f7edc26f3340202e4dde6a9d3d17294","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cozy-labs/konnectors/pulls/44/commits","review_comments_url":"https://api.github.com/repos/cozy-labs/konnectors/pulls/44/comments","review_comment_url":"https://api.github.com/repos/cozy-labs/konnectors/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cozy-labs/konnectors/issues/44/comments","statuses_url":"https://api.github.com/repos/cozy-labs/konnectors/statuses/97b025ca0f9ff3d8a4aff36245b7cfd5548a877e","head":{"label":"jankeromnes:currencies","ref":"currencies","sha":"97b025ca0f9ff3d8a4aff36245b7cfd5548a877e","user":{"login":"jankeromnes","id":599268,"avatar_url":"https://avatars.githubusercontent.com/u/599268?v=3","gravatar_id":"","url":"https://api.github.com/users/jankeromnes","html_url":"https://github.com/jankeromnes","followers_url":"https://api.github.com/users/jankeromnes/followers","following_url":"https://api.github.com/users/jankeromnes/following{/other_user}","gists_url":"https://api.github.com/users/jankeromnes/gists{/gist_id}","starred_url":"https://api.github.com/users/jankeromnes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jankeromnes/subscriptions","organizations_url":"https://api.github.com/users/jankeromnes/orgs","repos_url":"https://api.github.com/users/jankeromnes/repos","events_url":"https://api.github.com/users/jankeromnes/events{/privacy}","received_events_url":"https://api.github.com/users/jankeromnes/received_events","type":"User","site_admin":false},"repo":{"id":30727115,"name":"konnectors","full_name":"jankeromnes/konnectors","owner":{"login":"jankeromnes","id":599268,"avatar_url":"https://avatars.githubusercontent.com/u/599268?v=3","gravatar_id":"","url":"https://api.github.com/users/jankeromnes","html_url":"https://github.com/jankeromnes","followers_url":"https://api.github.com/users/jankeromnes/followers","following_url":"https://api.github.com/users/jankeromnes/following{/other_user}","gists_url":"https://api.github.com/users/jankeromnes/gists{/gist_id}","starred_url":"https://api.github.com/users/jankeromnes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jankeromnes/subscriptions","organizations_url":"https://api.github.com/users/jankeromnes/orgs","repos_url":"https://api.github.com/users/jankeromnes/repos","events_url":"https://api.github.com/users/jankeromnes/events{/privacy}","received_events_url":"https://api.github.com/users/jankeromnes/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jankeromnes/konnectors","description":"Import data in your Cozy","fork":true,"url":"https://api.github.com/repos/jankeromnes/konnectors","forks_url":"https://api.github.com/repos/jankeromnes/konnectors/forks","keys_url":"https://api.github.com/repos/jankeromnes/konnectors/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jankeromnes/konnectors/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jankeromnes/konnectors/teams","hooks_url":"https://api.github.com/repos/jankeromnes/konnectors/hooks","issue_events_url":"https://api.github.com/repos/jankeromnes/konnectors/issues/events{/number}","events_url":"https://api.github.com/repos/jankeromnes/konnectors/events","assignees_url":"https://api.github.com/repos/jankeromnes/konnectors/assignees{/user}","branches_url":"https://api.github.com/repos/jankeromnes/konnectors/branches{/branch}","tags_url":"https://api.github.com/repos/jankeromnes/konnectors/tags","blobs_url":"https://api.github.com/repos/jankeromnes/konnectors/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jankeromnes/konnectors/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jankeromnes/konnectors/git/refs{/sha}","trees_url":"https://api.github.com/repos/jankeromnes/konnectors/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jankeromnes/konnectors/statuses/{sha}","languages_url":"https://api.github.com/repos/jankeromnes/konnectors/languages","stargazers_url":"https://api.github.com/repos/jankeromnes/konnectors/stargazers","contributors_url":"https://api.github.com/repos/jankeromnes/konnectors/contributors","subscribers_url":"https://api.github.com/repos/jankeromnes/konnectors/subscribers","subscription_url":"https://api.github.com/repos/jankeromnes/konnectors/subscription","commits_url":"https://api.github.com/repos/jankeromnes/konnectors/commits{/sha}","git_commits_url":"https://api.github.com/repos/jankeromnes/konnectors/git/commits{/sha}","comments_url":"https://api.github.com/repos/jankeromnes/konnectors/comments{/number}","issue_comment_url":"https://api.github.com/repos/jankeromnes/konnectors/issues/comments{/number}","contents_url":"https://api.github.com/repos/jankeromnes/konnectors/contents/{+path}","compare_url":"https://api.github.com/repos/jankeromnes/konnectors/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jankeromnes/konnectors/merges","archive_url":"https://api.github.com/repos/jankeromnes/konnectors/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jankeromnes/konnectors/downloads","issues_url":"https://api.github.com/repos/jankeromnes/konnectors/issues{/number}","pulls_url":"https://api.github.com/repos/jankeromnes/konnectors/pulls{/number}","milestones_url":"https://api.github.com/repos/jankeromnes/konnectors/milestones{/number}","notifications_url":"https://api.github.com/repos/jankeromnes/konnectors/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jankeromnes/konnectors/labels{/name}","releases_url":"https://api.github.com/repos/jankeromnes/konnectors/releases{/id}","created_at":"2015-02-12T22:20:24Z","updated_at":"2015-03-07T19:53:56Z","pushed_at":"2015-03-08T01:55:05Z","git_url":"git://github.com/jankeromnes/konnectors.git","ssh_url":"git@github.com:jankeromnes/konnectors.git","clone_url":"https://github.com/jankeromnes/konnectors.git","svn_url":"https://github.com/jankeromnes/konnectors","homepage":null,"size":2699,"stargazers_count":0,"watchers_count":0,"language":"CoffeeScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"cozy-labs:master","ref":"master","sha":"f69aaaa928df77451c59deec1b22180670054e08","user":{"login":"cozy-labs","id":8415593,"avatar_url":"https://avatars.githubusercontent.com/u/8415593?v=3","gravatar_id":"","url":"https://api.github.com/users/cozy-labs","html_url":"https://github.com/cozy-labs","followers_url":"https://api.github.com/users/cozy-labs/followers","following_url":"https://api.github.com/users/cozy-labs/following{/other_user}","gists_url":"https://api.github.com/users/cozy-labs/gists{/gist_id}","starred_url":"https://api.github.com/users/cozy-labs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cozy-labs/subscriptions","organizations_url":"https://api.github.com/users/cozy-labs/orgs","repos_url":"https://api.github.com/users/cozy-labs/repos","events_url":"https://api.github.com/users/cozy-labs/events{/privacy}","received_events_url":"https://api.github.com/users/cozy-labs/received_events","type":"Organization","site_admin":false},"repo":{"id":15378288,"name":"konnectors","full_name":"cozy-labs/konnectors","owner":{"login":"cozy-labs","id":8415593,"avatar_url":"https://avatars.githubusercontent.com/u/8415593?v=3","gravatar_id":"","url":"https://api.github.com/users/cozy-labs","html_url":"https://github.com/cozy-labs","followers_url":"https://api.github.com/users/cozy-labs/followers","following_url":"https://api.github.com/users/cozy-labs/following{/other_user}","gists_url":"https://api.github.com/users/cozy-labs/gists{/gist_id}","starred_url":"https://api.github.com/users/cozy-labs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cozy-labs/subscriptions","organizations_url":"https://api.github.com/users/cozy-labs/orgs","repos_url":"https://api.github.com/users/cozy-labs/repos","events_url":"https://api.github.com/users/cozy-labs/events{/privacy}","received_events_url":"https://api.github.com/users/cozy-labs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cozy-labs/konnectors","description":"Import data in your Cozy","fork":false,"url":"https://api.github.com/repos/cozy-labs/konnectors","forks_url":"https://api.github.com/repos/cozy-labs/konnectors/forks","keys_url":"https://api.github.com/repos/cozy-labs/konnectors/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cozy-labs/konnectors/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cozy-labs/konnectors/teams","hooks_url":"https://api.github.com/repos/cozy-labs/konnectors/hooks","issue_events_url":"https://api.github.com/repos/cozy-labs/konnectors/issues/events{/number}","events_url":"https://api.github.com/repos/cozy-labs/konnectors/events","assignees_url":"https://api.github.com/repos/cozy-labs/konnectors/assignees{/user}","branches_url":"https://api.github.com/repos/cozy-labs/konnectors/branches{/branch}","tags_url":"https://api.github.com/repos/cozy-labs/konnectors/tags","blobs_url":"https://api.github.com/repos/cozy-labs/konnectors/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cozy-labs/konnectors/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cozy-labs/konnectors/git/refs{/sha}","trees_url":"https://api.github.com/repos/cozy-labs/konnectors/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cozy-labs/konnectors/statuses/{sha}","languages_url":"https://api.github.com/repos/cozy-labs/konnectors/languages","stargazers_url":"https://api.github.com/repos/cozy-labs/konnectors/stargazers","contributors_url":"https://api.github.com/repos/cozy-labs/konnectors/contributors","subscribers_url":"https://api.github.com/repos/cozy-labs/konnectors/subscribers","subscription_url":"https://api.github.com/repos/cozy-labs/konnectors/subscription","commits_url":"https://api.github.com/repos/cozy-labs/konnectors/commits{/sha}","git_commits_url":"https://api.github.com/repos/cozy-labs/konnectors/git/commits{/sha}","comments_url":"https://api.github.com/repos/cozy-labs/konnectors/comments{/number}","issue_comment_url":"https://api.github.com/repos/cozy-labs/konnectors/issues/comments{/number}","contents_url":"https://api.github.com/repos/cozy-labs/konnectors/contents/{+path}","compare_url":"https://api.github.com/repos/cozy-labs/konnectors/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cozy-labs/konnectors/merges","archive_url":"https://api.github.com/repos/cozy-labs/konnectors/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cozy-labs/konnectors/downloads","issues_url":"https://api.github.com/repos/cozy-labs/konnectors/issues{/number}","pulls_url":"https://api.github.com/repos/cozy-labs/konnectors/pulls{/number}","milestones_url":"https://api.github.com/repos/cozy-labs/konnectors/milestones{/number}","notifications_url":"https://api.github.com/repos/cozy-labs/konnectors/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cozy-labs/konnectors/labels{/name}","releases_url":"https://api.github.com/repos/cozy-labs/konnectors/releases{/id}","created_at":"2013-12-22T16:24:12Z","updated_at":"2015-03-03T15:34:05Z","pushed_at":"2015-03-03T15:34:05Z","git_url":"git://github.com/cozy-labs/konnectors.git","ssh_url":"git@github.com:cozy-labs/konnectors.git","clone_url":"https://github.com/cozy-labs/konnectors.git","svn_url":"https://github.com/cozy-labs/konnectors","homepage":null,"size":3625,"stargazers_count":4,"watchers_count":4,"language":"CoffeeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":7,"forks":5,"open_issues":7,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cozy-labs/konnectors/pulls/44"},"html":{"href":"https://github.com/cozy-labs/konnectors/pull/44"},"issue":{"href":"https://api.github.com/repos/cozy-labs/konnectors/issues/44"},"comments":{"href":"https://api.github.com/repos/cozy-labs/konnectors/issues/44/comments"},"review_comments":{"href":"https://api.github.com/repos/cozy-labs/konnectors/pulls/44/comments"},"review_comment":{"href":"https://api.github.com/repos/cozy-labs/konnectors/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cozy-labs/konnectors/pulls/44/commits"},"statuses":{"href":"https://api.github.com/repos/cozy-labs/konnectors/statuses/97b025ca0f9ff3d8a4aff36245b7cfd5548a877e"}}}}