Making the most of online news, part 1

Get the most out of the news on the Internet





Inspired by the article Why I Still Use RSS





I myself am very actively using the news format, which I would like to share with the community.





There will be screenshots and maybe a little redundant explanation.





There will be the following parts:





  1. Part 1 :





  • What information do I generally consume through news;





  • Reading programs (rss-aggregators) - what I personally use;





  • RSS and Atom formats, how they can be processed by programs on the local computer;





  1. 2:





  • (zapier, ifttt);





  1. 3:





  • - .





1

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





. , 1.





, , (, ) . , , .





(rss-)

, . , - , Apple .





- , .. - «  » . .





RSS Owl:





RSS Owl
RSS Owl

JetBrains: OMEA Reader:





JetBrains OMEA Reader
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



, «  ».





A bit of tuning - I don't like pop-ups. And when the task is executed on schedule, the script execution window pops up on the whole screen every 4 hours. You can run power-shell code through SilentCMD or CreateProcessHidden . True, the antivirus swears at the latter, but not much.





This method of checking news has such a disadvantage - it requires that this computer be constantly turned on. Therefore, in the next parts I will tell you how to automate reading news using automation services and how I download podcasts for myself.





Well, I hope the information was helpful.

I read the comments with interest.





I will try to post the rest of the chapters in the near future.








All Articles