gangstanthony

reddit powershell questions.ps1

Apr 28th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # get last powershell questions
  2.  
  3. # http://meta.stackexchange.com/questions/43160/how-to-get-an-rss-feed-of-latest-questions
  4.  
  5. $file = 'C:\redditposh.csv'
  6. $errorlog = 'C:\redditposherrors.txt'
  7.  
  8. if (!(Test-Path $file)) {
  9.     'title,link,time' | Out-File $file
  10. }
  11. $last = ipcsv $file
  12.  
  13. $smtpserver = 'smtp.domain.com'
  14.  
  15. $reddit = ([xml](iwr reddit.com/r/powershell/new/.rss).content).feed.entry[0] | % {
  16.     [pscustomobject]@{
  17.         Title = $_.title
  18.         Link = $_.link.href
  19.         Time = Get-Date -f s
  20.     }
  21. }
  22. if ($reddit.link -and @($last | ? link -eq $reddit.Link).Count -eq 0) {
  23.     $reddit | epcsv $file -NoTypeInformation -Append
  24.  
  25.     $body = $reddit.title, $reddit.link -join "`n"
  26.  
  27.     Send-MailMessage -To $to -From $from -Subject 'reddit' -Body $body -SmtpServer $smtpserver
  28.  
  29.     if ($error[0].exception -notmatch 'module') {
  30.         Get-Date >> $errorlog
  31.         $error[0] >> $errorlog
  32.     }
  33. }
  34.  
  35. $poshorg = (iwr 'http://powershell.org/wp/forums/forum/windows-powershell-qa/').ParsedHtml.getElementById('bbp-forum-0').InnerHtml -split "`n" | select -Skip 9 -f 1 | % {
  36.     [pscustomobject]@{
  37.         Title = (Get-Culture).TextInfo.ToTitleCase(($_ -replace '.*title=(.*) ?href=.*', '$1').trim('" '))
  38.         Link = $_ -replace '.*href="(.*)".*', '$1'
  39.         Time = Get-Date -f s
  40.     }
  41. }
  42. if ($poshorg.link -and @($last | ? link -eq $poshorg.Link).Count -eq 0) {
  43.     $poshorg | epcsv $file -NoTypeInformation -Append
  44.    
  45.     $body = $poshorg.title, $poshorg.link -join "`n"
  46.  
  47.     Send-MailMessage -To $to -From $from -Subject 'poshorg' -Body $body -SmtpServer $smtpserver
  48.  
  49.     if ($error[0].exception -notmatch 'module') {
  50.         Get-Date >> $errorlog
  51.         $error[0] >> $errorlog
  52.     }
  53. }
  54.  
  55. $spiceworks = (iwr 'https://community.spiceworks.com/programming/topics?sort=recent').Links.href | ? {$_ -match 'community\.spiceworks\.com\/topic\/'} | select -f 1 | % {
  56.     [pscustomobject]@{
  57.         Title = (Get-Culture).TextInfo.ToTitleCase((Split-Path $_ -Leaf).Replace('-', ' ') -replace '^\d+ ')
  58.         Link = $_
  59.         Time = Get-Date -f s
  60.     }
  61. }
  62. if ($spiceworks.link -and @($last | ? link -eq $spiceworks.Link).Count -eq 0) {
  63.     $spiceworks | epcsv $file -NoTypeInformation -Append
  64.    
  65.     $body = $spiceworks.title, $spiceworks.link -join "`n"
  66.  
  67.     Send-MailMessage -To $To -From $from -Subject 'spiceworks' -Body $body -SmtpServer $smtpserver
  68.  
  69.     if ($error[0].exception -notmatch 'module') {
  70.         Get-Date >> $errorlog
  71.         $error[0] >> $errorlog
  72.     }
  73. }
  74.  
  75. $poshcom = (iwr http://powershell.com/cs/forums/230.aspx).links | ? {$_.href -match '^\/cs\/forums\/t\/'} | select href, outertext -f 1 | % {
  76.     [pscustomobject]@{
  77.         Title = (Get-Culture).TextInfo.ToTitleCase($_.outertext)
  78.         Link = -join ('http://powershell.com', $_.href)
  79.         Time = Get-Date -f s
  80.     }
  81. }
  82. if ($poshcom -and @($last | ? link -eq $poshcom.Link).Count -eq 0) {
  83.     $poshcom | epcsv $file -NoTypeInformation -Append
  84.    
  85.     $body = $poshcom.title, $poshcom.link -join ' '
  86.  
  87.     Send-MailMessage -To $To -From $from -Subject 'poshcom' -Body $body -SmtpServer $smtpserver
  88.  
  89.     if ($error[0].exception -notmatch 'module') {
  90.         Get-Date >> $errorlog
  91.         $error[0] >> $errorlog
  92.     }
  93. }
  94.  
  95. <# updates too often
  96. $so = ([xml](iwr http://stackoverflow.com/feeds/tag/powershell)).feed.entry[0] | % {
  97.     [pscustomobject]@{
  98.         Title = $_.title.'#text'
  99.         Link = $_.link.href
  100.         Time = Get-Date -f s
  101.     }
  102. }
  103. if ($so.link -and @($last | ? link -eq $so.Link).Count -eq 0) {
  104.     $so | epcsv $file -NoTypeInformation -Append
  105.  
  106.     $body = $so.title, $so.link -join "`n"
  107.  
  108.     Send-MailMessage -To $To -From $from -Subject 'so' -Body $body -SmtpServer $smtpserver
  109.  
  110.     if ($error[0].exception -notmatch 'module') {
  111.         Get-Date >> $errorlog
  112.         $error[0] >> $errorlog
  113.     }
  114. }#>
Add Comment
Please, Sign In to add comment