-
Notifications
You must be signed in to change notification settings - Fork 35
CrowdTangle Integration #325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
90 commits
Select commit
Hold shift + click to select a range
cd3b375
Added crowd-tangle content service
TheDanieLNK 48231ec
Update content service factory
TheDanieLNK 11c00bd
Added crowdtangle test service
TheDanieLNK 41f5335
Corrected typo in test file
TheDanieLNK c110d59
Add empty test fixture and new unit test
TheDanieLNK 77b5a2d
Added new test fixture and updated ct test service
TheDanieLNK e9a1315
Update lib.fetching.content-service.crowd-tangle-content-service.test.js
TheDanieLNK fc1c0e4
Update lib.fetching.content-service.crowd-tangle-content-service.test.js
TheDanieLNK aea7c9c
Added new fixtures and updated test service
TheDanieLNK 76cf6e7
Updated fixture
TheDanieLNK 6efaa2e
Updated crowdtangle test service
TheDanieLNK 5b15584
Update test service
TheDanieLNK 0dafafa
Update ct test service
TheDanieLNK b261d2d
Slight change
TheDanieLNK 1c1528e
Update
TheDanieLNK 858d07e
Updata ct test service
TheDanieLNK 6ef022c
Add console log to inspect
TheDanieLNK dbd473a
Last test check for ct_id
TheDanieLNK 9c9616b
Finished test for now :)
TheDanieLNK ed1ffd7
Added debug one-liner
TheDanieLNK 9bdfa78
Update .gitignore
TheDanieLNK 2ffc086
Update crowd-tangle-content-service.js
TheDanieLNK 2abf699
Update crowd-tangle-content-service.js
TheDanieLNK ab3358a
Update crowd-tangle-content-service.js
TheDanieLNK 79e8a89
Update service and test
TheDanieLNK 560067e
Update crowd-tangle-content-service.js
TheDanieLNK 5eb44ac
Update crowd-tangle-content-service.js
TheDanieLNK 6267a62
Update fixtures
TheDanieLNK 3a12736
Added crowdtangle to media list
TheDanieLNK b5c2345
Added facebook as descriptor for crowdtangle
TheDanieLNK c599216
temporarily removed whatsapp from media list
TheDanieLNK 91ece58
change options in source ctrl
TheDanieLNK c806003
edit angular config
TheDanieLNK f66f57e
Update modal.html
TheDanieLNK f1d9c73
Edited media options for GY deployment
TheDanieLNK ab2731f
Edited translations file
TheDanieLNK e257788
Added crowdtangle add source changes
TheDanieLNK 288370f
Resolved merge conflicts
TheDanieLNK 002ad67
Adding ct data to frontend
TheDanieLNK 6aae236
Crowdtangle end-to-end works; needs clean up
TheDanieLNK 7ee9472
added check for burmese encoding
harshilshah4251 7b35ecd
Changed crowdtangle logo in reports to facebook
TheDanieLNK 5b2a1df
Merge branch 'ct_integration' into harshil_dev
harshilshah4251 9a13665
replaced hardcoded value
harshilshah4251 cabf6f6
Merge pull request #280 from TID-Lab/harshil_dev
TheDanieLNK 9521373
Added list to crowdtangle search list
TheDanieLNK cc016cb
resolved merge conflict with add burmese language tools
TheDanieLNK 80c5e56
Removed media<->source filter
TheDanieLNK d5a6ff8
Perform zawgyi conversion on author names
TheDanieLNK a6db7dc
added encoding check to twitter, whatsapp, rss
harshilshah4251 6bc81cd
added encoding check to twitter, whatsapp, rss
harshilshah4251 c1aa988
Removed stub comments from ct_content-service
TheDanieLNK 7935c01
Merge branch 'ct_integration' into harshil_dev
TheDanieLNK 4bea120
Added a facebook section for the API Auth in settings
sripushkar b5dba34
Merge pull request #281 from TID-Lab/harshil_dev
TheDanieLNK ac50ff1
Update README with more dev setup info
cooperka ac7ebd3
Added code to get list name in crowdtangle content service
TheDanieLNK cd014d2
Removed slack because we don't use that API anymore and PrettyJSON be…
ae255cd
Working Crowdtangle List Tags
1d6b0c6
Store CT media url and statistics in database
mkyaw6 c10146b
Add continuous calls to CT api
mkyaw6 6710d04
Cleaned up white space in crowdtangle accountid-listname json pairs
TheDanieLNK dbc0072
Removed myanmar-tools from devdependencies. Already in dependencies
TheDanieLNK 355c094
Removed straying console logged error
TheDanieLNK 1ecd989
Reintroduced previous media options for future use
TheDanieLNK f62fc24
Removed hardcoded crowdtangle option from settings. if we wanted to h…
TheDanieLNK 488b273
Removed commented code. We do not required users to enter dashboard a…
TheDanieLNK f8dc695
Removed case variations of crowdtangle in translations; retained one.
TheDanieLNK ee5c2bb
Removed stray TODO
TheDanieLNK e1503d0
Replaced setTimeout with process.nextTick to ensure all test reports …
TheDanieLNK bd16142
Removed setInterval called within crowdtangle context service. Crowdt…
TheDanieLNK 69f4c73
Changed Crowdtangle's API call to happen twice per minute re: Crowdta…
TheDanieLNK 49583f9
Corrected missing comma in JSON
TheDanieLNK d1c31ba
Added config to rss content service
TheDanieLNK d385948
Added config to whatsapp content service
TheDanieLNK bcf3ec6
Added crowdtangle to spanish translation
TheDanieLNK d3edf70
added acct id <-> list name
harshilshah4251 e7136a3
added acct id <-> list name
harshilshah4251 ba6c78f
Edited order and formatting.
harshilshah4251 5c2c559
Added sample secrets.json file
TheDanieLNK 14fa15e
Call CT API based on last report date to avoid duplicates
mkyaw6 42e47d6
Store raw api response
mkyaw6 5454366
Merge branch 'develop' into ct_integration
karpawich 7828cac
fix: remove Zawgyi detection & conversion from content services
karpawich 41a6432
fix: keep all implemented Sources available
karpawich 9b715a1
fix: remove CrowdTangle id's for Myanmar
karpawich 3e4baec
docs: explain labeling CrowdTangle reports as Facebook
karpawich 4d0324b
feat: config shorter interval for CrowdTangle bot
karpawich 8692bea
fix: add back URL field to Source modal
karpawich b3fcf93
test: capitalize Errors
karpawich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,5 +44,4 @@ config/cert.pem | |
|
|
||
| config/key.pem | ||
|
|
||
| docs/_build | ||
|
|
||
| docs/_build | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "crowdtangle_list_account_pairs":{} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
155 changes: 155 additions & 0 deletions
155
lib/fetching/content-services/crowd-tangle-content-service.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| var request = require('request'); | ||
| var url = require('url'); | ||
|
|
||
| var ContentService = require('../content-service'); | ||
| var util = require('util'); | ||
| var config = require('../../../config/secrets'); | ||
| var crowdtangle_lists = require('../../../config/crowdtangle_list'); | ||
|
|
||
| var request = require('request'); | ||
| var _ = require('underscore'); | ||
|
|
||
|
|
||
| //options.lastReportDate is passed here through the content-service-factory and will be utilised in calling the api, but its actually only maintained by the parent content service, it is only utilised by the child | ||
| var CrowdTangleContentService = function(options) { | ||
| this._baseUrl = config.get().crowdtangle.baseUrl; | ||
| this._pathName = config.get().crowdtangle.pathName; | ||
| this._count = config.get().crowdtangle.count; | ||
| this._language = config.get().crowdtangle.language; | ||
| this._sortParameter = config.get().crowdtangle.sortParam; | ||
| this._apiToken = config.get().crowdtangle.apiToken; | ||
| this._keywords = options.keywords; | ||
| this._lastReportDate = options._lastReportDate; | ||
| this._listIds = parseInt(options.tags); | ||
| this.fetchType = 'pull'; | ||
| this.interval = 30000; | ||
| ContentService.call(this, options); //associates the child service with its parent, which has the notion of lastreportdate | ||
| } | ||
|
|
||
|
|
||
| util.inherits(CrowdTangleContentService, ContentService); | ||
|
|
||
| //this method overwrites the _doFetch method in the content-service (which is the parent class) | ||
| //and then inside the content-service, we have a fetch method that is called by the pull-bot and is responsible for emitting (writing) the reports and updating the final value of lastReportDate | ||
| //options.maxCount (present but not used, used by the parent content service) | ||
| //what about types? -- discuss with Michael | ||
| CrowdTangleContentService.prototype._doFetch = function(options, callback) { | ||
| var self = this; | ||
| //handle errors using process.nextTick | ||
| // this will depend mostly on the options that we expect to receive, and if there is issue with that | ||
|
|
||
| // if (!this._url) { | ||
| // process.nextTick(function() { self.emit('error', new Error('Missing URL')); }); | ||
| // return callback([]); | ||
| // } | ||
|
|
||
| //now we need to submit the request | ||
| this._httpRequest( {url: this._completeUrl(options)}, function(err, res, body) { | ||
| if (err) { | ||
| self.emit('error', new Error('HTTP error: ' + err.message)); | ||
| return callback([]); | ||
| } else if (res.statusCode != 200) { | ||
| self.emit('error', new Error.HTTP(res.statusCode)); | ||
| return callback([]); | ||
| } | ||
|
|
||
| //if no errors, parse the body.. | ||
| var responses; | ||
| try { | ||
| responses = JSON.parse(body).result.posts; | ||
| if (!(responses instanceof Array)) { | ||
| self.emit('error', new Error('Wrong data')); | ||
| return callback([]); | ||
| } | ||
| // any other error handling wrt the structure of responses | ||
| } catch (e) { | ||
| self.emit('error', new Error('Parse error: ' + e.message)); | ||
| return callback([]); | ||
| } | ||
| // the responses will be sorted by the content-service (parent method) | ||
| // Parse response data and return them. | ||
| var reportData = responses.map(function(x) { return self._parse(x); }); | ||
| callback(reportData); | ||
| }) | ||
| }; | ||
|
|
||
| CrowdTangleContentService.prototype._httpRequest = function(params, callback) { | ||
| request(params, callback); | ||
| }; | ||
|
|
||
| CrowdTangleContentService.prototype._completeUrl = function() { | ||
| // add one second to last report date to start fetching from | ||
| var startDate = new Date(this._lastReportDate.getTime() + 1000).toISOString(); | ||
| return url.format({ | ||
| protocol: 'https', | ||
| hostname: this._baseUrl, | ||
| pathname: this._pathName, | ||
| query: { | ||
| token: this._apiToken, | ||
| count: this._count, | ||
| language: this._language, | ||
| listIds: this._listIds, | ||
| searchTerm: this._keywords, | ||
| sortBy: this._sortParameter, | ||
| startDate: startDate, | ||
| endDate: new Date().toISOString() | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| CrowdTangleContentService.prototype._parse = function(data) { | ||
|
|
||
| var metadata = { | ||
| sponsor: data.brandedContentSponsor || null, | ||
| caption: data.caption || null, | ||
| description: data.description || null, | ||
| title: data.title || null, | ||
| crowdtangleId: data.id || null, | ||
| externalUrl: data.link || null, | ||
| platform: data.platform || null, | ||
| type: data.type || null, | ||
| accountVerified: data.account ? data.account.verified : false, | ||
| accountHandle: data.account ? data.account.handle : null, | ||
| subscriberCount: data.account ? data.account.subscriberCount : 0, | ||
| accountUrl: data.account ? data.account.url : null, | ||
| mediaUrl: data.media? data.media.map(function(medium) { | ||
| return {type: medium.type, url: medium.url} | ||
| }) : null, | ||
| actualStatistics: data.statistics.actual, | ||
| expectedStatistics: data.statistics.expected, | ||
| rawAPIResponse: data | ||
| }; | ||
| var text = data.message || data.description || data.title || data.caption || "[No Content]"; // TODO need to revisit, what if there is no text? what about youtube case | ||
| var author = data.account ? data.account.name || data.account.handle : null; | ||
|
|
||
| // This code deals specifically with matching a crowdtangle list to a report's account id | ||
| this.crowdtangle_lists = crowdtangle_lists.crowdtangle_list_account_pairs; | ||
| // If the list is found and matched, then the ct_tag is the list name | ||
| if (this.crowdtangle_lists[data.account.id]) { | ||
| metadata.ct_tag = this.crowdtangle_lists[data.account.id]; | ||
| } else { | ||
| // If the list is not found and not matched, make the ct_tag the account.id so we can identify it later. | ||
| metadata.ct_tag = data.account.id; | ||
| } | ||
|
|
||
| return { | ||
| authoredAt: new Date(data.date + " UTC") || new Date(), | ||
| fetchedAt: new Date(), | ||
| content: text, | ||
| author: author, | ||
| metadata: metadata, | ||
| url: data.postUrl, | ||
| //_sources: '', //need to get this info from somewhere | ||
| //_sourceNicknames: '' | ||
| }; | ||
| } | ||
|
|
||
|
|
||
| CrowdTangleContentService.prototype.reloadSettings = function() { | ||
| this._baseUrl = config.get().crowdtangle.baseUrl; | ||
| this._pathName = config.get().crowdtangle.pathName; | ||
| this._count = config.get().crowdtangle.count; | ||
| this._language = config.get().crowdtangle.language; | ||
| }; | ||
|
|
||
| module.exports = CrowdTangleContentService; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.