示例#1
0
        internal static string GetAllAsCsv(SqlTwitchFollower[] followers)
        {
            string csv = "";
            if (followers != null)
            {
                for (int i = 0; i < followers.Length; i++)
                {
                    if (i > 0)
                    {
                        csv += ",";
                    }
                    csv += followers[i].user.userName;
                }
            }

            return csv;
        }
示例#2
0
        internal static SqlTwitchFollower[] ParseFollowers(string json)
        {
            LinkedList<SqlTwitchFollower> followers = new LinkedList<SqlTwitchFollower>();

            if (json != null)
            {
                // {"follows":[{"created_at":"2015-06-27T06:25:12Z","_links":{"self":"https://api.twitch.tv/kraken/users/volt_100/follows/channels/hardlysober"},"notifications":false,"user":{"_id":79242000,"name":"volt_100","created_at":"2015-01-08T17:08:01Z","updated_at":"2015-06-20T16:41:10Z","_links":{"self":"https://api.twitch.tv/kraken/users/volt_100"},"display_name":"volt_100","logo":"http://static-cdn.jtvnw.net/jtv_user_pictures/volt_100-profile_image-653aa9b8c5343c09-300x300.jpeg","bio":null,"type":"user"}},{"created_at":"2015-06-27T05:50:23Z","_links":{"self":"https://api.twitch.tv/kraken/users/doctordoofenshmirtz/follows/channels/hardlysober"},"notifications":false,"user":{"_id":73136919,"name":"doctordoofenshmirtz","created_at":"2014-10-15T22:50:12Z","updated_at":"2015-06-20T01:00:20Z","_links":{"self":"https://api.twitch.tv/kraken/users/doctordoofenshmirtz"},"display_name":"DoctorDoofenshmirtz","logo":null,"bio":null,"type":"user"}},{"created_at":"2015-06-27T01:12:13Z","_links":{"self":"https://api.twitch.tv/kraken/users/dylanplayscc/follows/channels/hardlysober"},"notifications":false,"user":{"_id":94456844,"name":"dylanplayscc","created_at":"2015-06-25T19:18:22Z","updated_at":"2015-06-25T19:18:36Z","_links":{"self":"https://api.twitch.tv/kraken/users/dylanplayscc"},"display_name":"Dylanplayscc","logo":null,"bio":null,"type":"user"}},{"created_at":"2015-06-26T06:22:56Z","_links":{"self":"https://api.twitch.tv/kraken/users/goldguy421/follows/channels/hardlysober"},"notifications":false,"user":{"_id":92309564,"name":"goldguy421","created_at":"2015-05-30T23:01:27Z","updated_at":"2015-06-22T04:30:08Z","_links":{"self":"https://api.twitch.tv/kraken/users/goldguy421"},"display_name":"Goldguy421","logo":null,"bio":null,"type":"user"}},{"created_at":"2015-06-26T04:40:18Z","_links":{"self":"https://api.twitch.tv/kraken/users/mrbobcat321/follows/channels/hardlysober"},"notifications":false,"user":{"_id":92797431,"name":"mrbobcat321","created_at":"2015-06-06T01:53:50Z","updated_at":"2015-06-25T06:23:02Z","_links":{"self":"https://api.twitch.tv/kraken/users/mrbobcat321"},"display_name":"mrbobcat321","logo":null,"bio":"im 13 love to play wizard101 i going to start doing this more often so ya :)","type":"user"}}],"_total":437,"_links":{"self":"https://api.twitch.tv/kraken/channels/hardlysober/follows?direction=DESC&limit=5&offset=0","next":"https://api.twitch.tv/kraken/channels/hardlysober/follows?direction=DESC&limit=5&offset=5"}}

                json = json.GetBetween("{", "}", true, false);
                // "follows":[{"created_at":"2015-06-27T06:25:12Z","_links":{"self":"https://api.twitch.tv/kraken/users/volt_100/follows/channels/hardlysober"},"notifications":false,"user":{"_id":79242000,"name":"volt_100","created_at":"2015-01-08T17:08:01Z","updated_at":"2015-06-20T16:41:10Z","_links":{"self":"https://api.twitch.tv/kraken/users/volt_100"},"display_name":"volt_100","logo":"http://static-cdn.jtvnw.net/jtv_user_pictures/volt_100-profile_image-653aa9b8c5343c09-300x300.jpeg","bio":null,"type":"user"}},{"created_at":"2015-06-27T05:50:23Z","_links":{"self":"https://api.twitch.tv/kraken/users/doctordoofenshmirtz/follows/channels/hardlysober"},"notifications":false,"user":{"_id":73136919,"name":"doctordoofenshmirtz","created_at":"2014-10-15T22:50:12Z","updated_at":"2015-06-20T01:00:20Z","_links":{"self":"https://api.twitch.tv/kraken/users/doctordoofenshmirtz"},"display_name":"DoctorDoofenshmirtz","logo":null,"bio":null,"type":"user"}},{"created_at":"2015-06-27T01:12:13Z","_links":{"self":"https://api.twitch.tv/kraken/users/dylanplayscc/follows/channels/hardlysober"},"notifications":false,"user":{"_id":94456844,"name":"dylanplayscc","created_at":"2015-06-25T19:18:22Z","updated_at":"2015-06-25T19:18:36Z","_links":{"self":"https://api.twitch.tv/kraken/users/dylanplayscc"},"display_name":"Dylanplayscc","logo":null,"bio":null,"type":"user"}},{"created_at":"2015-06-26T06:22:56Z","_links":{"self":"https://api.twitch.tv/kraken/users/goldguy421/follows/channels/hardlysober"},"notifications":false,"user":{"_id":92309564,"name":"goldguy421","created_at":"2015-05-30T23:01:27Z","updated_at":"2015-06-22T04:30:08Z","_links":{"self":"https://api.twitch.tv/kraken/users/goldguy421"},"display_name":"Goldguy421","logo":null,"bio":null,"type":"user"}},{"created_at":"2015-06-26T04:40:18Z","_links":{"self":"https://api.twitch.tv/kraken/users/mrbobcat321/follows/channels/hardlysober"},"notifications":false,"user":{"_id":92797431,"name":"mrbobcat321","created_at":"2015-06-06T01:53:50Z","updated_at":"2015-06-25T06:23:02Z","_links":{"self":"https://api.twitch.tv/kraken/users/mrbobcat321"},"display_name":"mrbobcat321","logo":null,"bio":"im 13 love to play wizard101 i going to start doing this more often so ya :)","type":"user"}}],"_total":437,"_links":{"self":"https://api.twitch.tv/kraken/channels/hardlysober/follows?direction=DESC&limit=5&offset=0","next":"https://api.twitch.tv/kraken/channels/hardlysober/follows?direction=DESC&limit=5&offset=5"}

                SqlTwitchChannel channel = new SqlTwitchChannel(Twitch.GetUserFromName(json.GetBetween("https://api.twitch.tv/kraken/channels/", "/")));

                string follows = json.GetBetween("\"follows\":[", "]", true, false);
                // follows = {"created_at":"2015-06-27T06:25:12Z","_links":{"self":"https://api.twitch.tv/kraken/users/volt_100/follows/channels/hardlysober"},"notifications":false,"user":{"_id":79242000,"name":"volt_100","created_at":"2015-01-08T17:08:01Z","updated_at":"2015-06-20T16:41:10Z","_links":{"self":"https://api.twitch.tv/kraken/users/volt_100"},"display_name":"volt_100","logo":"http://static-cdn.jtvnw.net/jtv_user_pictures/volt_100-profile_image-653aa9b8c5343c09-300x300.jpeg","bio":null,"type":"user"}},{"created_at":"2015-06-27T05:50:23Z","_links":{"self":"https://api.twitch.tv/kraken/users/doctordoofenshmirtz/follows/channels/hardlysober"},"notifications":false,"user":{"_id":73136919,"name":"doctordoofenshmirtz","created_at":"2014-10-15T22:50:12Z","updated_at":"2015-06-20T01:00:20Z","_links":{"self":"https://api.twitch.tv/kraken/users/doctordoofenshmirtz"},"display_name":"DoctorDoofenshmirtz","logo":null,"bio":null,"type":"user"}},{"created_at":"2015-06-27T01:12:13Z","_links":{"self":"https://api.twitch.tv/kraken/users/dylanplayscc/follows/channels/hardlysober"},"notifications":false,"user":{"_id":94456844,"name":"dylanplayscc","created_at":"2015-06-25T19:18:22Z","updated_at":"2015-06-25T19:18:36Z","_links":{"self":"https://api.twitch.tv/kraken/users/dylanplayscc"},"display_name":"Dylanplayscc","logo":null,"bio":null,"type":"user"}},{"created_at":"2015-06-26T06:22:56Z","_links":{"self":"https://api.twitch.tv/kraken/users/goldguy421/follows/channels/hardlysober"},"notifications":false,"user":{"_id":92309564,"name":"goldguy421","created_at":"2015-05-30T23:01:27Z","updated_at":"2015-06-22T04:30:08Z","_links":{"self":"https://api.twitch.tv/kraken/users/goldguy421"},"display_name":"Goldguy421","logo":null,"bio":null,"type":"user"}},{"created_at":"2015-06-26T04:40:18Z","_links":{"self":"https://api.twitch.tv/kraken/users/mrbobcat321/follows/channels/hardlysober"},"notifications":false,"user":{"_id":92797431,"name":"mrbobcat321","created_at":"2015-06-06T01:53:50Z","updated_at":"2015-06-25T06:23:02Z","_links":{"self":"https://api.twitch.tv/kraken/users/mrbobcat321"},"display_name":"mrbobcat321","logo":null,"bio":"im 13 love to play wizard101 i going to start doing this more often so ya :)","type":"user"}}

                if (follows != null)
                {
                    string[] followsJsonList = follows.Tokenize("{\"created_at\":\"", true);
                    // followsList[i] = {"created_at":"2015-06-27T06:25:12Z","_links":{"self":"https://api.twitch.tv/kraken/users/volt_100/follows/channels/hardlysober"},"notifications":false,"user":{"_id":79242000,"name":"volt_100","created_at":"2015-01-08T17:08:01Z","updated_at":"2015-06-20T16:41:10Z","_links":{"self":"https://api.twitch.tv/kraken/users/volt_100"},"display_name":"volt_100","logo":"http://static-cdn.jtvnw.net/jtv_user_pictures/volt_100-profile_image-653aa9b8c5343c09-300x300.jpeg","bio":null,"type":"user"}},
                    // w/ or w/o a comma at the end

                    foreach (string followJson in followsJsonList)
                    {
                        string userJson = followJson.GetBetween("\"user\":{", ",\"type\":\"user\"}");
                        // userJson = "_id":79242000,"name":"volt_100","created_at":"2015-01-08T17:08:01Z","updated_at":"2015-06-20T16:41:10Z","_links":{"self":"https://api.twitch.tv/kraken/users/volt_100"},"display_name":"volt_100","logo":"http://static-cdn.jtvnw.net/jtv_user_pictures/volt_100-profile_image-653aa9b8c5343c09-300x300.jpeg","bio":null

                        SqlTwitchUser user = ParseUser(userJson);
                        if (user != null)
                        {
                            SqlTwitchFollower follower = new SqlTwitchFollower(user, channel);
                            followers.AddLast(follower);
                        }
                    }
                }

                // TODO for later, followerCount = uint.Parse(SoberString.TextBetween(json, "],\"_total\":", ",", false, true));
            }

            return followers.ToArray<SqlTwitchFollower>();
        }