<commit_before>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Kent.Boogaart.KBCsv;
using MongoDB.Bson;
using Twitterizer;
using twitter.GetFriends.Properties;

namespace twitter.GetFriends
{
    internal sealed class Program
    {
        private static OAuthTokens _tokens;

        static Program()
        {
            _tokens = new OAuthTokens
            {
                ConsumerKey = Settings.Default.ConsumerKey,
                ConsumerSecret = Settings.Default.ConsumerSecret
            };
        }
        
        private static void Main()
        {
            if (Settings.Default.UseAccessPair)
            {
                _tokens.AccessToken = Settings.Default.AccessToken;
                _tokens.AccessTokenSecret = Settings.Default.AccessSecret;
            }
            else
            {
                if (string.IsNullOrEmpty(Settings.Default.UserAccessToken) || string.IsNullOrEmpty(Settings.Default.UserAccessSecret))
                {
                    var tokenResponse = GetUserToken();
                    Settings.Default.UserAccessToken = tokenResponse.Token;
                    Settings.Default.UserAccessSecret = tokenResponse.TokenSecret;
                    Settings.Default.UserId = (int)tokenResponse.UserId;
                    Settings.Default.Save();
                }
            }

            {
                var userInfo = GetUserInfo().ToBsonDocument();
                var csvWriter = new CsvWriter(Console.Out);
                csvWriter.WriteHeaderRecord(userInfo.Names.ToArray());
                csvWriter.WriteDataRecord(userInfo.Values);
                Console.WriteLine();
            }

            {
                var users = GetMutualFriends(_tokens).ToBsonDocument();
                var csvWriter = new CsvWriter(Console.Out);
                csvWriter.WriteHeaderRecord(users.Names.ToArray());
                csvWriter.WriteDataRecord(users.Values);
                Console.WriteLine();
            }
            
            Console.Write("Press any key to continue . . .");
            Console.ReadKey(false);
            Console.WriteLine();
        }

        private static TwitterUser GetUserInfo()
        {
            _tokens.AccessToken = Settings.Default.UserAccessToken;
            _tokens.AccessTokenSecret = Settings.Default.UserAccessSecret;

            var lookupOptions = new LookupUsersOptions();
            lookupOptions.UserIds.Add(Settings.Default.UserId);
            lookupOptions.UseSSL = true;

            var userInfo = TwitterUser.Lookup(_tokens, lookupOptions);
            return userInfo.ResponseObject.First();
        }<commit_msg>The program only lists friends, and messages that arent part of the csv go to stderr.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Kent.Boogaart.KBCsv;
using MongoDB.Bson;
using Twitterizer;
using twitter.GetFriends.Properties;

namespace twitter.GetFriends
{
    internal sealed class Program
    {
        private static OAuthTokens _tokens;

        static Program()
        {
            _tokens = new OAuthTokens
            {
                ConsumerKey = Settings.Default.ConsumerKey,
                ConsumerSecret = Settings.Default.ConsumerSecret
            };
        }
        
        private static void Main()
        {
            if (Settings.Default.UseAccessPair)
            {
                _tokens.AccessToken = Settings.Default.AccessToken;
                _tokens.AccessTokenSecret = Settings.Default.AccessSecret;
            }
            else
            {
                if (string.IsNullOrEmpty(Settings.Default.UserAccessToken) || string.IsNullOrEmpty(Settings.Default.UserAccessSecret))
                {
                    var tokenResponse = GetUserToken();
                    Settings.Default.UserAccessToken = tokenResponse.Token;
                    Settings.Default.UserAccessSecret = tokenResponse.TokenSecret;
                    Settings.Default.UserId = (int)tokenResponse.UserId;
                    Settings.Default.Save();
                }
                _tokens.AccessToken = Settings.Default.UserAccessToken;
                _tokens.AccessTokenSecret = Settings.Default.UserAccessSecret;
            }

            /*
            {
                var userInfo = GetUserInfo().ToBsonDocument();
                var csvWriter = new CsvWriter(Console.Out);
                csvWriter.WriteHeaderRecord(userInfo.Names.ToArray());
                csvWriter.WriteDataRecord(userInfo.Values);
                Console.WriteLine();
            }
            */
            {
                var users = GetMutualFriends(_tokens);
                var csvWriter = new CsvWriter(Console.Out);
                csvWriter.WriteHeaderRecord(users.First().ToBsonDocument().Names.ToArray());
                foreach (var user in users) { csvWriter.WriteDataRecord(user.ToBsonDocument().Values.ToArray()); }
                Console.WriteLine();
            }
            
            Console.Write("Press any key to continue . . .");
            Console.ReadKey(false);
            Console.WriteLine();
        }

        private static TwitterUser GetUserInfo()
        {
            var lookupOptions = new LookupUsersOptions();
            lookupOptions.UserIds.Add(Settings.Default.UserId);
            lookupOptions.UseSSL = true;

            var userInfo = TwitterUser.Lookup(_tokens, lookupOptions);
            return userInfo.ResponseObject.First();
        }
{'fraction_non_alphanumeric': 0.08315373563218391, 'fraction_numerical': 0.0, 'mean_word_length': 1.7339224349533628, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '336492', 'n_tokens_mistral': 1353, 'n_tokens_neox': 1290, 'n_words': 234}