Advertisement
Harshmage

FCC Telemarketer and RoboCall Blacklist DL & Format

Feb 11th, 2016
600
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. . ".\Out-Pastebin.ps1"
  2.  
  3. <# Updated 20160404
  4.     20160812
  5.         ~ Updated to pull custom CSV from FCC's new API site
  6.         t Working on FreePBX function, next update will have it complete
  7.     20160404
  8.         + Added log file statements
  9.         ~ Changed inital question to new or compare, defaults to compare if not new
  10.         - Removed compare question in favor of default
  11.     20160328
  12.         + Added If statment for comparison question, as script must be run twice to have a comparison
  13.         + Added While statment to compare $file and $file2 to see if they are the same file, and ask for a new $file2 if true
  14.         + Added subtraction of 1 from count reports (see ending Write-Hosts in the Delta and Primary If statement)
  15.     20160321
  16.         ~ Reverted back to if statements instead of functions that just broke everything.
  17.        
  18. #>
  19.  
  20. $date = Get-Date -Format yyyyMMdd
  21. $logFile = ".\FCCListLog.log"
  22. $tmCIDN = ".\TelemarketingCIDN.csv"
  23. $tmABPN = ".\TelemarketingABPN.csv"
  24. $tmTemp = ".\Telemarketing-Temp"
  25. $tmDelta = ".\Telemarketing_RoboCall_Weekly_Data_Deltas-$date.csv"
  26. $tmDeltaList = ".\Telemarketing_RoboCall_Weekly_Data_List_Deltas-$date.csv"
  27. $tmMaster = ".\Telemarketing_RoboCall_Weekly_Data_Primary-$date.csv"
  28. $tmMasterList = ".\Telemarketing_RoboCall_Weekly_Data_List_Primary-$date.csv"
  29. If (Test-Path $tmCIDN) { Remove-Item $tmCIDN }
  30. If (Test-Path $tmABPN) { Remove-Item $tmABPN }
  31. If (Test-Path $tmTemp) { Remove-Item $tmTemp }
  32. If (!(Test-Path $logFile)) { New-Item $logFile -ItemType file }
  33.  
  34. # Gives us the Open File dialog
  35. Function Get-FileName($initialDirectory)
  36. {  
  37.     [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") |
  38.     Out-Null
  39.  
  40.     $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
  41.     $OpenFileDialog.initialDirectory = $initialDirectory
  42.     $OpenFileDialog.filter = "CSV files (*.csv)| *.csv"
  43.     $OpenFileDialog.ShowDialog() | Out-Null
  44.     $OpenFileDialog.filename
  45. } #end function Get-FileName
  46.  
  47. # Formatting function to transpose 200 numbers in the column to rows
  48. Function _Transpose($inpFile) {
  49.     If ($inpFile -like "*Delta*") {
  50.         Write-Output "Transpose Using Delta"
  51.         $inpFile = $tmDeltaList
  52.         $outFile = $tmDelta
  53.     } Else {
  54.         Write-Output "Transpose Using Primary"
  55.         $inpFile = $tmTemp
  56.         $outFile = $tmMaster
  57.     }
  58.     $tmTransposeTemp = ".\tmTransposeTemp.csv"
  59.     Write-Output "Creating $tmTransposeTemp"
  60.     Copy-Item $inpFile -Destination $tmTransposeTemp
  61.     # Create file header for Google Contacts import
  62.     $replace = "Name,Given Name,Additional Name,Family Name,Yomi Name,Given Name Yomi,Additional Name Yomi,Family Name Yomi,Name Prefix,Name Suffix,Initials,Nickname,Short Name,Maiden Name,Birthday,Gender,Location,Billing Information,Directory Server,Mileage,Occupation,Hobby,Sensitivity,Priority,Subject,Notes,Group Membership,Phone 1 - Type,Phone 1 - Value" | Out-File $outFile -Append
  63.     $number = 0
  64.     $letter = 65
  65.     $round = 0
  66.     $firstLine = (Import-CSV $tmTransposeTemp) | Select -First 2
  67.     # Will error and stop when it tries to import a null into an array, which is kinda what we want. Should really find a clean exit.
  68.     While ($firstLine[1] -ne $null) {
  69.         # Create index for Spam contacts (Spam A0..Z9)
  70.         If ($number -eq 100) { $number = 0 }
  71.         If ($letter -eq 90) { $letter = 65 }
  72.         if ($round -le 100) {
  73.             $index = [char]$letter + $number.ToString("00")
  74.             $number++
  75.         } else {
  76.             $letter++
  77.             $index = [char]$letter + $number.ToString("00")
  78.             $number++
  79.             $round = 0
  80.         }
  81.         #Write-Output "Spam $index - $($firstLine[0].List)"
  82.         $round++
  83.         $batch = 200
  84.         (Import-CSV $tmTransposeTemp) | Select -First $batch | Export-CSV $tmTemp -NoTypeInformation
  85.         $replace = @(Get-Content $tmTemp) -Join ","
  86.         $replace = $replace -replace '"','' -replace ',',' ::: '
  87.         If ($inpFile -like "*Delta*") {
  88.             $insert = "Spam Delta $index $date,Spam,,,,,,,,,,,,,,,,,,,,,,,,,* My Contacts ::: Spammers,Mobile,"
  89.         } Else {
  90.             $insert = "Spam $index,Spam,,,,,,,,,,,,,,,,,,,,,,,,,* My Contacts ::: Spammers,Mobile,"
  91.         }
  92.         $replace -replace 'Caller ID Number',$insert -replace ', ::: ',',' | Out-File $outFile -Append
  93.         Write-Output "$($insert)$($firstLine[0].'Caller ID Number')"
  94.         (Import-CSV $tmTransposeTemp) | Select -Skip $batch | Export-CSV $tmTemp -NoTypeInformation
  95.         Move $tmTemp -Destination $tmTransposeTemp -Force
  96.         $firstLine = (Import-CSV $tmTransposeTemp) | Select -First 2
  97.         $batch += 200
  98.     }
  99.     If (Test-Path $tmTransposeTemp) { Remove-Item $tmTransposeTemp }
  100.     If (Test-Path $tmTemp) { Remove-Item $tmTemp }
  101. }
  102.  
  103. Function _FreePBX {
  104.     Import-CSV $tmMasterList
  105.     field 1 = numbers
  106.     field 2 = description
  107.     all descriptions = telemarketing
  108. }
  109.  
  110. $start = Get-Date -format "HH:mm:ss"
  111.  
  112. # Get the latest list from the FCC website
  113. Read-Host -Prompt "Get New list or Compare? [N or C]" -OutVariable new
  114. if ($new -like "n") {
  115.     $url = "https://opendata.fcc.gov/api/views/tkbm-mngi/rows.csv?accessType=DOWNLOAD"
  116.     $file = "Telemarketing_RoboCall_Weekly_Data-$date.csv"
  117.     Write-Host $file -ForegroundColor Yellow
  118.     If (!(Get-Item -Path .\Telemarketing_RoboCall_Weekly_Data-$date.csv)) {
  119.         Invoke-WebRequest -Uri $url -OutFile $file -ErrorAction Stop
  120.     }
  121.     $tmMaster = ".\Telemarketing_RoboCall_Weekly_Data_Primary-$date.csv"
  122.     $tmMasterList = ".\Telemarketing_RoboCall_Weekly_Data_List_Primary-$date.csv"
  123. } else {
  124.     $new = "c"
  125.     $file = Get-FileName -initialDirectory "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
  126. }
  127.  
  128. # Delta (Compare) and Primary list generators
  129. if ($new -like "c") {
  130.     $file2 = Get-FileName -initialDirectory "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
  131.     While ($file -eq $file2) {
  132.         Write-Host "Duplicate file selected, please select a new file to compare to..." -ForegroundColor Red
  133.         $file2 = Get-FileName -initialDirectory "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
  134.     }
  135.     $comp1 = Import-CSV $file
  136.     $comp2 = Import-CSV $file2
  137.     Write-Host "Comparing files..." -ForegroundColor Yellow
  138.     Compare-Object $comp1 $comp2 -Property "List" | Export-CSV ".\tmDeltas-$date.csv" -NoTypeInformation
  139.     (Import-CSV ".\tmDeltas-$date.csv") | Select "List" | Export-CSV  $tmDeltaList -NoTypeInformation
  140.     Write-Host "Transposing..." -ForegroundColor Yellow
  141.     _Transpose("Delta")
  142.     Remove-Item ".\tmDeltas-$date.csv"
  143.     $tmDeltaCount = (Get-Content $tmDeltaList) | Measure-Object -Line
  144.     $tmDeltaContacts = (Get-Content $tmDelta) | Measure-Object -Line
  145.     $tmMasterCount = (Get-Content $tmMasterList) | Measure-Object -Line
  146.     $PastebinContent = (Get-Content $tmDelta)
  147.     #Out-Pastebin -InputObject $PastebinContent -PasteTitle "FCC Telemarketer and RoboCall Blacklist - Deltas $date" -ExpiresIn N -Visibility Public -OpenInBrowser -OutVariable PastedURI
  148.     $log = "$date - Primary list is $($tmMasterCount.Lines) numbers, and the Deltas from last file are $($tmDeltaCount.Lines) in $($tmDeltaContacts.Lines), URL $PastedURI"
  149.     Write-Host $log -ForegroundColor Yellow
  150.     $log | Out-File $logFile -Append
  151. } else {
  152.     Write-Output "Creating $tmCIDN"
  153.     Import-CSV $file | Select "Caller ID Number" | Export-CSV $tmCIDN –NoTypeInformation
  154.     (Import-CSV $tmCIDN) | Sort "Caller ID Number" -Unique | Export-CSV $tmCIDN -NoTypeInformation
  155.     Write-Output "Creating $tmABPN"
  156.     Import-CSV $file | Select "Advertiser Business Number" | Export-CSV $tmABPN –NoTypeInformation
  157.     (Import-CSV $tmABPN) | Sort "Advertiser Business Number" -Unique | Export-CSV $tmABPN -NoTypeInformation
  158.     $gcCIDN = Get-Content $tmCIDN
  159.     $gcABPN = Get-Content $tmABPN
  160.     Add-Content $tmTemp $gcCIDN
  161.     Add-Content $tmTemp $gcABPN
  162.     Write-Output "Creating $tmTemp"
  163.     (Import-CSV $tmTemp) | Sort "Caller ID Number" -Unique | Where-Object {$_ -notlike "*Advertiser*"} | Export-CSV $tmTemp -NoTypeInformation
  164.     Get-Content $tmTemp | Select -Skip 1 | Set-Content $tmMasterList
  165.     #(Import-Csv $tmMasterList) | Select-Object @{ expression={$_.'-'}; label='List' } | Export-Csv $tmMasterList -NoTypeInformation
  166.     #Remove-Item $tmTemp
  167.     Write-Output "Transposing..."
  168.     _Transpose("Master")
  169.     If (Test-Path $tmCIDN) { Remove-Item $tmCIDN }
  170.     If (Test-Path $tmABPN) { Remove-Item $tmABPN }
  171.     $tmMasterCount = (Get-Content $tmMasterList) | Measure-Object -Line
  172.     $tmMasterContacts = (Get-Content $tmMaster) | Measure-Object -Line
  173.     $PastebinContent = (Get-Content $tmMaster)
  174.     #Out-Pastebin -InputObject $PastebinContent -PasteTitle "FCC Telemarketer and RoboCall Blacklist - Full $date" -ExpiresIn N -Visibility Public -OpenInBrowser -OutVariable PastedURI
  175.     $log = "$date - Primary list is $($tmMasterCount.Lines) numbers, and $($tmMasterContacts.Lines) contacts, URL $PastedURI"
  176.     Write-Host $log -ForegroundColor Yellow
  177.     $log | Out-File $logFile -Append
  178. }
  179.  
  180. $end = Get-Date -format "HH:mm:ss"
  181. Write-Output "Started  at $($start)"
  182. Write-Output "Finished at $($end)"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement