Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › Help with Javascript and APIs
New Posts  All Forums:Forum Nav:

Help with Javascript and APIs

post #1 of 2
Thread Starter 
Hey all, I decided to finally give a try at the world of API development with Twitter and decided to start with a contest bot after reading an article by a guy about all the stuff he won using one. (Hooray for greed crossing with programming!)

Anyways, I found a bot written in JS already that had many of the functions that I desired, only problem so far is it doesn't seem to have a rate limiter set up for how many tweets it can do, and for some reason can't filter out retweets despite theoretically being able to do so.

I was hoping that someone around here with a bit more knowledge could help me out here. I would like to make it so that the retweetWorker() function will be able to call back to the errorHandler function and update how often it tries to retweet if you hit the limit (about 300 tweets every 3 hour interval-ish). And then find a way to filter out all the retweets, though that's secondary for now. Here's the code.

https://github.com/raulrene/Twitter-ContestJS-bot

Thanks if you can help, thanks if you can't but bothered reading to this point!
Dynamix
(15 items)
 
  
CPUMotherboardGraphicsRAM
i7-860 Gigabyte GA-P55A-UD4P Radeon 7970 Corsair Domintor Twins + Other = 16 Gb 
Hard DriveHard DriveOptical DriveCooling
WD Caviar Black, 500gb OCZ Solid 3 Sony Optiarc Corsair H50 
OSMonitorKeyboardPower
Windows 7 Ultimate Samsung P2570HD + Other Logitech G110 Corsair 750W HX 
CaseMouse
Antec p183 Logitech MX Revolution 
  hide details  
Reply
Dynamix
(15 items)
 
  
CPUMotherboardGraphicsRAM
i7-860 Gigabyte GA-P55A-UD4P Radeon 7970 Corsair Domintor Twins + Other = 16 Gb 
Hard DriveHard DriveOptical DriveCooling
WD Caviar Black, 500gb OCZ Solid 3 Sony Optiarc Corsair H50 
OSMonitorKeyboardPower
Windows 7 Ultimate Samsung P2570HD + Other Logitech G110 Corsair 750W HX 
CaseMouse
Antec p183 Logitech MX Revolution 
  hide details  
Reply
post #2 of 2
It is in there
Code:
     RATE_LIMIT_EXCEEDED_TIMEOUT = 1000 * 60 * 10,   // 10 minutes
        RETWEET_TIMEOUT = 1000 * 5;                                     // 5 seconds


You see the RETWEET_TIMEOUT at the bottom, this waits Basically this setTimeout function is a function where you pass it another function and it will run that function after the given time. If you see at the bottom of that function, it calls retweetWorker again, thus causing it to do the wait and then call itself again. Javascript has no "wait" function, so this is what people do with stuff like this. ... well kinda... there is also an interval one, but yeah. If you want to wait 10 seconds then run the rest of your code... you gotta do it like this... kinda annoying, but it has its reasons.
Code:
     var retweetWorker = function () {

                setTimeout(function () {

                        // Check if we have elements in the Result Array
                        if (searchResultsArr.length) {

                                // Pop the first element (by doing a shift() operation)
                                var searchItem = searchResultsArr[0];   
                                searchResultsArr.shift();
                                
                                // Retweet
                                API.retweet(searchItem.id_str);
                                console.log("Retweet", searchItem.id);

                                // Check if we also need to Favorite
                                if (searchItem.text.toLowerCase().indexOf("fav") > -1) {
                                        API.favorite(searchItem.id_str);
                                        console.log("Favorite", searchItem.id);
                                } 

                                if (searchItem.text.toLowerCase().indexOf("follow") > -1) {
                                        API.follow(searchItem.user.id_str);
                                        console.log("Follow", searchItem.user.screen_name);
                                }
                        }       

                        retweetWorker();
                }, RETWEET_TIMEOUT);
        }
Zev's Comp
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5-2500K Sandy Bridge 3.3GHz GIGABYTE GA-Z68X-UD3H-B3 LGA 1155 Intel Z68 HDM... GeForce GTX 750 Ti G.SKILL Ripjaws X Series 8GB 
Hard DriveHard DriveHard DrivePower
1TB HDD 64GB SSD (Used for SRT) 500 GB. Antec BP550 Plus 550W Continuous Power ATX12V V... 
Case
COOLER MASTER ELITE 335 RC-335-KKN1-GP Black S... 
  hide details  
Reply
Zev's Comp
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5-2500K Sandy Bridge 3.3GHz GIGABYTE GA-Z68X-UD3H-B3 LGA 1155 Intel Z68 HDM... GeForce GTX 750 Ti G.SKILL Ripjaws X Series 8GB 
Hard DriveHard DriveHard DrivePower
1TB HDD 64GB SSD (Used for SRT) 500 GB. Antec BP550 Plus 550W Continuous Power ATX12V V... 
Case
COOLER MASTER ELITE 335 RC-335-KKN1-GP Black S... 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Web Coding
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › Help with Javascript and APIs