Collect reviews via Twitter.
A tweet is considered a review if it's of the following format:
@client #ratingHashTag #productHashTag review text
For example:
@tshacktoberfest The #vue stroller is like a race car for my niece. She loves the cup holders! #5stars #durable
(source: https://twitter.com/mitchheard/status/534465429800890370)
First, install/update and start MongoDB:
# alternatively, run `brew upgrade --cleanup mongodb` if mongodb is already installed
brew install mongodb
# you can create and use any dbpath, just DO NOT use a directory within this repo!
mkdir ~/_mongodb
mongod --dbpath ~/_mongodb/
Then, open a new Terminal and create the tweeviews database:
# start mongo shell (automatically connects to localhost)
mongo
# create and switch to the tweeviews db
> use tweeviews
# create an un-capped collection to avoid deleting old data when at-cap
> db.createCollection("clients", {capped: false})
# exit or stay, whatever
> exit
At this point, you can clone the repo and run the app:
# alternatively, run `brew upgrade --cleanup node` if node is already installed
brew install node
git clone [email protected]:95civicdude/tweeviews.git
cd tweeviews
npm install
npm start
To add or update a client: http://localhost:3000/clients/
To add, update, or end a campaign: http://localhost:3000/campaigns/
The app expects the following mongodb document format:
{
"_id" : ObjectId("xxxxxxxxx"), // unique object id, auto-generated by mongo
"name" : "xxxxxxxxx", // unique client name
"apiKey" : "xxxxxxxxx", // BV API key for Tweeviews use
"encodingKey" : "xxxxxxxxx", // BV shared encoding key
"twitterHandle" : "xxxxxxxxx", // client's Twitter account
"consumerKey": "xxxxxxxxx", // client-specific Twitter API consumer key
"consumerSecret": "xxxxxxxxx", // client-specific Twitter API consumer secret
"accessTokenKey": "xxxxxxxxx", // client-specific Twitter API access token key
"accessTokenSecret": "xxxxxxxxx", // client-specific Twitter API access token secret
"searchInterval" : 0, // milliseconds between Twitter searches (0 to stop searching)
"products" : [ // array of products with Teeviews campaigns
{
"externalId" : "0000", // BV product id
"hashTag" : "tag", // hashtag to identify the product on Twitter (note: no hash sign)
"start" : 0000000000000, // start date of the campaign (milliseconds since Unix epoch)
"end" : 0000000000000 // end date of the campaign (milliseconds since Unix epoch)
},
{
"externalId" : "0001",
"hashTag" : "tag2",
"start" : 0000000000000,
"end" : null // note: end may be null
}
]
}
To work in the db, directly, launch mongo
in Terminal and run mongodb collection methods against tweeviews's clients collection. For example:
mongo
> use tweeviews
# see all collections
> db.getCollectionNames()
# get the number of client docs
> db.clients.count()
# find a client by some field within the client doc schema
> db.clients.find({"name":"jeffs-testcompany"})
The node app uses the mongodb npm package with singleton db and collections objects created at server start via dbConnection.js. You probably will never need to access the db object; just use the collections object. To work on documents, do this:
var dbConnection = require("dbConnection.js");
dbConnection.getCollection(function(clientsCollection) {
// find a client by name
clientsCollection.find({
"name" : "jeffs-testcompany"
// loop over each client found with the given name
}).each(function(err, clientDoc) {
if (err) {
throw err;
}
if (clientDoc) {
// do stuff with the client document
console.log(JSON.stringify(clientDoc, null, " "));
}
});
});
To turn the Twitter poller on or off, set data.twitterPoller.pollingInterval = n
in config.js where n is some time value in milliseconds (0 = off).
Place configuration settings in config.js.