Tirez le meilleur parti des actualités sur Internet
Inspiré de l'article Pourquoi j'utilise toujours RSS
J'utilise moi-même très activement le format des nouvelles, que j'aimerais partager avec la communauté.
Il y aura des captures d'écran et peut-être une petite explication redondante.
Il y aura les parties suivantes:
Partie 1 :
Quelles informations est-ce que je consomme généralement à travers les actualités;
Programmes de lecture (agrégateurs rss) - ce que j'utilise personnellement;
Les formats RSS et Atom, comment ils peuvent être traités par des programmes sur l'ordinateur local;
Partie 2 :
Automators (zapier, ifttt);
3:
- .
1
, , , , ( , !). , RSS. . RSS. , RSS! , , RSS .
. , 1.
(rss-)
, . , - , Apple .
- , .. - « » . .
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 peu de réglage - je n'aime pas les pop-ups. Et lorsque la tâche est exécutée selon le calendrier, toutes les 4 heures, la fenêtre d'exécution du script apparaît sur tout l'écran. Vous pouvez exécuter du code Power Shell via SilentCMD ou CreateProcessHidden . Certes, l'antivirus ne jure que sur ce dernier, mais pas beaucoup.
Cette méthode de vérification des actualités présente un tel inconvénient: elle nécessite que cet ordinateur soit constamment allumé. Par conséquent, dans les prochaines parties, je vous expliquerai comment automatiser la lecture des actualités à l'aide de services d'automatisation et comment je télécharge des podcasts pour moi-même.
Eh bien, j'espère que les informations ont été utiles.
J'ai lu les commentaires avec intérêt.
J'essaierai de publier le reste des chapitres dans un proche avenir.