Aprovechando al máximo las noticias en línea, parte 1

Aprovecha al máximo las noticias en Internet





Inspirado en el artículo ¿Por qué sigo usando RSS?





Yo mismo estoy usando muy activamente el formato de noticias, que me gustaría compartir con la comunidad.





Habrá capturas de pantalla y tal vez una pequeña explicación redundante.





Habrá las siguientes partes:





  1. Parte 1 :





  • ¿Qué información consumo generalmente a través de las noticias?





  • Programas de lectura (agregadores de rss): lo que yo uso personalmente;





  • RSS Atom, ;





  1. 2:





  • (zapier, ifttt);





  1. 3:





  • - .





1

, , , , ( , !). , RSS. . RSS. , RSS! , , RSS .





. , 1.





, , (, ) . , , .





(rss-)

, . , - , Apple .





- , .. - «  » . .





RSS Owl:





Búho RSS
RSS Owl

JetBrains: OMEA Reader:





Lector JetBrains OMEA
JetBrains OMEA Reader

JetBrains , , :









  • ,









  • - .





RSS Atom,

, - xml-. RSS ( , ). :





  • - - <pubDate>Sun, 28 May 2017 09:00:00 GMT</pubDate>



    ,





  • - , RSS, ( ). . , , .





RSS Google - Atom, .





, , curl, wget (- ?) Power-shell.





, , Windows 10 curl «   » . .





Curl:





chcp 65001  
  
curl ^  
  --header "user-agent: cURL automated task" ^  
  --output "%TEMP%\updates.xml" ^  
  "https://news.webits.1c.ru/news/Updates/atom"
      
      



, curl: (35) schannel: next InitializeSecurityContext failed: Unknown error (0x80092012) - .



5 .





BOM, . - .





Power-shell:





# file: Get-News-001.ps1  
Clear-Host  
  
$webClient = New-Object Net.WebClient  
$webClient.UseDefaultCredentials = $true  
$webClient.Proxy.Credentials = $webClient.Credentials  
$webClient.Headers.Add("user-agent", "PowerShell automated task")  
  
# ,  - ,     BOM,     
#  DownloadString       .  
#       UTF8  
$newsData = $webClient.DownloadData("https://news.webits.1c.ru/news/Updates/atom")  
  
Write-Host ([System.Text.Encoding]::UTF8).GetString($newsData)

      
      



, power-shell . IDE, , -ExecutionPolicy=RemoteSigned







powershell -file "Get-News-001.ps1" -ExecutionPolicy=RemoteSigned
      
      



? . - xml, - ? , - ?





1 «  = »



« = »







:





# file: Get-News-002.ps1
Clear-Host

#  ,   
$CategoryProducts = @(
    # "=1:  ", # !
    "= " # !
)
$CategoryNewsTypes = @(
    "  =  "
)

$webClient = New-Object Net.WebClient
$webClient.UseDefaultCredentials = $true
$webClient.Proxy.Credentials = $webClient.Credentials
$webClient.Headers.Add("user-agent", "PowerShell automated task")

# ..   BOM,    .
$newsData = $webClient.DownloadData("https://news.webits.1c.ru/news/Updates/atom")
[xml]$news = ([System.Text.Encoding]::UTF8).GetString($newsData)
#[xml]$news = Get-Content -Encoding UTF8 -LiteralPath "$($env:TEMP)\updates.xml"

for($c1=0;$c1 -lt $news.feed.entry.Count;$c1++){
    #  
    $entry = $news.feed.entry[$c1]
    $ProductName    = ""
    $bFoundProduct  = $false
    $bFoundNewsType = $false
    for($c2=0;$c2 -lt $entry.category.Count;$c2++){
        #     
        $CategoryProducts | ForEach-Object {
            if($entry.category[$c2].term -eq $_){
                $ProductName = $entry.category[$c2].term
                $bFoundProduct = $true
            }
        }
        $CategoryNewsTypes | ForEach-Object {
            if($entry.category[$c2].term -eq $_){
                $bFoundNewsType = $true
            }
        }
    }
    if ($bFoundProduct -and $bFoundNewsType) {
        Write-Host ("  . : {0}, : {1}" -f ($entry.id, $entry.title))
    }

}

      
      



. , ? , .





, - entry.id



- .





# file: Get-News-003.ps1
Clear-Host

