├── .gitignore ├── src └── main │ ├── webapp │ ├── META-INF │ │ └── MANIFEST.MF │ ├── images │ │ └── sign-in-with-twitter-gray.png │ ├── WEB-INF │ │ └── web.xml │ ├── favorite.html │ ├── keyword.html │ ├── biokeyword.html │ ├── unfavorite.html │ ├── index.html │ ├── index2.html │ └── unfollow.html │ └── java │ └── com │ ├── utils │ └── Setup.java │ └── sl │ ├── db │ ├── DBException.java │ └── DBConn.java │ ├── pojo │ └── UserPojo.java │ ├── SigninServlet.java │ ├── CallbackServlet.java │ ├── dao │ └── TwitterDAO.java │ ├── PostBiokeyword.java │ ├── PostKeyword.java │ ├── PostFavorite.java │ ├── PostUnfavorite.java │ └── PostUnfollow.java ├── postgresql.txt ├── LICENSE ├── pom.xml └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | Procfile -------------------------------------------------------------------------------- /src/main/webapp/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /src/main/webapp/images/sign-in-with-twitter-gray.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wcrasta/TwitterBoost-Tools/HEAD/src/main/webapp/images/sign-in-with-twitter-gray.png -------------------------------------------------------------------------------- /src/main/java/com/utils/Setup.java: -------------------------------------------------------------------------------- 1 | package com.utils; 2 | 3 | public class Setup { 4 | public static String DB_URL = ""; 5 | public static String CONSUMER_KEY = ""; 6 | public static String CONSUMER_SECRET = ""; 7 | } -------------------------------------------------------------------------------- /postgresql.txt: -------------------------------------------------------------------------------- 1 | CREATE TABLE twitter_user ( 2 | user_id SERIAL PRIMARY KEY NOT NULL, 3 | twitter_user_id bigint NULL, 4 | screen_name varchar(45) NULL, 5 | access_token varchar(100) NULL, 6 | access_token_secret varchar(100) NULL, 7 | created_date TIMESTAMP NULL DEFAULT NOW()); -------------------------------------------------------------------------------- /src/main/java/com/sl/db/DBException.java: -------------------------------------------------------------------------------- 1 | package com.sl.db; 2 | 3 | public class DBException extends Exception { 4 | 5 | private static final long serialVersionUID = 1L; 6 | 7 | private String message; 8 | 9 | public DBException(String string) { 10 | message = string; 11 | } 12 | 13 | public String getMessage() { 14 | return message; 15 | } 16 | 17 | public void setMessage(String message) { 18 | this.message = message; 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | index.html 10 | 11 | 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Warren Crasta 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/main/webapp/favorite.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Favorite Tweets by Keyword 5 | Tools Page 6 | 7 |

Favorite Tweets by Keyword

8 | 9 |

10 | Favorite tweets that contain a certain keyword. The maximum number of tweets you can favorite in 12 | 24 hours is 1000. 13 |

14 | 15 | 16 |
17 | Keyword:
18 | Include RTs: Yes No
Number of tweets to 21 | favorite (max: 1000):

Once you click submit, the server will favorite the 24 | number of tweets you specified, without stopping. If you understand, 25 | re-enter the number of tweets to favorite.

27 |
28 |
29 | 30 | -------------------------------------------------------------------------------- /src/main/webapp/keyword.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Follow Users by Tweet Keyword 5 | Tools Page 6 | 7 |

Follow Users by Tweet Keyword

8 | 9 |

10 | Look for users who tweeted a certain keyword and follow them. The maximum number of users you can follow in 24 12 | hours is 1000. 13 |

14 | 15 | 16 |
17 | Keyword:
18 | Include RTs: Yes No
Number of users to 21 | follow (max: 1000):

Once you click submit, the server will follow the 24 | number of users you specified, without stopping. If you understand, 25 | re-enter the number of users to follow.

27 |
28 |
29 | 30 | -------------------------------------------------------------------------------- /src/main/webapp/biokeyword.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Follow Users by Bio Keyword 5 | Tools Page 6 | 7 |

Follow Users by Bio Keyword

8 | 9 |

10 | Look for users with a certain keyword in their bio and follow them. The maximum number of users you can follow in 24 12 | hours is 1000. 13 |

14 | 15 | 16 |
17 | Keyword:
18 | What page do you want to start on (max: 50):
Number 20 | of users to follow (max: 1000):
There are 20 users/page, 22 | so if you notice that you are following the same people over and over 23 | again, use different pages. In most cases,you should use page 1 first. 24 |

Once you click 25 | submit, the server will follow the number of users you specified, 26 | without stopping. If you understand, re-enter the number of users to 27 | follow.


30 |
31 | 32 | -------------------------------------------------------------------------------- /src/main/java/com/sl/pojo/UserPojo.java: -------------------------------------------------------------------------------- 1 | package com.sl.pojo; 2 | 3 | public class UserPojo 4 | { 5 | private long user_id; 6 | 7 | private long twitter_user_id; 8 | 9 | private String twitter_screen_name; 10 | 11 | private String access_token; 12 | 13 | private String access_token_secret; 14 | 15 | public long getUser_id() { 16 | return user_id; 17 | } 18 | 19 | public void setUser_id(long user_id) { 20 | this.user_id = user_id; 21 | } 22 | 23 | public long getTwitter_user_id() { 24 | return twitter_user_id; 25 | } 26 | 27 | public void setTwitter_user_id(long twitter_user_id) { 28 | this.twitter_user_id = twitter_user_id; 29 | } 30 | 31 | public String getTwitter_screen_name() { 32 | return twitter_screen_name; 33 | } 34 | 35 | public void setTwitter_screen_name(String twitter_screen_name) { 36 | this.twitter_screen_name = twitter_screen_name; 37 | } 38 | 39 | public String getAccess_token() { 40 | return access_token; 41 | } 42 | 43 | public void setAccess_token(String access_token) { 44 | this.access_token = access_token; 45 | } 46 | 47 | public String getAccess_token_secret() { 48 | return access_token_secret; 49 | } 50 | 51 | public void setAccess_token_secret(String access_token_secret) { 52 | this.access_token_secret = access_token_secret; 53 | } 54 | 55 | @Override 56 | public String toString() { 57 | return "UserPojo [user_id=" + user_id + ", twitter_user_id=" 58 | + twitter_user_id + ", twitter_screen_name=" 59 | + twitter_screen_name + ", access_token=" + access_token 60 | + ", access_token_secret=" + access_token_secret + "]"; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/main/webapp/unfavorite.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | Unfavorite tweets 7 | Tools Page 8 | 9 |

Unfavorite tweets

10 | 11 |

Either unfavorite all of your favorited tweets OR unfavorite tweets only 12 | by people you do not follow.

13 | 14 | 15 |
16 | Unfavorite ALL tweets: Yes No
19 | 20 | 25 | 26 | 27 | Once you click submit, the 28 | server will unfavorite your tweets (as chosen above), without stopping. If you 29 | understand, enter "I UNDERSTAND".


32 |
33 | 48 | 49 | -------------------------------------------------------------------------------- /src/main/webapp/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Welcome 5 | 6 | 7 |

Welcome

8 |

9 | This app no longer works. These days I'm busy with work, and 10 | don't have time to find & fix the issue. I suspect that Twitter changed some authentication setting. 11 | The code/logic in the GitHub repo is still functional, so feel free to try and fix the app yourself. 12 | Myself and others would appreciate it! 13 |

14 | Twitter Boost Tools is a FREE web application to boost your Twitter 15 | account stats/follower engagement. For more information and to see the 16 | source code of the project, check out the GitHub 18 | repository. Created by @warrencrasta. Feel free to contact me if you have specific Twitter needs.
20 |

Tools:

21 |
    22 |
  1. Unfollow users who don't follow you (with an option to 23 | save a group of people from being unfollowed). 24 |
  2. 25 |
  3. Follow users based on a keyword they tweeted (can follow a 26 | maximum of 1000 people every 24 hours).
  4. 27 |
  5. Follow users based on a keyword in their bio (can follow a 28 | maximum of 1000 people every 24 hours).
  6. 29 |
  7. Favorite tweets based on a keyword (can favorite a maximum of 30 | 1000 tweets every 24 hours).
  8. 31 |
  9. Unfavorite all (or some) of your favorited tweets.
  10. 32 |
  11. *NEW* ($5) Get 60 verified Twitter followers (accounts with the blue checkmark).
  12. 33 |
34 |
35 | 36 |
37 | 38 | -------------------------------------------------------------------------------- /src/main/webapp/index2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Welcome 5 | 6 | 7 |

Welcome

8 | This app no longer works. These days I'm busy with work, and 9 | don't have time to find & fix the issue. I suspect that Twitter changed some authentication setting. 10 | The code/logic in the GitHub repo is still functional, so feel free to try and fix the app yourself. 11 | Myself and others would appreciate it! 12 |

13 | Twitter Boost Tools is a FREE web application to boost your Twitter 14 | account stats/follower engagement. For more information and to see the 15 | source code of the project, check out the GitHub 17 | repository. Created by @warrencrasta. Feel free to contact me if you have specific Twitter needs.
19 |

Tools:

20 |
    21 |
  1. Unfollow users who don't follow you (with an option to 22 | save a group of people from being unfollowed).
  2. 23 |
  3. Follow users based on a keyword they tweeted (can follow a 24 | maximum of 1000 people every 24 hours).
  4. 25 |
  5. Follow users based on a keyword in their bio (can follow a 26 | maximum of 1000 people every 24 hours).
  6. 27 |
  7. Favorite tweets based on a keyword (can favorite a maximum of 28 | 1000 tweets every 24 hours).
  8. 29 |
  9. Unfavorite all (or some) of your favorited tweets.
  10. 30 |
  11. *NEW* ($5) Get 60 verified Twitter followers (accounts with the blue checkmark).
  12. 31 |
32 | 33 | -------------------------------------------------------------------------------- /src/main/java/com/sl/SigninServlet.java: -------------------------------------------------------------------------------- 1 | package com.sl; 2 | 3 | import twitter4j.Twitter; 4 | import twitter4j.TwitterException; 5 | import twitter4j.TwitterFactory; 6 | import twitter4j.auth.RequestToken; 7 | import twitter4j.conf.ConfigurationBuilder; 8 | 9 | import javax.servlet.ServletException; 10 | import javax.servlet.annotation.WebServlet; 11 | import javax.servlet.http.HttpServlet; 12 | import javax.servlet.http.HttpServletRequest; 13 | import javax.servlet.http.HttpServletResponse; 14 | 15 | import com.utils.Setup; 16 | 17 | import java.io.IOException; 18 | 19 | @WebServlet("/signin") 20 | public class SigninServlet extends HttpServlet { 21 | private static final long serialVersionUID = -6205814293093350242L; 22 | 23 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 24 | // configure twitter api with consumer key and secret key 25 | ConfigurationBuilder cb = new ConfigurationBuilder(); 26 | cb.setDebugEnabled(true) 27 | .setOAuthConsumerKey(Setup.CONSUMER_KEY) 28 | .setOAuthConsumerSecret(Setup.CONSUMER_SECRET); 29 | TwitterFactory tf = new TwitterFactory(cb.build()); 30 | Twitter twitter = tf.getInstance(); 31 | request.getSession().setAttribute("twitter", twitter); 32 | try { 33 | 34 | // setup callback URL 35 | StringBuffer callbackURL = request.getRequestURL(); 36 | int index = callbackURL.lastIndexOf("/"); 37 | callbackURL.replace(index, callbackURL.length(), "").append("/callback"); 38 | 39 | // get request object and save to session 40 | RequestToken requestToken = twitter.getOAuthRequestToken(callbackURL.toString()); 41 | request.getSession().setAttribute("requestToken", requestToken); 42 | 43 | // redirect to twitter authentication URL 44 | response.sendRedirect(requestToken.getAuthenticationURL()); 45 | 46 | } catch (TwitterException e) { 47 | throw new ServletException(e); 48 | } 49 | 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | com.sl 5 | TwitterBoost-Tools 6 | war 7 | 0.0.1-SNAPSHOT 8 | 9 | 10 | org.postgresql 11 | postgresql 12 | 9.4.1212 13 | 14 | 15 | org.twitter4j 16 | twitter4j-core 17 | 4.0.4 18 | 19 | 20 | javax.servlet 21 | javax.servlet-api 22 | 3.0.1 23 | provided 24 | 25 | 26 | 27 | 28 | 29 | com.heroku.sdk 30 | heroku-maven-plugin 31 | 1.1.3 32 | 33 | 34 | maven-compiler-plugin 35 | 3.5.1 36 | 37 | 1.8 38 | 1.8 39 | 40 | 41 | 42 | org.apache.maven.plugins 43 | maven-war-plugin 44 | 3.1.0 45 | 46 | 47 | org.apache.maven.plugins 48 | maven-dependency-plugin 49 | 2.3 50 | 51 | 52 | package 53 | 54 | copy 55 | 56 | 57 | 58 | 59 | com.github.jsimone 60 | webapp-runner 61 | 8.5.11.3 62 | webapp-runner.jar 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /src/main/java/com/sl/CallbackServlet.java: -------------------------------------------------------------------------------- 1 | package com.sl; 2 | 3 | import twitter4j.Twitter; 4 | import twitter4j.TwitterException; 5 | import twitter4j.auth.AccessToken; 6 | import twitter4j.auth.RequestToken; 7 | 8 | import javax.servlet.ServletException; 9 | import javax.servlet.annotation.WebServlet; 10 | import javax.servlet.http.HttpServlet; 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | 14 | import com.sl.dao.TwitterDAO; 15 | import com.sl.db.DBException; 16 | import com.sl.pojo.UserPojo; 17 | 18 | import java.io.IOException; 19 | 20 | @WebServlet("/callback") 21 | public class CallbackServlet extends HttpServlet { 22 | private static final long serialVersionUID = 1657390011452788111L; 23 | 24 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 25 | // Get twitter object from session 26 | Twitter twitter = (Twitter) request.getSession().getAttribute("twitter"); 27 | //Get twitter request token object from session 28 | RequestToken requestToken = (RequestToken) request.getSession().getAttribute("requestToken"); 29 | String verifier = request.getParameter("oauth_verifier"); 30 | try { 31 | // Get twitter access token object by verifying request token 32 | AccessToken accessToken = twitter.getOAuthAccessToken(requestToken, verifier); 33 | request.getSession().removeAttribute("requestToken"); 34 | 35 | // Get user object from database with twitter user id 36 | UserPojo user = TwitterDAO.selectTwitterUser(accessToken.getUserId()); 37 | if(user == null) { 38 | // if user is null, create new user with given twitter details 39 | user = new UserPojo(); 40 | user.setTwitter_user_id(accessToken.getUserId()); 41 | user.setTwitter_screen_name(accessToken.getScreenName()); 42 | user.setAccess_token(accessToken.getToken()); 43 | user.setAccess_token_secret(accessToken.getTokenSecret()); 44 | TwitterDAO.insertRow(user); 45 | user = TwitterDAO.selectTwitterUser(accessToken.getUserId()); 46 | } else { 47 | // if user already there in database, update access token 48 | user.setAccess_token(accessToken.getToken()); 49 | user.setAccess_token_secret(accessToken.getTokenSecret()); 50 | TwitterDAO.updateAccessToken(user); 51 | } 52 | request.setAttribute("user", user); 53 | } catch (TwitterException | DBException e) { 54 | throw new ServletException(e); 55 | } 56 | request.getRequestDispatcher("/index2.html").forward(request, response); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/webapp/unfollow.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | Unfollow Non-Followers 7 | Tools Page 8 | 9 |

Unfollow Non-Followers

10 | 11 | 12 |

Unfollow everyone who doesn't follow you. If you want to 13 | make sure that some people are safe from being unfollowed, you may do 14 | so using the radio buttons below. The lists below refer to Twitter 16 | lists, which you can add/remove members from.

17 | 18 |
19 | Do you already have a "Never Unfollow" whitelist? Yes No
22 | 27 | 33 |
Once you click 34 | submit, the server will unfollow ALL of your non-followers EXCEPT 35 | THOSE PROTECTED BY YOUR NEVER UNFOLLOW LIST, without stopping. If 36 | you understand, enter "I UNDERSTAND".


39 |
40 | 64 | 65 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TwitterBoost-Tools 2 | 3 | **NOTE:** As of Sep 24, 2017, this project is no longer being maintained. 4 | 5 | A web application to boost your Twitter account stats/follower engagement. I've used these tools sporadically to grow my own Twitter account, [@warrencrasta](https://twitter.com/warrencrasta), with tremendous success. If you liked this project, or found these tools interesting, please consider starring the repository. 6 | 7 | **Link to app:** http://twitterboost-tools.herokuapp.com/ 8 | 9 | **NOTE:** Use this program within the bounds of the [Twitter Terms of Service](https://twitter.com/tos?lang=en). Please do not abuse this application. 10 | 11 | ## Possible Uses For This Application 12 | 13 | I have used this program sporadically to follow 1000 people a day based on a keyword they tweeted/a keyword in their bio. I also favorite 1000 tweets a day. I tweet about basketball/school a lot, so I use keywords related to basketball/school in order to increase the chance of them following me back. **Typically, I gain about 100 *real* new followers a day, and lots of *real* RTs/Favorites on my tweets.** A few days later, I use the tool to unfollow users who don't follow me back and to unfavorite all of my tweets. 14 | 15 | ## Instructions For Contributing/Installation 16 | 17 | Feel free to contribute to this project! There are many improvements that can be made, both in terms of code quality and in terms of whole new ideas that can be implemented. If you encounter a bug, please let me know. 18 | 19 | **To Develop:** 20 | 21 | 1. Clone the repository. 22 | 2. Open Eclipse IDE (Java EE perspective) and import this repo as a Maven project. 23 | 3. Create a Tomcat server in Eclipse and add the project to the Tomcat server. 24 | 4. Go to [https://apps.twitter.com/](https://apps.twitter.com/) and create a Twitter Application. Go to the Keys and Access Tokens tab of your application and note the **Consumer Key (API Key)** and **Consumer Secret (API Secret)**. 25 | 5. Edit **src/main/java/com/utils/Setup.java** with the appropriate values. For DB_URL, create a PostgreSQL database and a table called twitter_user. See **postgresql.txt** in this repo for the create table query. The DB_URL should look like: `jdbc:postgresql://:/?user=&password=&sslmode=require` but some trial-and-error might be needed. For more information, Google "PostgreSQL JDBC connection". 26 | 6. Follow existing coding conventions. 27 | 28 | The steps above are just high-level descriptions of how to set up the development environment. Setting up Tomcat in Eclipse with Maven can be tricky. 29 | 30 | If you do contribute, be advised that it may take some time to get your PR merged in. If you're interested in being a collaborator, e-mail me. If you don't know how to implement something, but do have an idea that you would like to see implemented, feel free to shoot me an e-mail and I can try to implement it. 31 | 32 | ## Credits 33 | 34 | Author: Warren Crasta (warrencrasta@gmail.com) 35 | 36 | Created with the help of [Twitter4J](http://twitter4j.org/en/index.html). Thank you to [Dasari Srinivas](http://blog.sodhanalibrary.com/2016/05/login-with-twitter-using-java-tutorial.html) for providing much of the boilerplate code. 37 | -------------------------------------------------------------------------------- /src/main/java/com/sl/db/DBConn.java: -------------------------------------------------------------------------------- 1 | package com.sl.db; 2 | 3 | import java.sql.Connection; 4 | import java.sql.DriverManager; 5 | import java.sql.PreparedStatement; 6 | import java.sql.ResultSet; 7 | import java.sql.SQLException; 8 | import java.sql.Statement; 9 | 10 | import com.utils.Setup; 11 | 12 | public class DBConn { 13 | Connection con = null; 14 | static String className = "class sodhana.sdb.connection.DBConnection"; 15 | 16 | /** 17 | * @return 18 | * @throws ClassNotFoundException 19 | * @throws SQLException 20 | * To Create Connections 21 | */ 22 | public static Connection getConnection() throws ClassNotFoundException, SQLException { 23 | Class.forName("org.postgresql.Driver"); 24 | Connection connection = null; 25 | connection = DriverManager.getConnection(Setup.DB_URL); 26 | return connection; 27 | } 28 | 29 | /** 30 | * @param con 31 | * @param stmt 32 | * @param rs 33 | * To close statements, result sets and Connection 34 | */ 35 | public static void close(Connection con, Statement stmt, ResultSet rs) { 36 | try { 37 | if (rs != null) { 38 | rs.close(); 39 | } 40 | if (stmt != null) { 41 | stmt.close(); 42 | } 43 | if (con != null) { 44 | con.close(); 45 | } 46 | } catch (SQLException e) { 47 | e.printStackTrace(); 48 | } catch (Exception e) { 49 | e.printStackTrace(); 50 | } 51 | } 52 | 53 | /** 54 | * @param con 55 | * @param stmt 56 | * To close statements and Connection 57 | */ 58 | public static void close(Connection con, Statement stmt) { 59 | try { 60 | if (stmt != null) { 61 | stmt.close(); 62 | } 63 | if (con != null) { 64 | con.close(); 65 | } 66 | } catch (SQLException e) { 67 | e.printStackTrace(); 68 | } catch (Exception e) { 69 | e.printStackTrace(); 70 | } 71 | } 72 | 73 | /** 74 | * @param con 75 | * @param pstmt 76 | * @param rs 77 | * To Close PreparedStatement and Connection 78 | */ 79 | public static void close(Connection con, PreparedStatement pstmt, 80 | ResultSet rs) { 81 | try { 82 | if (rs != null) { 83 | rs.close(); 84 | } 85 | if (pstmt != null) { 86 | pstmt.close(); 87 | } 88 | if (con != null) { 89 | con.close(); 90 | } 91 | } catch (SQLException e) { 92 | e.printStackTrace(); 93 | } catch (Exception e) { 94 | e.printStackTrace(); 95 | } 96 | } 97 | 98 | /** 99 | * @param con 100 | * To close connection 101 | */ 102 | public static void closeConnection(Connection con) { 103 | try { 104 | if (con != null) 105 | con.close(); 106 | } catch (SQLException e) { 107 | e.printStackTrace(); 108 | } catch (Exception e) { 109 | e.printStackTrace(); 110 | } 111 | } 112 | 113 | /** 114 | * @param conn 115 | * @throws SQLException 116 | * To Commit and Close the connection 117 | */ 118 | public static void commitAndClose(Connection conn) throws SQLException { 119 | conn.commit(); 120 | conn.close(); 121 | } 122 | 123 | public static void main(String args[]) throws ClassNotFoundException, SQLException { 124 | getConnection(); 125 | } 126 | 127 | } -------------------------------------------------------------------------------- /src/main/java/com/sl/dao/TwitterDAO.java: -------------------------------------------------------------------------------- 1 | package com.sl.dao; 2 | 3 | import java.sql.Connection; 4 | import java.sql.PreparedStatement; 5 | import java.sql.ResultSet; 6 | import java.sql.SQLException; 7 | import com.sl.db.DBConn; 8 | import com.sl.db.DBException; 9 | import com.sl.pojo.UserPojo; 10 | 11 | 12 | public class TwitterDAO { 13 | 14 | public static UserPojo selectUser(String userId) throws DBException { 15 | Connection conn = null; 16 | PreparedStatement ps = null; 17 | ResultSet res = null; 18 | UserPojo pojo = null; 19 | try { 20 | conn = DBConn.getConnection(); 21 | ps = conn.prepareStatement("select * from twitter_user where user_id = ?"); 22 | ps.setString(1, userId); 23 | res = ps.executeQuery(); 24 | if (res != null) { 25 | while (res.next()) { 26 | pojo = new UserPojo(); 27 | pojo.setUser_id(res.getInt(1)); 28 | pojo.setTwitter_user_id(res.getLong(2)); 29 | pojo.setTwitter_screen_name(res.getString(3)); 30 | pojo.setAccess_token(res.getString(4)); 31 | pojo.setAccess_token_secret(res.getString(5)); 32 | } 33 | } 34 | DBConn.close(conn, ps, res); 35 | } catch (ClassNotFoundException | SQLException e) { 36 | DBConn.close(conn, ps, res); 37 | throw new DBException(e.toString()); 38 | } 39 | return pojo; 40 | } 41 | 42 | 43 | public static UserPojo selectTwitterUser(long user_id) throws DBException { 44 | Connection conn = null; 45 | PreparedStatement ps = null; 46 | ResultSet res=null; 47 | UserPojo pojo = null; 48 | try { 49 | conn = DBConn.getConnection(); 50 | ps = conn.prepareStatement("select * from twitter_user where twitter_user_id = ?"); 51 | ps.setLong(1, user_id); 52 | res = ps.executeQuery(); 53 | if (res != null) { 54 | while (res.next()) { 55 | pojo = new UserPojo(); 56 | pojo.setUser_id(res.getInt(1)); 57 | pojo.setTwitter_user_id(res.getLong(2)); 58 | pojo.setTwitter_screen_name(res.getString(3)); 59 | pojo.setAccess_token(res.getString(4)); 60 | pojo.setAccess_token_secret(res.getString(5)); 61 | } 62 | } 63 | DBConn.close(conn, ps, res); 64 | } catch (ClassNotFoundException | SQLException e) { 65 | DBConn.close(conn, ps, res); 66 | throw new DBException(e.toString()); 67 | } 68 | return pojo; 69 | } 70 | 71 | public static void updateAccessToken(UserPojo pojo) throws DBException { 72 | Connection conn = null; 73 | PreparedStatement ps = null; 74 | try { 75 | conn = DBConn.getConnection(); 76 | ps = conn.prepareStatement("update twitter_user set access_token=?, access_token_secret=? where twitter_user_id = ?"); 77 | ps.setString(1, pojo.getAccess_token()); 78 | ps.setString(2, pojo.getAccess_token_secret()); 79 | ps.setLong(3, pojo.getTwitter_user_id()); 80 | ps.executeUpdate(); 81 | DBConn.close(conn, ps); 82 | } catch (ClassNotFoundException | SQLException e) { 83 | DBConn.close(conn, ps); 84 | throw new DBException(e.toString()); 85 | } 86 | } 87 | 88 | 89 | // add users vote 90 | public static void insertRow(UserPojo pojo) throws DBException{ 91 | Connection conn = null; 92 | PreparedStatement ps = null; 93 | try { 94 | conn = DBConn.getConnection(); 95 | ps = conn.prepareStatement("insert into twitter_user (twitter_user_id, screen_name, access_token, access_token_secret) values (?,?,?,?)"); 96 | ps.setLong(1,pojo.getTwitter_user_id()); 97 | ps.setString(2,pojo.getTwitter_screen_name()); 98 | ps.setString(3,pojo.getAccess_token()); 99 | ps.setString(4,pojo.getAccess_token_secret()); 100 | ps.executeUpdate(); 101 | DBConn.close(conn, ps); 102 | } catch (ClassNotFoundException | SQLException e) { 103 | DBConn.close(conn, ps); 104 | throw new DBException(e.toString()); 105 | } 106 | } 107 | 108 | } -------------------------------------------------------------------------------- /src/main/java/com/sl/PostBiokeyword.java: -------------------------------------------------------------------------------- 1 | /* 2 | * IDEAS: 3 | * Include # of users followed today in Rate Limiting Info. 4 | */ 5 | 6 | package com.sl; 7 | 8 | import java.io.IOException; 9 | import java.io.PrintWriter; 10 | 11 | import javax.servlet.ServletException; 12 | import javax.servlet.annotation.WebServlet; 13 | import javax.servlet.http.HttpServlet; 14 | import javax.servlet.http.HttpServletRequest; 15 | import javax.servlet.http.HttpServletResponse; 16 | 17 | import twitter4j.*; 18 | import java.util.*; 19 | 20 | @WebServlet("/postBiokeyword") 21 | public class PostBiokeyword extends HttpServlet { 22 | @Override 23 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 24 | response.setContentType("text/html"); 25 | response.setHeader("Connection", "keep-alive"); 26 | response.setHeader("Transfer-Encoding", "chunked"); 27 | 28 | PrintWriter out = response.getWriter(); 29 | out.println(""); 30 | out.println(""); 31 | out.println(""); 32 | out.println("Results"); 33 | out.println("Tools Page"); 34 | out.println(""); 35 | out.println(""); 36 | out.println("

Results

"); 37 | 38 | String query = request.getParameter("keyword"); 39 | int page = Integer.parseInt(request.getParameter("page")); 40 | int follow = Integer.parseInt(request.getParameter("follow")); 41 | int follow2 = Integer.parseInt(request.getParameter("follow2")); 42 | Twitter twitter = (Twitter)request.getSession().getAttribute("twitter"); 43 | if (follow == follow2) { 44 | out.println("To stop the process at any time, click the Stop loading this page button on your browser.

"); 45 | response.flushBuffer(); 46 | ResponseList users; 47 | int count = 0; 48 | try { 49 | do { 50 | users = twitter.searchUsers(query, page); 51 | for (User user : users) { 52 | if (count < follow){ 53 | try{ 54 | twitter.createFriendship(user.getId()); 55 | out.println(count+1 + ". Following @" + 56 | user.getScreenName() + ".
"); 57 | response.flushBuffer(); 58 | count++; 59 | /* Optional Delay, in seconds. */ 60 | // TimeUnit.SECONDS.sleep(1); 61 | } catch (TwitterException te) { 62 | if (te.toString().contains("You are unable to follow more people at this time.")) { 63 | out.println("Couldn't follow users: " + te + "
"); 64 | response.flushBuffer(); 65 | break; 66 | } 67 | /* Ignore any errors and keep running. */ 68 | } 69 | } else { 70 | break; 71 | } 72 | } 73 | page++; 74 | } while (users.size() != 0 && page < 50 && (count < follow)); 75 | } catch (TwitterException te) { 76 | out.println("Couldn't retrieve tweets: " + te + "
"); 77 | response.flushBuffer(); 78 | return; 79 | } 80 | 81 | out.println("

Twitter Rate-Limiting Info

"); 82 | response.flushBuffer(); 83 | 84 | Map rateLimitStatus; 85 | try { 86 | rateLimitStatus = twitter.getRateLimitStatus(); 87 | for (String endpoint : rateLimitStatus.keySet()) { 88 | RateLimitStatus status = rateLimitStatus.get(endpoint); 89 | if (status.getRemaining() < status.getLimit()) { 90 | out.println("Endpoint: " + endpoint + "
"); 91 | out.println("Limit: " + status.getLimit() + "
"); 92 | out.println("Remaining: " + status.getRemaining() + "
"); 93 | out.println("Seconds until remaining resets: " + status.getSecondsUntilReset() + "

"); 94 | } 95 | } 96 | } catch (TwitterException te) { 97 | out.println("Couldn't retrieve rate-limits: " + te + "
"); 98 | response.flushBuffer(); 99 | return; 100 | } 101 | } else { 102 | out.println("The two follow numbers you entered did not match. Click the Back Button on your browser to try again.
"); 103 | response.flushBuffer(); 104 | } 105 | out.println(""); 106 | out.println(""); 107 | } 108 | } -------------------------------------------------------------------------------- /src/main/java/com/sl/PostKeyword.java: -------------------------------------------------------------------------------- 1 | /* 2 | * IDEAS: 3 | * Include # of users followed today in Rate Limiting Info. 4 | */ 5 | 6 | package com.sl; 7 | 8 | import java.io.IOException; 9 | import java.io.PrintWriter; 10 | 11 | import javax.servlet.ServletException; 12 | import javax.servlet.annotation.WebServlet; 13 | import javax.servlet.http.HttpServlet; 14 | import javax.servlet.http.HttpServletRequest; 15 | import javax.servlet.http.HttpServletResponse; 16 | 17 | import twitter4j.*; 18 | import java.util.*; 19 | 20 | @WebServlet("/postKeyword") 21 | public class PostKeyword extends HttpServlet { 22 | @Override 23 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 24 | response.setContentType("text/html"); 25 | response.setHeader("Connection", "keep-alive"); 26 | response.setHeader("Transfer-Encoding", "chunked"); 27 | 28 | PrintWriter out = response.getWriter(); 29 | out.println(""); 30 | out.println(""); 31 | out.println(""); 32 | out.println("Results"); 33 | out.println("Tools Page"); 34 | out.println(""); 35 | out.println(""); 36 | out.println("

Results

"); 37 | 38 | String keyword = request.getParameter("keyword"); 39 | String ans = request.getParameter("RTs"); 40 | int follow = Integer.parseInt(request.getParameter("follow")); 41 | int follow2 = Integer.parseInt(request.getParameter("follow2")); 42 | Twitter twitter = (Twitter)request.getSession().getAttribute("twitter"); 43 | if (follow == follow2) { 44 | Query query; 45 | if(ans.equalsIgnoreCase("yes")) { 46 | query = new Query(keyword); 47 | } else{ 48 | query = new Query(keyword + " -filter:retweets"); 49 | } 50 | query.setResultType(Query.RECENT); 51 | 52 | /* Add tweets to a list. */ 53 | long lastID = Long.MAX_VALUE; 54 | ArrayList tweets = new ArrayList(); 55 | while (tweets.size() < follow) { 56 | if (follow - tweets.size() > 100) 57 | query.setCount(100); 58 | else 59 | query.setCount(follow - tweets.size()); 60 | try { 61 | QueryResult result = twitter.search(query); 62 | tweets.addAll(result.getTweets()); 63 | for (Status t: tweets) 64 | if(t.getId() < lastID) lastID = t.getId(); 65 | } 66 | catch (TwitterException te) { 67 | out.println("Couldn't retrieve tweets: " + te); 68 | response.flushBuffer(); 69 | break; 70 | }; 71 | query.setMaxId(lastID-1); 72 | } 73 | out.println("To stop the process at any time, click the Stop loading this page button on your browser.

"); 74 | response.flushBuffer(); 75 | /* Follow all users in the tweets list. */ 76 | 77 | for (int i = 0; i < tweets.size(); i++){ 78 | Status s = tweets.get(i); 79 | try { 80 | twitter.createFriendship(s.getUser().getId()); 81 | out.println(i+1 + ". Following @" + s.getUser().getScreenName() + ".
"); 82 | response.flushBuffer(); 83 | } catch (TwitterException te) { 84 | /* Ignore any errors and keep running. */ 85 | if (te.toString().contains("You are unable to follow more people at this time.")) { 86 | out.println("Couldn't follow users: " + te); 87 | response.flushBuffer(); 88 | break; 89 | } 90 | // out.println(te); 91 | } 92 | } 93 | out.println("

Twitter Rate-Limiting Info

"); 94 | response.flushBuffer(); 95 | 96 | Map rateLimitStatus; 97 | try { 98 | rateLimitStatus = twitter.getRateLimitStatus(); 99 | for (String endpoint : rateLimitStatus.keySet()) { 100 | RateLimitStatus status = rateLimitStatus.get(endpoint); 101 | if (status.getRemaining() < status.getLimit()) { 102 | out.println("Endpoint: " + endpoint + "
"); 103 | out.println("Limit: " + status.getLimit() + "
"); 104 | out.println("Remaining: " + status.getRemaining() + "
"); 105 | out.println("Seconds until remaining resets: " + status.getSecondsUntilReset() + "

"); 106 | } 107 | } 108 | } catch (TwitterException te) { 109 | out.println("Couldn't retrieve rate-limits: " + te); 110 | response.flushBuffer(); 111 | return; 112 | } 113 | } else { 114 | out.println("The two follow numbers you entered did not match. Click the Back Button on your browser to try again."); 115 | response.flushBuffer(); 116 | } 117 | out.println(""); 118 | out.println(""); 119 | } 120 | } -------------------------------------------------------------------------------- /src/main/java/com/sl/PostFavorite.java: -------------------------------------------------------------------------------- 1 | /* 2 | * IDEAS: 3 | * Include # of tweets favorited today in Rate Limiting Info. 4 | */ 5 | 6 | package com.sl; 7 | 8 | import java.io.IOException; 9 | import java.io.PrintWriter; 10 | 11 | import javax.servlet.ServletException; 12 | import javax.servlet.annotation.WebServlet; 13 | import javax.servlet.http.HttpServlet; 14 | import javax.servlet.http.HttpServletRequest; 15 | import javax.servlet.http.HttpServletResponse; 16 | 17 | import twitter4j.*; 18 | import java.util.*; 19 | 20 | @WebServlet("/postFavorite") 21 | public class PostFavorite extends HttpServlet { 22 | @Override 23 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 24 | response.setContentType("text/html"); 25 | response.setHeader("Connection", "keep-alive"); 26 | response.setHeader("Transfer-Encoding", "chunked"); 27 | 28 | PrintWriter out = response.getWriter(); 29 | out.println(""); 30 | out.println(""); 31 | out.println(""); 32 | out.println("Results"); 33 | out.println("Tools Page"); 34 | out.println(""); 35 | out.println(""); 36 | out.println("

Results

"); 37 | 38 | String keyword = request.getParameter("keyword"); 39 | String ans = request.getParameter("RTs"); 40 | int favorite = Integer.parseInt(request.getParameter("favorite")); 41 | int favorite2 = Integer.parseInt(request.getParameter("favorite2")); 42 | Twitter twitter = (Twitter)request.getSession().getAttribute("twitter"); 43 | if (favorite == favorite2) { 44 | out.println("To stop the process at any time, click the Stop loading this page button on your browser.

"); 45 | response.flushBuffer(); 46 | Query query; 47 | if(ans.equalsIgnoreCase("yes") || ans.equalsIgnoreCase("y")) { 48 | query = new Query(keyword); 49 | } else{ 50 | query = new Query(keyword + " -filter:retweets"); 51 | } 52 | query.setResultType(Query.RECENT); 53 | 54 | /* Add tweets to a list. */ 55 | long lastID = Long.MAX_VALUE; 56 | ArrayList tweets = new ArrayList(); 57 | while (tweets.size() < favorite) { 58 | if (favorite - tweets.size() > 100) 59 | query.setCount(100); 60 | else 61 | query.setCount(favorite - tweets.size()); 62 | try { 63 | QueryResult result = twitter.search(query); 64 | tweets.addAll(result.getTweets()); 65 | for (Status t: tweets) 66 | if(t.getId() < lastID) lastID = t.getId(); 67 | } 68 | catch (TwitterException te) { 69 | out.println("Couldn't retrieve tweets: " + te + "
"); 70 | response.flushBuffer(); 71 | break; 72 | }; 73 | query.setMaxId(lastID-1); 74 | } 75 | /* Favorite all users in the tweets list. */ 76 | for (int i = 0; i < tweets.size(); i++){ 77 | Status s = tweets.get(i); 78 | try { 79 | twitter.createFavorite(s.getId()); 80 | out.println(i+1 + ". Favoriting tweet by @" + s.getUser().getScreenName() + ".
"); 81 | response.flushBuffer(); 82 | } catch (TwitterException te) { 83 | /* Ignore any errors and keep running. */ 84 | if (te.toString().contains("Your account may not be allowed to perform this action.")) { 85 | out.println("Couldn't favorite tweets: " + te + "
"); 86 | response.flushBuffer(); 87 | break; 88 | } 89 | } 90 | } 91 | out.println("

Twitter Rate-Limiting Info

"); 92 | response.flushBuffer(); 93 | 94 | Map rateLimitStatus; 95 | try { 96 | rateLimitStatus = twitter.getRateLimitStatus(); 97 | for (String endpoint : rateLimitStatus.keySet()) { 98 | RateLimitStatus status = rateLimitStatus.get(endpoint); 99 | if (status.getRemaining() < status.getLimit()) { 100 | out.println("Endpoint: " + endpoint + "
"); 101 | out.println("Limit: " + status.getLimit() + "
"); 102 | out.println("Remaining: " + status.getRemaining() + "
"); 103 | out.println("Seconds until remaining resets: " + status.getSecondsUntilReset() + "

"); 104 | } 105 | } 106 | } catch (TwitterException te) { 107 | out.println("Couldn't retrieve rate-limits: " + te + "
"); 108 | response.flushBuffer(); 109 | return; 110 | } 111 | } else { 112 | out.println("The two favorite numbers you entered did not match. Click the Back Button on your browser to try again.
"); 113 | response.flushBuffer(); 114 | } 115 | out.println(""); 116 | out.println(""); 117 | } 118 | } -------------------------------------------------------------------------------- /src/main/java/com/sl/PostUnfavorite.java: -------------------------------------------------------------------------------- 1 | /* 2 | * IDEAS: 3 | * Include # of tweets unfavorited today in Rate Limiting Info. 4 | * Instead of unfavoriting all tweets, unfavorite only tweets from users you do not follow. 5 | */ 6 | 7 | package com.sl; 8 | 9 | import java.io.IOException; 10 | import java.io.PrintWriter; 11 | 12 | import javax.servlet.ServletException; 13 | import javax.servlet.annotation.WebServlet; 14 | import javax.servlet.http.HttpServlet; 15 | import javax.servlet.http.HttpServletRequest; 16 | import javax.servlet.http.HttpServletResponse; 17 | 18 | import twitter4j.*; 19 | import java.util.*; 20 | 21 | @WebServlet("/postUnfavorite") 22 | public class PostUnfavorite extends HttpServlet { 23 | @Override 24 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 25 | response.setContentType("text/html"); 26 | response.setHeader("Connection", "keep-alive"); 27 | response.setHeader("Transfer-Encoding", "chunked"); 28 | 29 | PrintWriter out = response.getWriter(); 30 | out.println(""); 31 | out.println(""); 32 | out.println(""); 33 | out.println("Results"); 34 | out.println("Tools Page"); 35 | out.println(""); 36 | out.println(""); 37 | out.println("

Results

"); 38 | 39 | String unfavorite = request.getParameter("unfavorite"); 40 | String unfavorite1 = request.getParameter("no1"); 41 | String unfavorite2 = request.getParameter("unfavorite2"); 42 | 43 | Twitter twitter = (Twitter)request.getSession().getAttribute("twitter"); 44 | if ((unfavorite2.equalsIgnoreCase("I UNDERSTAND")) && (unfavorite.equals("yes") || unfavorite1.equals("yes"))) { 45 | out.println("To stop the process at any time, click the Stop loading this page button on your browser.

"); 46 | response.flushBuffer(); 47 | ArrayList following = new ArrayList(); 48 | if (unfavorite1 != null) { 49 | if (unfavorite1.equals("yes")) { 50 | long cursor2 = -1; 51 | IDs friends; 52 | try { 53 | do { 54 | friends = twitter.getFriendsIDs(cursor2); 55 | for (long id : friends.getIDs()) { 56 | following.add(id); 57 | } 58 | } while ((cursor2 = friends.getNextCursor()) != 0); 59 | } catch (TwitterException te) { 60 | out.println("Failed to get friends' ids: " + te + "
"); 61 | response.flushBuffer(); 62 | return; 63 | } 64 | } 65 | } 66 | int page = 1; 67 | ResponseList tweets; 68 | int count = 0; 69 | try { 70 | do { 71 | tweets = twitter.getFavorites(); 72 | for (Status s : tweets) { 73 | if (unfavorite.equals("yes") || !following.contains(s.getUser().getId())) { 74 | twitter.destroyFavorite(s.getId()); 75 | out.println(count+1 + ". Unfavoriting tweet by @" + s.getUser().getScreenName() + ".
"); 76 | response.flushBuffer(); 77 | count++; 78 | } 79 | } 80 | page++; 81 | } while (tweets.size() != 0 && page < 50); 82 | } catch (TwitterException te) { 83 | if (te.toString().contains("Your account may not be allowed to perform this action.")) { 84 | out.println("Couldn't unfavorite tweets: " + te + "
"); 85 | response.flushBuffer(); 86 | return; 87 | } 88 | /* Ignore any errors and keep running. */ 89 | } 90 | 91 | out.println("

Twitter Rate-Limiting Info

"); 92 | response.flushBuffer(); 93 | 94 | Map rateLimitStatus; 95 | try { 96 | rateLimitStatus = twitter.getRateLimitStatus(); 97 | for (String endpoint : rateLimitStatus.keySet()) { 98 | RateLimitStatus status = rateLimitStatus.get(endpoint); 99 | if (status.getRemaining() < status.getLimit()) { 100 | out.println("Endpoint: " + endpoint + "
"); 101 | out.println("Limit: " + status.getLimit() + "
"); 102 | out.println("Remaining: " + status.getRemaining() + "
"); 103 | out.println("Seconds until remaining resets: " + status.getSecondsUntilReset() + "

"); 104 | } 105 | } 106 | } catch (TwitterException te) { 107 | out.println("Couldn't retrieve rate-limits: " + te + "
"); 108 | response.flushBuffer(); 109 | return; 110 | } 111 | } else { 112 | out.println("One or both of the values you entered in the previous page are incorrect. Click the Back Button on your browser to try again.
"); 113 | response.flushBuffer(); 114 | } 115 | out.println(""); 116 | out.println(""); 117 | } 118 | } -------------------------------------------------------------------------------- /src/main/java/com/sl/PostUnfollow.java: -------------------------------------------------------------------------------- 1 | /* 2 | * IDEAS: 3 | * Include # of users unfollowed in last 24 hours in Rate Limiting Info. 4 | */ 5 | 6 | package com.sl; 7 | 8 | import java.io.IOException; 9 | import java.io.PrintWriter; 10 | 11 | import javax.servlet.ServletException; 12 | import javax.servlet.annotation.WebServlet; 13 | import javax.servlet.http.HttpServlet; 14 | import javax.servlet.http.HttpServletRequest; 15 | import javax.servlet.http.HttpServletResponse; 16 | 17 | import twitter4j.*; 18 | import java.util.*; 19 | 20 | @WebServlet("/postUnfollow") 21 | public class PostUnfollow extends HttpServlet { 22 | @Override 23 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 24 | response.setContentType("text/html"); 25 | response.setHeader("Connection", "keep-alive"); 26 | response.setHeader("Transfer-Encoding", "chunked"); 27 | 28 | PrintWriter out = response.getWriter(); 29 | out.println(""); 30 | out.println(""); 31 | out.println(""); 32 | out.println("Results"); 33 | out.println("Tools Page"); 34 | out.println(""); 35 | out.println(""); 36 | out.println("

Results

"); 37 | 38 | Twitter twitter = (Twitter)request.getSession().getAttribute("twitter"); 39 | String owner = request.getParameter("owner"); 40 | String listName = request.getParameter("listName"); 41 | String unfollow = request.getParameter("unfollow"); 42 | String already = request.getParameter("already"); 43 | String already3 = request.getParameter("already3"); 44 | 45 | if (unfollow.equalsIgnoreCase("I UNDERSTAND")) { 46 | out.println("To stop the process at any time, click the Stop loading this page button on your browser.

"); 47 | response.flushBuffer(); 48 | List neverUnfollow = new ArrayList(); 49 | if (already.equals("no") && already3.equals("yes")){ 50 | long cursor2 = -1; 51 | IDs friends; 52 | int count = 0; 53 | try { 54 | do { 55 | friends = twitter.getFriendsIDs(cursor2); 56 | for (long id : friends.getIDs()) { 57 | out.println(count+1 + ". Adding @" + twitter.showUser(id).getScreenName() + 58 | " to the Never Unfollow list.
"); 59 | response.flushBuffer(); 60 | count++; 61 | neverUnfollow.add(id); 62 | // Can also add users to Twitter list here. 63 | // http://twitter4j.org/javadoc/twitter4j/api/ListsResources.html#createUserListMember-long-long- 64 | } 65 | } while ((cursor2 = friends.getNextCursor()) != 0); 66 | try { 67 | // Add users to Twitter list here. 68 | UserList newList = twitter.createUserList("Never Unfollow", false, "Created by @warrencrasta's Twitter Tools."); 69 | for (int i = 0; i < neverUnfollow.size(); i += 100) { 70 | List sub = neverUnfollow.subList(i, Math.min(neverUnfollow.size(), i + 100)); 71 | twitter.createUserListMembers(newList.getId(), sub.stream().mapToLong(l -> l).toArray()); 72 | } 73 | } catch (TwitterException te) { 74 | out.println("Couldn't create Twitter list: " + te + "
"); 75 | response.flushBuffer(); 76 | return; 77 | } 78 | } catch (TwitterException te) { 79 | out.println("Failed to get friends' ids: " + te + "
"); 80 | response.flushBuffer(); 81 | return; 82 | } 83 | } else if (owner != null && !owner.isEmpty()) { 84 | long cursor = -1; 85 | PagableResponseList users; 86 | int count = 0; 87 | try { 88 | do { 89 | users = twitter.getUserListMembers(owner, listName, cursor); 90 | for (User user : users) { 91 | out.println(count+1 + ". Adding @" + user.getScreenName() + 92 | " to Never Unfollow list.
"); 93 | response.flushBuffer(); 94 | count++; 95 | neverUnfollow.add(user.getId()); 96 | } 97 | } while ((cursor = users.getNextCursor()) != 0); 98 | } catch (TwitterException te) { 99 | out.println("Failed to get list members: " + te + "
"); 100 | response.flushBuffer(); 101 | return; 102 | } 103 | } 104 | if (already.equals("no") && already3.equals("yes")) { 105 | try { 106 | out.println("" + neverUnfollow.size() + " users were added to the Never Unfollow list.

"); 108 | response.flushBuffer(); 109 | } catch (TwitterException te) { 110 | out.println("Failed to get user's username: " + te); 111 | response.flushBuffer(); 112 | return; 113 | } 114 | } else { 115 | out.println("" + neverUnfollow.size() + " users were added to the" 116 | + " Never Unfollow list.

"); 117 | response.flushBuffer(); 118 | } 119 | 120 | long cursor2 = -1; 121 | IDs friends; 122 | ArrayList following = new ArrayList(); 123 | try { 124 | do { 125 | friends = twitter.getFriendsIDs(cursor2); 126 | for (long id : friends.getIDs()) { 127 | following.add(id); 128 | } 129 | } while ((cursor2 = friends.getNextCursor()) != 0); 130 | } catch (TwitterException te) { 131 | out.println("Failed to get friends' ids: " + te + "
"); 132 | response.flushBuffer(); 133 | return; 134 | } 135 | 136 | long cursor3 = -1; 137 | IDs followerIDs; 138 | ArrayList followers = new ArrayList(); 139 | try { 140 | do { 141 | followerIDs = twitter.getFollowersIDs(cursor3); 142 | for (long id : followerIDs.getIDs()) { 143 | followers.add(id); 144 | } 145 | } while ((cursor3 = followerIDs.getNextCursor()) != 0); 146 | } catch (TwitterException te) { 147 | out.println("Failed to get followers' ids: " + te + "
"); 148 | response.flushBuffer(); 149 | return; 150 | } 151 | int count2 = 0; 152 | /* Iterate through the list of people you are following. */ 153 | for (int i = 0; i < following.size(); i++) { 154 | /* If a person doesn't follow you back, unfollow them. */ 155 | if (!followers.contains(following.get(i))){ 156 | if(!neverUnfollow.contains(following.get(i))){ 157 | try { 158 | twitter.destroyFriendship(following.get(i)); 159 | out.println(count2+1 + ". Unfollowed @" + twitter.showUser(following.get(i)).getScreenName() + ".
"); 160 | response.flushBuffer(); 161 | count2++; 162 | /* Optional Delay, in seconds. */ 163 | // TimeUnit.SECONDS.sleep(1); 164 | } catch (TwitterException te) { 165 | /* Ignore any errors and keep running. */ 166 | } 167 | } 168 | } 169 | } 170 | out.println("" + count2 + " users were unfollowed.
"); 171 | 172 | out.println("

Twitter Rate-Limiting Info

"); 173 | response.flushBuffer(); 174 | 175 | Map rateLimitStatus; 176 | try { 177 | rateLimitStatus = twitter.getRateLimitStatus(); 178 | for (String endpoint : rateLimitStatus.keySet()) { 179 | RateLimitStatus status = rateLimitStatus.get(endpoint); 180 | if (status.getRemaining() < status.getLimit()) { 181 | out.println("Endpoint: " + endpoint + "
"); 182 | out.println("Limit: " + status.getLimit() + "
"); 183 | out.println("Remaining: " + status.getRemaining() + "
"); 184 | out.println("Seconds until remaining resets: " + status.getSecondsUntilReset() + "

"); 185 | } 186 | } 187 | } catch (TwitterException te) { 188 | out.println("Couldn't retrieve rate-limits: " + te + "
"); 189 | response.flushBuffer(); 190 | return; 191 | } 192 | } else { 193 | out.println("You did not type \"I UNDERSTAND\" correctly. Click the Back Button on your browser to try again.
"); 194 | response.flushBuffer(); 195 | } 196 | 197 | out.println(""); 198 | out.println(""); 199 | } 200 | } --------------------------------------------------------------------------------