-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathebayReader.ps1
125 lines (105 loc) · 4.14 KB
/
ebayReader.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# Powershell-Script to generate "http://localhost:8800/ebay.html"
# List default product keywords here:
$searchList = @(
'Fallblattanzeige',
'Flipdot'
)
if($Request -and $Request.Query['search']){
$searchList = @(
$Request.Query['search']
)
}
$pageTitle = "Ebay-Watch"
$Ebay = "https://www.ebay.de"
.\common.ps1
$ReportData = [System.Collections.ArrayList]@()
foreach($product in $searchList) {
$searchLink="$Ebay/dsc/i.html?_ipg=200&_nkw=$product&_rss=1&rt=nc"
$webResult = Invoke-RestMethod -Uri $searchLink -UserAgent $agent -Headers $global:headers -ErrorAction Stop
if($webResult.count -eq 0) { break }
foreach($item in $webResult)
{
if($item.title -is [array]){
$title = $item.title[0]
} elseif ($item.title.innertext) {
$title = $item.title.innertext
} else {
$title = $item.title
}
if($item.published){
$pubDate = Get-Date $item.published
} elseif ($item.date) {
$pubDate = $item.date -replace "T"," "
$pubDate = Get-Date ($pubDate.substring(0,19))
} else {
$pubDate = $item.pubdate -replace " MST"
$pubDate = Get-Date $pubDate
}
$Description = $item.description."#cdata-section"
$ENDDATE_REGEX = [regex] ".*(End Date: <span>+)(?'EndDate'[^<]+).*"
if($description -match $ENDDATE_REGEX) {
$EndDate = $Matches.EndDate
$d = $EndDate -split ' '
$realDate = "{0}{1}{2} {3}" -f $d[0],$d[1],(Get-Date).Year,$d[2]
$de = New-Object system.globalization.cultureinfo(“de-DE”)
$CloseDate = [datetime]::ParseExact($realDate,'dd.MMM.yyyy HH:mm',$de)
if((Get-Date).Month -gt $CloseDate.Month){
$CloseDate.AddYears(1)
}
}
$IMAGE_REGEX = [regex] ".*(src=`"+)(?'ImageSrc'[^`"]+).*"
if($description -match $IMAGE_REGEX) {
$imgLink = $Matches.ImageSrc
}
$cat = $item.Category.'#cdata-section'
$BidCount = $item.BidCount."#text"
$cp = $item.CurrentPrice."#text"
if ($cp) {
$CurrentPrice = [int]$cp/100
} else {
$CurrentPrice = "?"
}
$bn = $item.BuyItNowPrice."#text"
if($bn -gt 0){
$BuyItNowPrice = [int]$bn/100
} else {
$BuyItNowPrice = ""
}
if($item.link.href){
$link = $item.link.href
} elseif($item.link.innertext){
$link = $item.link.innertext
} else {
$link = $item.link
}
#$bytes = [System.Text.Encoding]::Unicode.GetBytes($link)
#$jsLink =[Convert]::ToBase64String($bytes)
$moob="<a data=""$link"" href='javascript:markDBEntry(""$link"",""$title"",""$cat"");'>Marker</a>"
$row = New-Object PSObject -Property @{
Channel = $chanTitle
Article = "<a href='$link' onpointerenter=""showImage('$imgLink')"" onpointerleave=""hideImage()"" target='_blank'>$title</a>"
Category = $cat
Published = $pubDate
Ends = $CloseDate
Bids = $BidCount
Price = $CurrentPrice
FixPrice = $BuyItNowPrice
Action = $moob
}
$ReportData.Add($row) > $null;
}
}
# prepare html-table
$timestamp = Get-Date -Format "HH:mm"
$ReportHeader ="<div class='header'><h1>$pageTitle</h1><div class='timestamp'>$timestamp</div><form>
<input type='text' name='search' value='$($searchList[0])'><input type='hidden' name='refresh' value='1'><input type='submit' value='Update'></form></div>"
$ReportFooter = @("<img id='floatingimg' onerror=""javascript: alert('failure')""></img>
<script src='res/tsorter.min.js'></script>
<script src='res/moment.js'></script>
<script src='res/ebayTable.js'></script>")
# switch to script-folder
Push-Location $PSScriptRoot
# Create a sorted HTML table
$page = ($ReportData | Sort-Object {$_.EndDate -as [DateTime]} | Select-Object Published, Ends, Article, FixPrice, Price, Bids, Category | ConvertTo-Html -title $pageTitle -PreContent "$ReportHeader" -PostContent "$ReportFooter")
$html = global:SetPageHeader $page
global:writePage $html "ebay.html"