#      email.
$sendedEmailsPath = "$($env:TEMP)\sended.csv" # !
if(Test-Path $sendedEmailsPath){
    #  
} else {
    #    -   
    Add-Content -LiteralPath $sendedEmailsPath -Encoding UTF8 -Force -Value ""
}
$sendedEmails = Get-Content -LiteralPath $sendedEmailsPath -Encoding UTF8 -Force

#  
$CurrentDate        = Get-Date 
$CurrentDate_String = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$From               = "news_center_tester@mail.ru" # !
$To                 = "old-coder-75@mail.ru" # !
$EncodingUTF8       = [System.Text.Encoding]::UTF8
$UserName           = "news_center_tester" # !
$Password           = "*****" # !
$Credential         = New-Object -TypeName System.Management.Automation.PSCredential($UserName, (ConvertTo-SecureString $Password -AsPlainText -Force))

$SMTPServer         = "smtp.mail.ru" # !
$SMTPPort           = 587 # !

#  ,   
$CategoryProducts = @(
    # "=1:  ", # !
    "= " # !
)
$CategoryNewsTypes = @(
    "  =  "
)

$webClient = New-Object Net.WebClient
$webClient.UseDefaultCredentials = $true
$webClient.Proxy.Credentials = $webClient.Credentials
$webClient.Headers.Add("user-agent", "PowerShell automated task")

$newsData = $webClient.DownloadData("https://news.webits.1c.ru/news/Updates/atom")
[xml]$news = ([System.Text.Encoding]::UTF8).GetString($newsData)
#[xml]$news = Get-Content -Encoding UTF8 -LiteralPath "$($env:TEMP)\updates.xml"

for($c1=0;$c1 -lt $news.feed.entry.Count;$c1++){
    #  
    $entry = $news.feed.entry[$c1]
    $ProductName    = ""
    $bFoundProduct  = $false
    $bFoundNewsType = $false
    for($c2=0;$c2 -lt $entry.category.Count;$c2++){
        #     
        $CategoryProducts | ForEach-Object {
            if($entry.category[$c2].term -eq $_){
                $ProductName = $entry.category[$c2].term
                $bFoundProduct = $true
            }
        }
        $CategoryNewsTypes | ForEach-Object {
            if($entry.category[$c2].term -eq $_){
                $bFoundNewsType = $true
            }
        }
    }

    if ($bFoundProduct -and $bFoundNewsType) {

           Write-Host ("  . : {0}, : {1}" -f ($entry.id, $entry.title))

        # ,       email?
        #    email    id   - $sendedEmailsPath.
        $bEmailWasSent = $false
        foreach ($sendedEmail in $sendedEmails) {
            if ( $sendedEmail.StartsWith($entry.id) ) {
                $bEmailWasSent = $true
                break
            }
        }

        #       email.
        if ($bEmailWasSent -eq $false){

            Write-Host "    ..."

            #  
            $Subject = $entry.title
            $Body = "<h1>  </h1>" + `
                "<p>" + `
                $entry.summary."#cdata-section" + `
                "</p>"

            Send-MailMessage `
                -From $From `
                -To $To `
                -Body $Body `
                -BodyAsHtml `
                -Credential $Credential `
                -Encoding $EncodingUTF8 `
                -SmtpServer $SMTPServer `
                -Subject $Subject `
                -Priority High `
                -UseSsl `
                -Port $SMTPPort `
                -Verbose
                
            #   ,        
            $LogString = $entry.id + ";" + $CurrentDate_String + ";"
            Add-Content -LiteralPath $sendedEmailsPath -Encoding UTF8 -Force -Value $LogString

        } else {

               Write-Host "      ."

        }

    }

}

      
      



. . , 2 . " ". (Win+R) "taskschd.msc



".





:





«  4  » ():





(« »):





powershell.exe . - -file



, «  ».





Un poco de ajuste, no me gustan las ventanas emergentes. Y cuando la tarea se ejecuta de acuerdo con el cronograma, cada 4 horas aparece la ventana de ejecución del script en toda la pantalla. Puede ejecutar código de Power-Shell a través de SilentCMD o CreateProcessHidden . Es cierto que el antivirus maldice lo último, pero no mucho.





Este método de verificación de noticias tiene una gran desventaja: requiere que esta computadora esté encendida constantemente. Por eso, en las próximas partes te diré cómo automatizar la lectura de noticias usando servicios de automatización y cómo descargo podcasts para mí.





Bueno, espero que la información haya sido útil.

Leo los comentarios con interés.





Intentaré publicar el resto de los capítulos en un futuro próximo.








All Articles