Dapatkan hasil maksimal dari berita di Internet
Terinspirasi oleh artikel Why I Still Use RSS
Saya sendiri sangat aktif menggunakan format berita, yang ingin saya bagikan dengan komunitas.
Akan ada screenshot dan mungkin sedikit penjelasan yang berlebihan.
Akan ada bagian-bagian berikut ini:
Bagian 1 :
Informasi apa yang biasanya saya konsumsi melalui berita;
Membaca program (rss-aggregators) - apa yang saya gunakan secara pribadi;
RSS Atom, ;
2:
(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
, « ».
Sedikit penyetelan - Saya tidak suka pop-up. Dan ketika tugas dijalankan sesuai jadwal, setiap 4 jam jendela eksekusi skrip muncul di seluruh layar. Anda dapat menjalankan kode power-shell melalui SilentCMD atau CreateProcessHidden . Benar, antivirus bersumpah pada yang terakhir, tetapi tidak banyak.
Metode pengecekan berita ini memiliki kelemahan - metode ini mengharuskan komputer ini terus dihidupkan. Oleh karena itu, di bagian selanjutnya saya akan memberi tahu Anda cara mengotomatiskan membaca berita menggunakan layanan otomasi dan cara saya mengunduh podcast untuk diri saya sendiri.
Baiklah, semoga informasinya bermanfaat.
Saya membaca komentar dengan penuh minat.
Saya akan mencoba memposting bab lainnya dalam waktu dekat.