Hi,
This is going to be a two-step process for you. Your app now does two
things:
1. Track tweets and save them to DB.
2. On rendering Index page, displays those tweets.
You want to change the following:
- change the tracking keyword based on url
- fetch only such keyworded tweets.
The first part is simple.
Instead of the part:
app.get('/', routes.index), you will have app.get('/:keyword',
routes.keywordIndex);
And the routes.keywordIndex is a function that starts loading only
functions by that keyword
You will have to alter the tweet model slightly:
- add a 'keyword' property (and save it from that nTwitter stream, along
with tweet data).
- add a keyword parameter to Tweet.getTweets that will only search such
tweets. (And take it into account with paging.
Then alter the bottom part of server.js - instead of starting to fetch
right away, put the twit.stream(...) in a function that will take a
keyword. It will only start running (fetching stream) as you call this
function from route handler.
I think that nTwitter can only be used for one stream given one API key,
but not sure on that. Check it yourself, and if it's true, this will be a
single-user app :)
Here, I've given you one possible plan, but it's on you to start hacking
into details, and hit stackoverflow when stuck.
On Tuesday, March 3, 2015 at 5:45:22 PM UTC+1, Aryak Sengupta wrote:
>
> Any kind of help would be appreciated. I need to know whether I am moving
> in the right direction. Is it the way to do it? Or am I doing something
> terribly wrong. If my question needs further clarification, then please let
> me know. I'll try to phrase my question in a different manner.
>
> Thanks :)
>
> On Tue, Mar 3, 2015 at 12:59 PM, Aryak Sengupta <[email protected]
> <javascript:>> wrote:
>
>> Hi everyone,
>>
>> I am new to Nodejs and Socket.io. I have worked through a tutorial which
>> describes how both the technologies work together.
>>
>> *The link to the tutorial is this :--- > Build a real-time Twitter
>> stream
>> <https://scotch.io/tutorials/build-a-real-time-twitter-stream-with-node-and-react-js>
>> and
>> the code **for the tutorial **is posted at github :---> Code of
>> react-tweets <https://github.com/scotch-io/react-tweets>. *
>>
>> Everything works fine in the tutorial and I also have no issues in
>> understanding the code since the code is well commented.
>>
>>
>>
>> * In the server.js file, the tracking keyword which is "javascript" is
>> manually fed into the "twit" object. i.e. here is the code for it. *
>> *twit.stream('statuses/filter',{ track: 'javascript'}, function(stream){*
>> * streamHandler(stream,io);*
>> *});*
>>
>>
>>
>> *But I want to make a minor alteration in the code to make the
>> application a bit more versatile. I want to change the tracking keyword
>> dynamically using the URL entered by the user.*For example, if the URL
>> entered is *http://localhost/football <http://localhost/football>*, then
>> automatically I want the track keyword to be changed to "*football*".
>> The code should look like
>>
>> *twit.stream('statuses/filter',{ track: 'football'}, function(stream){*
>> * streamHandler(stream,io);*
>> *});*
>>
>> Now, I tried to set this object inside the *app.get("/cricket",
>> twit.stream.......); *function but I get an error "Expected callback got
>> object" .
>>
>> How do I change the above mentioned code to achieve this?. Please let me
>> know.
>>
>> Thanks a lot.
>>
>>
>
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/517362b9-c36c-4cab-954b-a75f884447c7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.