{"action":"created","comment":{"url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/pulls/comments/47081228","id":47081228,"diff_hunk":"@@ -0,0 +1,173 @@\n+package main;\n+\n+import com.google.maps.GeoApiContext;\n+import com.google.maps.GeocodingApi;\n+import com.google.maps.model.GeocodingResult;\n+import twitter4j.*;\n+\n+import java.io.PrintStream;\n+import java.text.DateFormat;\n+import java.text.SimpleDateFormat;\n+import java.util.ArrayList;\n+import java.util.Date;\n+import java.util.List;\n+\n+public class Worker {\n+\n+    private boolean hideRetweets;\n+    private Twitter twitter;\n+    private ArrayList<String> places = new ArrayList<>();\n+\n+    public Worker(boolean _hideRetweets, String place) {\n+        hideRetweets = _hideRetweets;\n+        twitter = new TwitterFactory().getInstance();\n+\n+        GeoApiContext context = new GeoApiContext().setApiKey(\"AIzaSyBuQLwjdz5j4zx2CBH02Aae6RwugsjdIVg\");\n+        try {\n+            GeocodingResult result = GeocodingApi.geocode(context, place).await()[0];\n+\n+            System.out.println(\"Your location: \" + result.geometry.location.lat + \", \" + result.geometry.location.lng);\n+\n+            GeoQuery geoQuery = new GeoQuery(new GeoLocation(result.geometry.location.lat, result.geometry.location.lng));\n+            geoQuery.setAccuracy(place);\n+            ResponseList<Place> places = twitter.searchPlaces(geoQuery);\n+\n+            for (Place p: places) {\n+                System.out.print(p);\n+                this.places.add(p.getId());\n+            }\n+\n+        } catch (Exception e) {\n+            System.err.println(e);\n+        }\n+\n+    }\n+\n+    Query getQuery(String queryStr, int count) {\n+        Query query = new Query(queryStr);\n+        if (count > 0 && count <= 100)\n+            query.setCount(count);\n+        return query;\n+    }\n+\n+    void proceedResult(PrintStream stream, QueryResult result, boolean timing) throws TwitterException {\n+        List<Status> tweets = result.getTweets();\n+        this.printTweets(stream, tweets, timing);\n+    }\n+\n+    QueryResult performQuerySearch(Query query) {\n+        QueryResult result;\n+        try {\n+            result = this.twitter.search(query);\n+            return result;\n+        } catch (TwitterException e){\n+            if (e.isCausedByNetworkIssue()) {\n+                System.err.println(\"No internet connection\");\n+            }\n+            else\n+                this.handleException(e);\n+            return performQuerySearch(query);\n+        }\n+\n+    }\n+\n+    public void performQuery(PrintStream stream, String queryStr, int count) {\n+        try {\n+            Query query = this.getQuery(queryStr, count);\n+            QueryResult result;\n+            int index = 0;\n+            do {\n+                result = this.performQuerySearch(query);\n+                proceedResult(stream, result, true);\n+                index += query.getCount();\n+            } while ((query = result.nextQuery()) != null && index < count);\n+        } catch (TwitterException e) {\n+            this.handleException(e);\n+        }\n+    }\n+\n+    void doStreaming(PrintStream stream, Query query) throws  TwitterException {\n+        QueryResult result;\n+        do {\n+            result = this.twitter.search(query);\n+            proceedResult(stream, result, false);\n+        } while ((query = result.nextQuery()) != null);\n+    }\n+\n+    public void performStream(PrintStream stream, String queryStr) {\n+\n+        TwitterStream twitterStream = new TwitterStreamFactory().getInstance();\n+        StatusListener listener = new StatusListener() {\n+            @Override\n+            public void onStatus(Status status) {\n+                System.out.println(\"@\" + status.getUser().getScreenName() + \" - \" + status.getText());\n+            }\n+\n+            @Override\n+            public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {\n+                System.out.println(\"Got a status deletion notice id:\" + statusDeletionNotice.getStatusId());\n+            }\n+\n+            @Override\n+            public void onTrackLimitationNotice(int numberOfLimitedStatuses) {\n+                System.out.println(\"Got track limitation notice:\" + numberOfLimitedStatuses);\n+            }\n+\n+            @Override\n+            public void onScrubGeo(long userId, long upToStatusId) {\n+                System.out.println(\"Got scrub_geo event userId:\" + userId + \" upToStatusId:\" + upToStatusId);\n+            }\n+\n+            @Override\n+            public void onStallWarning(StallWarning warning) {\n+                System.out.println(\"Got stall warning:\" + warning);\n+            }\n+\n+            @Override\n+            public void onException(Exception ex) {\n+                ex.printStackTrace();\n+            }\n+        };\n+        twitterStream.addListener(listener);\n+        twitterStream.sample();\n+    }\n+\n+    void printTweets(PrintStream stream, List<Status> tweets, boolean timing) {\n+        for (Status tweet: tweets) {\n+            if (tweet.getPlace() != null) {\n+                String id = tweet.getPlace().getId();\n+                if (this.places.contains(id)) {\n+                    this.printTweet(stream, tweet, timing);\n+                }\n+            }\n+        }\n+    }\n+\n+    void printTweet(PrintStream stream, Status tweet, boolean timing) {\n+        User user = tweet.getUser();\n+        Date date = tweet.getCreatedAt();\n+        DateFormat df = new SimpleDateFormat(\"HH:mm E d LLL yyyy\");\n+        String format = ((timing) ? df.format(date) + \" \" : \"\") + Worker.bluedText(\"@\" + user.getScreenName()) + \": \";","path":"projects/tulindanil/src/main/Worker.java","position":150,"original_position":150,"commit_id":"8ff731981fc6acea5ae982ae288805c09bd3524d","original_commit_id":"8ff731981fc6acea5ae982ae288805c09bd3524d","user":{"login":"Pitovsky","id":11497455,"avatar_url":"https://avatars.githubusercontent.com/u/11497455?v=3","gravatar_id":"","url":"https://api.github.com/users/Pitovsky","html_url":"https://github.com/Pitovsky","followers_url":"https://api.github.com/users/Pitovsky/followers","following_url":"https://api.github.com/users/Pitovsky/following{/other_user}","gists_url":"https://api.github.com/users/Pitovsky/gists{/gist_id}","starred_url":"https://api.github.com/users/Pitovsky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Pitovsky/subscriptions","organizations_url":"https://api.github.com/users/Pitovsky/orgs","repos_url":"https://api.github.com/users/Pitovsky/repos","events_url":"https://api.github.com/users/Pitovsky/events{/privacy}","received_events_url":"https://api.github.com/users/Pitovsky/received_events","type":"User","site_admin":false},"body":"Когда много конкатенаций, лучше использовать StringBuilder, он будет работать без лишних реаллокаций","created_at":"2015-12-09T11:54:08Z","updated_at":"2015-12-09T11:54:08Z","html_url":"https://github.com/KhurtinDN/fizteh-java-2015/pull/33#discussion_r47081228","pull_request_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/pulls/33","_links":{"self":{"href":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/pulls/comments/47081228"},"html":{"href":"https://github.com/KhurtinDN/fizteh-java-2015/pull/33#discussion_r47081228"},"pull_request":{"href":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/pulls/33"}}},"pull_request":{"url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/pulls/33","id":46683777,"html_url":"https://github.com/KhurtinDN/fizteh-java-2015/pull/33","diff_url":"https://github.com/KhurtinDN/fizteh-java-2015/pull/33.diff","patch_url":"https://github.com/KhurtinDN/fizteh-java-2015/pull/33.patch","issue_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/issues/33","number":33,"state":"open","locked":false,"title":"Тулин Даниил, 497 группа, TwitterStream ","user":{"login":"tulindanil","id":8260020,"avatar_url":"https://avatars.githubusercontent.com/u/8260020?v=3","gravatar_id":"","url":"https://api.github.com/users/tulindanil","html_url":"https://github.com/tulindanil","followers_url":"https://api.github.com/users/tulindanil/followers","following_url":"https://api.github.com/users/tulindanil/following{/other_user}","gists_url":"https://api.github.com/users/tulindanil/gists{/gist_id}","starred_url":"https://api.github.com/users/tulindanil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tulindanil/subscriptions","organizations_url":"https://api.github.com/users/tulindanil/orgs","repos_url":"https://api.github.com/users/tulindanil/repos","events_url":"https://api.github.com/users/tulindanil/events{/privacy}","received_events_url":"https://api.github.com/users/tulindanil/received_events","type":"User","site_admin":false},"body":"Далеко не конечный продукт. Пожалуйста, напишите свои замечания, чтобы я их быстрее исправил)","created_at":"2015-10-02T21:22:09Z","updated_at":"2015-12-09T11:54:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2e1e3149ab09d2d8997faa96fc8b2d9931dfca52","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/pulls/33/commits","review_comments_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/pulls/33/comments","review_comment_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/pulls/comments{/number}","comments_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/issues/33/comments","statuses_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/statuses/8ff731981fc6acea5ae982ae288805c09bd3524d","head":{"label":"tulindanil:TwitterStream","ref":"TwitterStream","sha":"8ff731981fc6acea5ae982ae288805c09bd3524d","user":{"login":"tulindanil","id":8260020,"avatar_url":"https://avatars.githubusercontent.com/u/8260020?v=3","gravatar_id":"","url":"https://api.github.com/users/tulindanil","html_url":"https://github.com/tulindanil","followers_url":"https://api.github.com/users/tulindanil/followers","following_url":"https://api.github.com/users/tulindanil/following{/other_user}","gists_url":"https://api.github.com/users/tulindanil/gists{/gist_id}","starred_url":"https://api.github.com/users/tulindanil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tulindanil/subscriptions","organizations_url":"https://api.github.com/users/tulindanil/orgs","repos_url":"https://api.github.com/users/tulindanil/repos","events_url":"https://api.github.com/users/tulindanil/events{/privacy}","received_events_url":"https://api.github.com/users/tulindanil/received_events","type":"User","site_admin":false},"repo":{"id":42769845,"name":"fizteh-java-2015","full_name":"tulindanil/fizteh-java-2015","owner":{"login":"tulindanil","id":8260020,"avatar_url":"https://avatars.githubusercontent.com/u/8260020?v=3","gravatar_id":"","url":"https://api.github.com/users/tulindanil","html_url":"https://github.com/tulindanil","followers_url":"https://api.github.com/users/tulindanil/followers","following_url":"https://api.github.com/users/tulindanil/following{/other_user}","gists_url":"https://api.github.com/users/tulindanil/gists{/gist_id}","starred_url":"https://api.github.com/users/tulindanil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tulindanil/subscriptions","organizations_url":"https://api.github.com/users/tulindanil/orgs","repos_url":"https://api.github.com/users/tulindanil/repos","events_url":"https://api.github.com/users/tulindanil/events{/privacy}","received_events_url":"https://api.github.com/users/tulindanil/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tulindanil/fizteh-java-2015","description":"","fork":true,"url":"https://api.github.com/repos/tulindanil/fizteh-java-2015","forks_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/forks","keys_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/teams","hooks_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/hooks","issue_events_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/issues/events{/number}","events_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/events","assignees_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/assignees{/user}","branches_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/branches{/branch}","tags_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/tags","blobs_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/git/refs{/sha}","trees_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/statuses/{sha}","languages_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/languages","stargazers_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/stargazers","contributors_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/contributors","subscribers_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/subscribers","subscription_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/subscription","commits_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/commits{/sha}","git_commits_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/git/commits{/sha}","comments_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/comments{/number}","issue_comment_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/issues/comments{/number}","contents_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/contents/{+path}","compare_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/merges","archive_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/downloads","issues_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/issues{/number}","pulls_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/pulls{/number}","milestones_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/milestones{/number}","notifications_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/labels{/name}","releases_url":"https://api.github.com/repos/tulindanil/fizteh-java-2015/releases{/id}","created_at":"2015-09-19T11:06:07Z","updated_at":"2015-09-19T11:06:07Z","pushed_at":"2015-12-07T11:07:13Z","git_url":"git://github.com/tulindanil/fizteh-java-2015.git","ssh_url":"git@github.com:tulindanil/fizteh-java-2015.git","clone_url":"https://github.com/tulindanil/fizteh-java-2015.git","svn_url":"https://github.com/tulindanil/fizteh-java-2015","homepage":null,"size":155,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"KhurtinDN:master","ref":"master","sha":"4f1ce962fa5c80da2ce2f04163c93f730eba1a0f","user":{"login":"KhurtinDN","id":320987,"avatar_url":"https://avatars.githubusercontent.com/u/320987?v=3","gravatar_id":"","url":"https://api.github.com/users/KhurtinDN","html_url":"https://github.com/KhurtinDN","followers_url":"https://api.github.com/users/KhurtinDN/followers","following_url":"https://api.github.com/users/KhurtinDN/following{/other_user}","gists_url":"https://api.github.com/users/KhurtinDN/gists{/gist_id}","starred_url":"https://api.github.com/users/KhurtinDN/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KhurtinDN/subscriptions","organizations_url":"https://api.github.com/users/KhurtinDN/orgs","repos_url":"https://api.github.com/users/KhurtinDN/repos","events_url":"https://api.github.com/users/KhurtinDN/events{/privacy}","received_events_url":"https://api.github.com/users/KhurtinDN/received_events","type":"User","site_admin":false},"repo":{"id":42640944,"name":"fizteh-java-2015","full_name":"KhurtinDN/fizteh-java-2015","owner":{"login":"KhurtinDN","id":320987,"avatar_url":"https://avatars.githubusercontent.com/u/320987?v=3","gravatar_id":"","url":"https://api.github.com/users/KhurtinDN","html_url":"https://github.com/KhurtinDN","followers_url":"https://api.github.com/users/KhurtinDN/followers","following_url":"https://api.github.com/users/KhurtinDN/following{/other_user}","gists_url":"https://api.github.com/users/KhurtinDN/gists{/gist_id}","starred_url":"https://api.github.com/users/KhurtinDN/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KhurtinDN/subscriptions","organizations_url":"https://api.github.com/users/KhurtinDN/orgs","repos_url":"https://api.github.com/users/KhurtinDN/repos","events_url":"https://api.github.com/users/KhurtinDN/events{/privacy}","received_events_url":"https://api.github.com/users/KhurtinDN/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/KhurtinDN/fizteh-java-2015","description":"","fork":false,"url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015","forks_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/forks","keys_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/keys{/key_id}","collaborators_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/teams","hooks_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/hooks","issue_events_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/issues/events{/number}","events_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/events","assignees_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/assignees{/user}","branches_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/branches{/branch}","tags_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/tags","blobs_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/git/refs{/sha}","trees_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/git/trees{/sha}","statuses_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/statuses/{sha}","languages_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/languages","stargazers_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/stargazers","contributors_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/contributors","subscribers_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/subscribers","subscription_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/subscription","commits_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/commits{/sha}","git_commits_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/git/commits{/sha}","comments_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/comments{/number}","issue_comment_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/issues/comments{/number}","contents_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/contents/{+path}","compare_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/compare/{base}...{head}","merges_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/merges","archive_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/downloads","issues_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/issues{/number}","pulls_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/pulls{/number}","milestones_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/milestones{/number}","notifications_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/labels{/name}","releases_url":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/releases{/id}","created_at":"2015-09-17T07:13:10Z","updated_at":"2015-11-24T22:02:16Z","pushed_at":"2015-12-09T11:38:47Z","git_url":"git://github.com/KhurtinDN/fizteh-java-2015.git","ssh_url":"git@github.com:KhurtinDN/fizteh-java-2015.git","clone_url":"https://github.com/KhurtinDN/fizteh-java-2015.git","svn_url":"https://github.com/KhurtinDN/fizteh-java-2015","homepage":null,"size":723,"stargazers_count":2,"watchers_count":2,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":36,"mirror_url":null,"open_issues_count":20,"forks":36,"open_issues":20,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/pulls/33"},"html":{"href":"https://github.com/KhurtinDN/fizteh-java-2015/pull/33"},"issue":{"href":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/issues/33"},"comments":{"href":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/issues/33/comments"},"review_comments":{"href":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/pulls/33/comments"},"review_comment":{"href":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/pulls/33/commits"},"statuses":{"href":"https://api.github.com/repos/KhurtinDN/fizteh-java-2015/statuses/8ff731981fc6acea5ae982ae288805c09bd3524d"}}}}