Exemplo n.º 1
0
 static int Main(string[] args)
 {
     try
     {
         string     credentialsPath        = args[0];
         string     sheetId                = args[1];
         string     tabName                = args[2];
         string     diapasone              = args[3];
         string     columnNames            = args[4]; // [["Партнер", "partner_ru_name"], ["CRM name", "crm_sell_point_name"]]
         string     columnNamesWithAlter   = args[5]; // [["Партнер", "partner_ru_name"], ["CRM name", "crm_sell_point_name"]]
         string[]   parsedColumns          = string.IsNullOrWhiteSpace(columnNames)?null:JsonConvert.DeserializeObject <string[]>(columnNames);
         string[][] parsedColumnsWithAlter = string.IsNullOrWhiteSpace(columnNamesWithAlter) ? null : JsonConvert.DeserializeObject <string[][]>(columnNamesWithAlter);
         KeyValuePair <string, string>[] argCols;
         if (parsedColumnsWithAlter != null && parsedColumnsWithAlter.Length > 0)
         {
             argCols = parsedColumnsWithAlter.Select(x => new KeyValuePair <string, string>(x[0], x[1])).ToArray();
         }
         else if (columnNames != null && columnNames.Length > 0)
         {
             argCols = parsedColumns.Select(x => new KeyValuePair <string, string>(x, x)).ToArray();
         }
         else
         {
             argCols = new KeyValuePair <string, string> [0];
         }
         string destTable        = args[6];
         string destSchema       = args[7];
         string connectionString = File.ReadAllText(args[8]);
         // Google Sheet
         //string connectionString = "Data Source=localhost;Initial Catalog=localdb;Integrated Security=True;MultipleActiveResultSets=True";
         GSReportManager gsrm = new GSReportManager(new GSApiV4ReportReceiver(new GSConfig {
             CredentialServiceAccountJsonPath = credentialsPath
         }));
         var gsrep = gsrm.Get(new GSReportInitializer(
                                  sheetId,
                                  tabName,
                                  diapasone,
                                  argCols
                                  )
                              );
         CustomReportStorageManager gsrmsm = new CustomReportStorageManager(
             new MsSqlCustomReportSaver(
                 new MsSqlDataTableStorageWorker(),
                 new MsSqlStorageInitializer(connectionString, destTable, true, destSchema)
                 )
             );
         gsrmsm.Save(gsrep);
         return(0);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemplo n.º 2
0
        static int Main(string[] args)
        {
            Console.OutputEncoding = Encoding.Unicode;
            string credentialsJsonPath = args[0];
            string reportType          = args[1];

            string[] columns                = JsonConvert.DeserializeObject <string[]>(args[2]);
            string   dateFormat             = args[3];
            DateTime eventDate              = DateTime.ParseExact(args[4], dateFormat, CultureInfo.CurrentCulture);
            string   dbConnectionStringPath = File.ReadAllText(args[5]);
            string   destTblName            = args[6];

            var rep = new YDReportManager(
                new YDRestApi5CustomReportReceiver()
                ).Get(
                new YDCustomReportInitializer(
                    new YDConfig
            {
                CredentialsJsonPath = credentialsJsonPath
            },
                    reportType,
                    eventDate,
                    eventDate,
                    columns,
                    false
                    )
                );

            if (rep.IsReady)
            {
                CustomReportStorageManager gsrmsm = new CustomReportStorageManager(
                    new MsSqlCustomReportSaver(
                        new MsSqlDataTableStorageWorker(),
                        new MsSqlStorageInitializer(dbConnectionStringPath, destTblName, true, "dbo")
                        )
                    );
                gsrmsm.Save(rep);
                return(0);
            }
            else
            {
                return(2);
            }
        }
Exemplo n.º 3
0
        static int Main(string[] args)
        {
            string   view_id    = args[0];
            string   dateFormat = args[1];
            string   ga_day     = args[2];
            DateTime event_day  = DateTime.ParseExact(ga_day, dateFormat, CultureInfo.CurrentCulture);
            string   metricStr  = args[3];

            string [][] metrics = string.IsNullOrWhiteSpace(metricStr) ? new string[0][] : JsonConvert.DeserializeObject <string[][]>(metricStr);
            string      dimStr  = args[4];

            string[][] dimesnions = string.IsNullOrWhiteSpace(dimStr) ? new string[0][] : JsonConvert.DeserializeObject <string[][]>(dimStr);
            string     credentialUserAccountJsonPath    = args[5];
            string     credentialServiceAccountJsonPath = args[6];
            string     connectionString = File.ReadAllText(args[7]);
            string     destinationTable = args[8];
            GCustomReportInitializer reportInitializer = new GCustomReportInitializer(
                new GView(view_id),
                event_day,
                metrics.Select(x => new KeyValuePair <string, string>(x[0], x[1])).ToArray(),
                dimesnions.Select(x => new KeyValuePair <string, string>(x[0], x[1])).ToArray()
                );
            GReportManager gaReportManager = new GReportManager(
                new GAnalyticsReportingV4CustomReportReciver(
                    new GConfig
            {
                CredentialUserAccountJsonPath      = string.IsNullOrWhiteSpace(credentialUserAccountJsonPath)?null: credentialUserAccountJsonPath
                , CredentialServiceAccountJsonPath = string.IsNullOrWhiteSpace(credentialServiceAccountJsonPath) ? null : credentialServiceAccountJsonPath
            }
                    )
                );
            var re = gaReportManager.Get(reportInitializer);

            CustomReportStorageManager gsm = new CustomReportStorageManager(
                new MsSqlCustomReportSaver(
                    new MsSqlDataTableStorageWorker(),
                    new MsSqlStorageInitializer(connectionString, destinationTable, true, "dbo")
                    )
                );

            gsm.Save(re);
            return(0);
        }
Exemplo n.º 4
0
        static int Main(string[] args)
        {
            ComagicCnslConfig ccc        = JsonConvert.DeserializeObject <ComagicCnslConfig>(File.ReadAllText(args[0]));
            string            apiHost    = args[1];
            string            apiVer     = args[2];
            string            dateFormat = args[3];
            string            reportType = args[4];
            string            dateFrom   = args[5];
            string            dateTo     = args[6];

            string [] columnNames = JsonConvert.DeserializeObject <string[]>(args[7]);
            string    tableName   = args[8];
            CMConfig  cmConfig    = new CMConfigWithAccessToken
                                    (
                ccc.AccessToken,
                apiHost,
                apiVer,
                dateFormat
                                    );
            CMCustomReportManager cmrm = new CMCustomReportManager(new CMCustomReportReceiver(cmConfig));
            var cmrep = cmrm.Get(new CMCustomReportInitializer(
                                     cmConfig,
                                     reportType,
                                     dateFrom,
                                     dateTo,
                                     columnNames
                                     )
                                 );
            CustomReportStorageManager cmsm = new CustomReportStorageManager(
                new MsSqlCustomReportSaver(
                    new MsSqlDataTableStorageWorker(),
                    new MsSqlStorageInitializer(
                        ccc.DbConnectionString,
                        tableName,
                        true,
                        "dbo"
                        )
                    )
                );

            cmsm.Save(cmrep);
            return(0);
        }
Exemplo n.º 5
0
        static int Main(string[] args)
        {
            string credentialsJsonPath = args[0];
            string developerToken      = File.ReadAllText(args[1]);
            string accountId           = args[2];
            string reportType          = args[3];

            KeyValuePair <string, string>[] columns = JsonConvert.DeserializeObject <string[][]>(args[4]).Select(x => new KeyValuePair <string, string>(x[0], x[1])).ToArray();
            string   dateFormat         = args[5];
            DateTime dateFrom           = DateTime.ParseExact(args[6], dateFormat, CultureInfo.CurrentCulture);
            string   dbConnectionString = File.ReadAllText(args[7]);
            string   tblName            = args[8];
            //Console.WriteLine(string.IsNullOrWhiteSpace(dbConnectionString)?"F**K NO Connection string": dbConnectionString);
            GADCustomReportManager p = new GADCustomReportManager(new ApiAdwrods201809CustomReportReceiver());
            var gadRep = p.Get(new GADCustomReportInitializer(
                                   new GADConfig {
                CredentialsJsonPath = credentialsJsonPath,
                DeveloperToken      = developerToken
            },
                                   accountId,
                                   columns,    //new string[] { "CampaignId", "Cost" },
                                   reportType, //"CAMPAIGN_PERFORMANCE_REPORT",
                                   dateFrom,   //new DateTime(2019, 1, 1),
                                   dateFrom    //new DateTime(2019, 5, 21)
                                   ));
            CustomReportStorageManager cmsm = new CustomReportStorageManager(
                new MsSqlCustomReportSaver(
                    new MsSqlDataTableStorageWorker(),
                    new MsSqlStorageInitializer(
                        dbConnectionString,
                        tblName,
                        true,
                        "dbo"
                        )
                    )
                );

            cmsm.Save(gadRep);
            return(0);
        }
Exemplo n.º 6
0
        static int Main(string[] args)
        {
            string   tokensJsonPath   = args[0];
            string   connectionString = File.ReadAllText(args[1]);
            CTConfig ctConfig         = new CTConfig
            {
                TokensJsonPath = tokensJsonPath
            };
            string siteId   = args[2];
            string dateFrom = args[3];
            string dateTo   = args[4];

            string[] columnNames      = JsonConvert.DeserializeObject <string[]>(args[5]);
            string   tblName          = args[6];
            CTCustomReportManager ctm = new CTCustomReportManager(new CTRestCallsReportReceiver(ctConfig));
            var ctr = ctm.Get(new CTCustomReportInitializer(
                                  siteId,
                                  dateFrom,
                                  dateTo,
                                  columnNames

                                  ));
            CustomReportStorageManager ctsm = new CustomReportStorageManager(
                new MsSqlCustomReportSaver(
                    new MsSqlDataTableStorageWorker(),
                    new MsSqlStorageInitializer(
                        connectionString,
                        tblName,
                        true,
                        "dbo"
                        )
                    )
                );

            ctsm.Save(ctr);
            return(0);
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            string connectionString = "Data Source=localhost;Initial Catalog=localdb;Integrated Security=True;MultipleActiveResultSets=True";

            /*
             * // Comagic https://dataapi.comagic.ru/v2.0
             *
             * CMCustomReportManager cmrm = new CMCustomReportManager(
             *  new CMCustomReportReceiver(
             *      new CMConfigWithCredentailsPath
             *      (
             *          @"C:\a.shamshur\public_projects\integration\common_credentials\comagic\credentials.json",
             *          "https://dataapi.comagic.ru",
             *          "v2.0",
             *          "yyyy-MM-dd HH:mm:ss"
             *      )
             *  )
             * );
             * var cmrep = cmrm.Get(new CMCustomReportInitializer(
             *      "communications_report",
             *      new DateTime(2019,1,1),
             *      new DateTime(2019, 1, 2),
             *      new string[]
             *      {
             *           "id"
             *          ,"communication_type"
             *          ,"communication_number"
             *          ,"date_time"
             *          ,"ua_client_id"
             *          ,"ym_client_id"
             *          ,"sale_date"
             *          ,"sale_cost"
             *          ,"search_query"
             *          ,"search_engine"
             *          ,"referrer_domain"
             *          ,"referrer"
             *          ,"entrance_page"
             *          ,"gclid"
             *          ,"yclid"
             *          ,"ymclid"
             *          ,"ef_id"
             *          ,"channel"
             *          ,"tags"
             *          ,"site_id"
             *          ,"site_domain_name"
             *          ,"campaign_id"
             *          ,"campaign_name"
             *          ,"visit_other_campaign"
             *          ,"visitor_id"
             *          ,"person_id"
             *          ,"visitor_type"
             *          ,"visitor_session_id"
             *          ,"visits_count"
             *          ,"visitor_first_campaign_id"
             *          ,"visitor_first_campaign_name"
             *          ,"visitor_city"
             *          ,"visitor_region"
             *          ,"visitor_country"
             *          ,"visitor_device"
             *          ,"visitor_custom_properties"
             *          ,"segments"
             *          ,"utm_source"
             *          ,"utm_medium"
             *          ,"utm_term"
             *          ,"utm_content"
             *          ,"utm_campaign"
             *          ,"openstat_ad"
             *          ,"openstat_campaign"
             *          ,"openstat_service"
             *          ,"openstat_source"
             *          ,"attributes"
             *      }
             *  )
             * );
             * CustomReportStorageManager cmsm = new CustomReportStorageManager(
             *  new MsSqlCustomReportSaver(
             *      new MsSqlDataTableStorageWorker(),
             *      new MsSqlStorageInitializer(
             *          "Data Source=localhost;Initial Catalog=localdb;Integrated Security=True;MultipleActiveResultSets=True",
             *          "t_stg_yd_data",
             *          true,
             *          "dbo"
             *      )
             *  )
             * );
             * cmsm.Save(cmrep);
             *
             *
             * // Google Sheet
             *
             * GSReportManager gsrm = new GSReportManager(new GSApiV4ReportReceiver(new GSConfig { CredentialServiceAccountJsonPath = @"C:\a.shamshur\public_projects\integration\common_credentials\google\bi-dev-001-06eaf0f926da.json" }));
             * var gsrep = gsrm.Get(new GSReportInitializer(
             *      "1h2yzyTI7dPFTe1aid7IVxyhNGrMTL1ARX0mVZIdc5qM",
             *      "Лист1",
             *      "B2:M",
             *      new KeyValuePair<string, string> [] {
             *          new KeyValuePair<string, string>("Партнер", "partner_ru_name"),
             *          new KeyValuePair<string, string>("CRM name", "crm_sell_point_name") }
             *  )
             * );
             * CustomReportStorageManager gsrmsm = new CustomReportStorageManager(
             *  new MsSqlCustomReportSaver(
             *      new MsSqlDataTableStorageWorker(),
             *      new MsSqlStorageInitializer(connectionString, "t_stg_gs_data", true, "dbo")
             *  )
             * );
             * gsrmsm.Save(gsrep);
             */
            // GA download and store in MS SQL

            GCustomReportInitializer reportInitializer = new GCustomReportInitializer(
                new GView("ga:157149180"),
                new DateTime(2019, 4, 1),
                new string [] {
                "ga:sessions"
            },
                new string [] {
                "ga:source",
                "ga:medium",
                "ga:campaign",
                "ga:adContent",
                "ga:keyword",
                "ga:dimension3"
            }
                );
            GReportManager gaReportManager = new GReportManager(
                new GAnalyticsReportingV4CustomReportReciver(
                    new GConfig
            {
                CredentialUserAccountJsonPath = @"C:\a.shamshur\public_projects\integration\common_credentials\google\bi-dev-user-credentials.json"
                                                //,CredentialServiceAccountJsonPath = @"C:\a.shamshur\public_projects\integration\common_credentials\google\bi-dev-001-06eaf0f926da.json"
            }
                    )
                );
            var re = gaReportManager.Get(reportInitializer);

            CustomReportStorageManager gsm = new CustomReportStorageManager(
                new MsSqlCustomReportSaver(
                    new MsSqlDataTableStorageWorker(),
                    new MsSqlStorageInitializer(connectionString, "t_stg_ga_data", true, "dbo")
                    )
                );

            gsm.Save(re);

            /*
             * // YANDEX
             *
             *          var token = YCommonCredentialManager.Get(new RestCredentialInitializer(@"C:\a.shamshur\public_projects\integration\common_credentials\yandex\bi-dev-credentials.json"));
             *          YReportInitializer initializer = new YReportInitializer(
             *                  new YCounter { Id = 52783963 },
             *  new DateTime(2019, 3, 14),
             *                  new string [] {"ym:s:visits"},
             *  new string[] {"ym:s:UTMSource"}
             * );
             *          YReportManager yrm = new YReportManager(new YRestReportReceiver(
             *  new YConfig
             *  {
             *      TokensJsonPath = @"C:\a.shamshur\public_projects\integration\common_credentials\yandex\bi-dev-credentials.json",
             *      ApiUrl = "https://api-metrika.yandex.net/"
             *  }
             * ));
             *          var r = yrm.Get(initializer);
             * CustomReportStorageManager ysm = new CustomReportStorageManager(
             *  new MsSqlCustomReportSaver(
             *      new MsSqlDataTableStorageWorker(),
             *      new MsSqlStorageInitializer(
             *          "Data Source=localhost;Initial Catalog=localdb;Integrated Security=True;MultipleActiveResultSets=True",
             *          "t_stg_yd_data",
             *          true,
             *          "dbo"
             *      )
             *  )
             * );
             * ysm.Save(r);
             */

            //ADWORDS

            /*
             * GADCustomReportManager p = new GADCustomReportManager(new ApiAdwrods201809CustomReportReceiver());
             * var gadRep = p.Get(new GADCustomReportInitializer(
             *  new GADConfig {
             *      CredentialsJsonPath = @"C:\a.shamshur\public_projects\integration\common_credentials\google\google-adwords-credentials_smartprice.json",
             *      DeveloperToken = "QXcVkUmW93V6TcMiqnXlAA"
             *  },
             *  "250-186-1680",
             *  new string[] { "CampaignId", "Cost" },
             *  "CAMPAIGN_PERFORMANCE_REPORT",
             *  new DateTime(2019, 1, 1),
             *  new DateTime(2019, 5, 21)
             * ));
             */

            //CALL-TOUCH

            /*
             * CTConfig ctConfig = new CTConfig
             * {
             *  TokensJsonPath = @"C:\a.shamshur\public_projects\integration\common_credentials\calltouch\credentials-28466.json"
             * };
             * CTCustomReportManager ctm = new CTCustomReportManager(new CTRestCallsReportReceiver(ctConfig));
             * var ctr = ctm.Get(new CTCustomReportInitializer(
             *  "29196",
             *  new DateTime(2019, 4, 1),
             *  new DateTime(2019, 4, 1),
             *  new string[]
             *  {
             *      "date",
             *      "source",
             *      "yaClientId"
             *  }
             * ));
             * CustomReportStorageManager ctsm = new CustomReportStorageManager(
             *  new MsSqlCustomReportSaver(
             *      new MsSqlDataTableStorageWorker(),
             *      new MsSqlStorageInitializer(
             *          "Data Source=localhost;Initial Catalog=localdb;Integrated Security=True;MultipleActiveResultSets=True",
             *          "t_stg_ct_data",
             *          true,
             *          "dbo"
             *      )
             *  )
             * );
             * ctsm.Save(ctr);
             */
        }