HarvEX eBay Script Examples & Templates Collection

This chapter presents a set of script examples & templates - ready for copy and paste. 

Some of this examples are preloaded in HarvEX after the installation from *.hxpy files in the HarvEX program directory.

Note: If you edit the preloaded example macros or newly added macros, they are not automatically stored as disk files but only stored in the HarvEX main internal database. You may write them to disk by right-click/Save to file from inside the macro list.

How to Copy & Paste and Run macro stuff:
  • Mark the specific macro text
  • Press Ctrl-C (=copy)
  • Place cursor to macro script editor in HarvEX
  • Press Ctrl-V (=paste)
  • Optionally press button "Save-As"
  • Press button "Execute" or [F5] or [Ctrl-Return] to run

Example Index

Examples

Hello World
[ hello_world ]

# Welcome to HarvEX Automation Macros !
print "Hello World !"
print "Bid Manager has", bm.GetCount(), "Items"
MessageBox("Welcome to HarvEX Macro Processor !")

Bulk Sniping
[ bulk_sniping ]

# Bulk-snipe selected bid manager items with a common bid value 2.01 !

for item in bm.GetSelectedItems():
  b = bm.GetItem(item)
  b.mybid = 2.01
  b.set_snipe()

[ bulk_sniping_gui_and_se ]

items = bm.GetSelectedItems()
titles = [bm.GetItem(item).title for item in items]
print titles
value=util.GetSimpleInput("N=%s: %s"%(len(items),str(items)),"1.00")
if not value: exit()
value=util.Str2Money(value)
for item in items:
  b = bm.GetItem(item)
  b.mybid = value
  b.set_snipe(se=1)     # snipe also SE server based
MessageBox("%s set for %s items: %s" % (value, len(items), titles) )

Custom filter for search results
[ filter_search ]

filter search macro

# Example: filter search results
# keep only auctions with 1..4 bids on

intab = searchpage.GetMatrix()
outtab = [line for line in intab
if 0 < line.nbid < 5 ]
searchpage.SetMatrix( outtab )
searchpage.Show()

Notes:

modified example with case insensitve search in the title:

outtab = [line for line in matrix
 if not re.search('(?i)laptops?|notebooks?', line.title)]

regex notes: (?i) : case insensitive search ; ..s? : character optionally present;

feed output to scan page instead of search-page:  scanpage.SetMatrix( outtab )

Bulk extract tabular data from eBay 'Sold Item' notification emails out of MS Outlook
[ scan_emails_sold ]

macro: scan emails for sold item notifications

(copying: click into the script + press Ctrl-A + press Ctrl-C ; in Macro Processor click "New" and Paste the macro )

# Scan data from eBay 'Sold Item' notification emails out of MS Outlook (MAPI).
# See other examples in the macro help page : POP3 scan, auto mailing, order tracking, ... 

outlookfolder = "inbox"
#outlookfolder = "inbox/ebaynew"       # this way for subfolders

subjectcontains = "(?i)Item Purchase|Sold Item|Item Sold|End of|Ende der|Verkaufter Artikel"
columns = '$item;$title;$price;$shipping;$buyer_email;$buyer_ID;$name;$street;$city;$end'

pa_email='(?:Buyer|Purchaser|Buyer E-mail|Käufer|E-Mail-Adresse der Käufers):.*?([\w.!+-]+@[\w.+-]+)'
pa_all = [
    '(\d{8,11})', # extractor pattern for: item no.
    '(?:Item name|Artikelbezeichnung):(.*)',
    '(?:price|Artikelpreis|-Preis):(.*)', 
    '(?i)(?:handling|Versand|packaging):(.*)', 
    pa_email,
    '\s\s(?:Buyer|Buyer User ID|Käufer|Mitgliedsname|Mitgliedsname des Käufers):([^:\r\n]*)',
    '(?s)(?:Name:.*)*(?:Name):([^\r\n]*)',
    '(?s)(?:(?:Street|Straße):.*)*(?:Street|Straße):([^\r\n]*)',
    '(?s)(?:(?:City|Ort):.*)*(?:City|Ort):([^\r\n]*)',
    '(?:End date|Angebotsende):(.*)', 
]
l = util.ScanOutlook( folder=outlookfolder, filter=subjectcontains, pattern=pa_all, errorlevel=0 )
scanpage.SetMatrix( l, headers=columns ) # [HX+]
scanpage.Show()

An extended version of that script calculates the price+shipping total to an extra column:

# Scan data from eBay 'Sold Item' notification emails out of MS Outlook (MAPI).
# and calculate price+shipping total to an extra columns

outlookfolder = "inbox"
outlookfolder = "inbox/ebaynew"       # this style for subfolders

subjectcontains = "(?i)Item Purchase|Sold Item|Item Sold|End of|Ende der|Verkaufter Artikel"
columns = '$item;$title;$price;$shipping;$buyer_email;$buyer_ID;$name;$street;$city;$end'
columns2= '$item;$title;$price;$shipping;$total;$buyer_email;$buyer_ID;$name;$street;$city;$end'   # $total added

pa_email='(?:Buyer|Purchaser|Buyer E-mail|Käufer|E-Mail-Adresse der Käufers):.*?([\w.!+-]+@[\w.+-]+)'
pa_all = [
    '(\d{8,11})', # extractor pattern for: item no.
    '(?:Item name|Artikelbezeichnung):(.*)',
    '(?:price|Artikelpreis|-Preis):(.*)', 
    '(?i)(?:handling|Versand|packaging):(.*)', 
    pa_email,
    '\s\s(?:Buyer|Buyer User ID|Käufer|Mitgliedsname|Mitgliedsname des Käufers):([^:\r\n]*)',
    '(?s)(?:Name:.*)*(?:Name):([^\r\n]*)',
    '(?s)(?:(?:Street|Straße):.*)*(?:Street|Straße):([^\r\n]*)',
    '(?s)(?:(?:City|Ort):.*)*(?:City|Ort):([^\r\n]*)',
    '(?:End date|Angebotsende):(.*)', 
]
l = util.ScanOutlook( folder=outlookfolder, filter=subjectcontains, pattern=pa_all, errorlevel=0 )

#calculate and insert $total=$price+$shipping
ll= []
for line in l:
    c = util.NamedList( line,columns )
    price,shipping = map( util.ExtractMoney , (c.price,c.shipping) )
    c.insert(4, util.Money2Str(price+shipping) )   # insert total
    ll.append(c)

scanpage.SetMatrix( ll, headers=columns2 ) # [HX+]
scanpage.Show()

 

A complete Bulk Congratulations Mailer reacting to eBay 'Sold Item' notification emails ( MS Outlook )
[ bulk_congratulations_mailer ]

[ bulk_congratulations_mailer ]

You can evolve & simulate this macro savely when having "send_or_prepare=0" : The generated emails are sent to the "Drafts" folder of MS Outlook. Only after setting send_or_prepare=1, the emails are going directly to the "Outbox".

(copying: click into the script + press Ctrl-A + press Ctrl-C ; in Macro Processor click "New" and Paste the macro )

# Scan data from eBay 'Sold Item' notification emails (MS Outlook).
# and send out you congratulation emails and optionally move the processed mails to a done folder
# (extended version of [ scan_emails_sold ] )

MessageBox('really process mails?','Congratulations Mailer',1) == 1  or exit()

##outlookfolder = "inbox"
outlookfolder = "inbox/ebaynew"       # get the eBay notifications mail from here
done_folder = None                    #"inbox/ebaynew/done"    # set to None if you don't want to move
send_or_prepare = 0                   # 0 = prepare in "Drafts" folder; 1 = send out immediately

subjectcontains = "(?i)Item Purchase|Sold Item|Item Sold|End of|Ende der|Verkaufter Artikel"
columns = '$item;$title;$price;$shipping;$buyer_email;$buyer_ID;$name;$street;$city;$end'
columns2= '$item;$title;$price;$shipping;$total;$buyer_email;$buyer_ID;$name;$street;$city;$end'   # $total added

pa_email='(?:Buyer|Purchaser|Buyer E-mail|Käufer|E-Mail-Adresse der Käufers):.*?([\w.!+-]+@[\w.+-]+)'
pa_all = [
    '(\d{8,11})', # extractor pattern for: item no.
    '(?:Item name|Artikelbezeichnung):(.*)',
    '(?:price|Artikelpreis|-Preis):(.*)', 
    '(?i)(?:handling|Versand|packaging):(.*)', 
    pa_email,
    '\s\s(?:Buyer|Buyer User ID|Käufer|Mitgliedsname|Mitgliedsname des Käufers):([^:\r\n]*)',
    '(?s)(?:Name:.*)*(?:Name):([^\r\n]*)',
    '(?s)(?:(?:Street|Straße):.*)*(?:Street|Straße):([^\r\n]*)',
    '(?s)(?:(?:City|Ort):.*)*(?:City|Ort):([^\r\n]*)',
    '(?:End date|Angebotsende):(.*)', 
]
l = util.ScanOutlook( folder=outlookfolder, filter=subjectcontains, pattern=pa_all, errorlevel=0 , returnitems=1 )

# calculate $total=$price+$shipping
# and send the mailing
text="""\
Congratulations %s !

You have won our eBay item %s/%s.
The price (%s) + shipping (%s) total is : %s
After we receive your payment through PayPal we will send out your item immediately.

Regards
"""

done_folder = done_folder and util.GetOutlookFolder(done_folder)
ll= []
for mailitem, line in l:
    c = util.NamedList( line,columns )
    price,shipping = map( util.ExtractMoney , (c.price,c.shipping) )
    c.insert(4, util.ExtractCurrency(c.price) + ' ' + util.Money2Str(price+shipping) )   # insert total
    c.set_headers( columns2 )
    ll.append(c)
    util.CreateOutlookMail(toaddr=c.buyer_email,
                           subject="Congratulation! Your eBay Purchase %s/%s" % (c.item,c.title), 
                           text = text % (c.name,c.item,c.title,c.price,c.shipping,c.total),
                           send=send_or_prepare )
    if done_folder: mailitem.Move( done_folder )

scanpage.SetMatrix( ll, headers=columns2 ) # [HX+]
scanpage.Show()

 

Render some bid manager item info into table + file
[ render_bm_info_to_file ]

render_bm_info_to_file macro

FILE = open("C:/MYOUTFILE.txt","w")
print >>FILE, "time:", time.asctime()
l=[]
for b in bm.Iter():
  columns = [b.item, b.currentbid, b.title]
  print >>FILE, '\t'.join(map(str, columns))   #\t = TAB spaced columns! 
  l.append(columns)
FILE.close()
scanpage.SetMatrix(l, "$item;$currentbid;$title")
scanpage.Show()

 

Simple column statistics on search results
[ simple_stat ]

[ simple_stat ] macro

# Example: quick statistics over bids in the search results.
# counts only auctions with at least 1 real bid

matrix = searchpage.GetMatrix()
stat = matrix.ColumnStat('bid')
print stat
print "bid : Count=%d Average=%.2f Variance=%.2f" % (stat.count, stat.avg, stat.var)

  
Manual statistics on search results with more control
[ special_stat ]

# Example: manual statistics over content in the Search Window.
# Counts auctions where at least one real bid on

sum_count = 0
sum_nbid = 0
sum_bid = 0.0
for line in searchpage.GetLines():
    if line.nbid > 0:
        sum_count += 1
        sum_bid += line.bid
        sum_nbid += line.nbid

if sum_count:
avg_bid = sum_bid / sum_count
else:
    avg_bid = 0.0

print sum_count,"Auctions with bid; ", sum_nbid, "bids total; average bid:%.2f" % avg_bid

  
Walk through the bid manager and manipulate bids
[ inc_flat_bids ]

# Example: navigate in the Bidmanager and manipulate bids
# by incrementing flat value bids (0.50ct round) by 0.03 

for b in bm.Iter():
    print b.item, b.mybid, b.currency, b.comment
    if b.is_active_snipe() and 0.00 == b.mybid % 0.50:
        MessageBox("incrementing %s %s (%s) !" % (b.item,b.title,b.mybid) )
        b.mybid += 0.03

 
Execute a combined multiple search for 3 categories
[ search_3_cat ]

# do a multiple search for 3 categories
# ( requires HarvEX+ )

q = AuctionQuery()
q.subjects = 'Dell Computer'
q.maxpages = 1
##q.completed = True
##q.searchurl = 'http://search.ebay.ca/search/search.dll?abc...'

categories=[
  '160',
  '12576',
  '20710',
]

for cat in categories:
    q.cat = cat
    SearchItems(q , adding=True, cached=SC_CACHEDORDOWNLOAD)

# result goes to the search page !

 

Bulk extract listing fees and data from eBay 'Listing Confirmed' notification emails out of MS Outlook
[ scan_listing_fees ]

scan listing fees macro

# Scan data out of eBay 'Listing Confirmed' notification emails from MS Outlook (MAPI).
# Edit for other languages

outlookfolder = "inbox/ebaynew" # this style for subfolders

subjectcontains = "(?i)listing confirmed|angebot bestätigt"
columns = '$scandate;$item;$date;$title;$quant;$duration;$xprice;$fees;$fee_raw;$resv1'

pa_email='(?:Buyer|Purchaser|Käufer|E-Mail-Adresse der Käufers):.*?([\w.+-]+@[\w.+-]+)' # email

pa_all = [
    '(\d{8,11})', # extractor pattern for: item no.
    '(?:Start date|Start):(.*)', 
    '(?:Item name|Artikelbezeichnung):(.*)',
    '(?:Quantity|Menge):(.*)', 
    '(?:Listing duration|Angebotsdauer):(.*)', 
    '(?i)(?:price|Startpreis|Sofort-Kaufen-Preis):(.*)', 
    '(?:Total fees.*?|Gesamtgebühr(?:en)?.*?):(.*)', 
    '(?:Total fees.*?|Gesamtgebühr(?:en)?.*?):[^\d]*(.*)', 
]
   
l = util.ScanOutlook(folder=outlookfolder, filter=subjectcontains, pattern=pa_all, errorlevel=0)

scandate = time.strftime("%d.%m.%Y")
l = [[scandate]+i for i in l]
scanpage.SetLines(l, headers=columns ) # [HX+]
scanpage.Show()

 

Raw scan bid + shipping total costs to a table (items from bid manager or from search page)
[ scan_shipping_raw ]

( a raw scan example! $ship and $total are now also valid pre-computed scan columns variables since v2.05/build166 )

l = []
##for b in searchpage.GetLines():
for b in bm.Iter():
  o = ScanItem(b.item, cached=SC_CACHEDORDOWNLOAD)
  if not o: continue
  ship = re.search("(?s)(?i)(?:Shipping and handling|Verpackung und Versand):.*?([\d,.]+)</b>", o.html)
  if ship:
    ship = ship.group(1)
    total = util.Money2Str(util.Str2Money(o.bid) + util.Str2Money(ship))
  else:
    ship="???"
    total=o.bid+" ?"
  ##print o.bid, ship, total, o.nbid, o.title
  l.append([b.item, o.bid, ship, total, o.nbid, o.currency, o.titlewords])
scanpage.SetMatrix(l, "$item;$bid;$ship;$total;$nbid;$currency;$titlewords" )
scanpage.Show()

  

Render MyBid + Shipping = MyTotal into the comment column (bid manager)
[ bm_mytotal_comment ]

bm_mytotal_comment macro

l=[]
for b in bm.Iter():
  o = ScanItem(b.item,cached=SC_CACHED)
  ##o = ScanItem(b.item,cached=SC_CACHEDORDOWNLOAD)
  if not o: continue
  if o.ship.startswith('?'):
    mytotal = '?'+str(b.mybid)
    currtotal = '?'+o.bid
  else:
    mytotal = b.mybid + util.Str2Money(o.ship)
    currtotal = util.Str2Money(o.bid) + util.Str2Money(o.ship)
  b.comment = util.xcomment('MTO', mytotal, b.comment)
bm.Show()

Note: util.xcomment auto-updates the 'MTO=...' tag in the bid manager comment,  if 'MTO=...' is already present in the comment.

 

Feed TurboLister with listings computed from the bid manager (or from anywhere)
[ turbolister_feed ]

[ turbolister_feed ] macro

# feeds bidmanager items to TurboLister 

templatecsv = "c:/turbolister_template.csv"
outcsv = "c:/turbolister_mylistings.csv"

items = bidmanager.GetSelectedItems()
if not items:  
    MessageBox("no items selected in bid manager", "TurboLister Feed", 16) # 16 = Error Box
    exit()      

if not util.isfile(templatecsv): 
    MessageBox(
        "Run TurboLister and select menu/File/Export to CSV;\n"
        "Export one or more template listings to %s" % templatecsv)

TL = util.ReadTurboListerCSV(templatecsv)
T = TL.copy(0)   # copy first listing of the template
print "Fields:", T.headers
print "Currency/Site:", T.Currency, T.Site   

TL.clear()          # cleanup listings list
for item in items:
    o = ScanItem(item,cached=SC_CACHED)         # SC_CACHEDORDOWNLOAD
    if not o: print item,"not in cache"; continue
    print o.title
    T['Title'] = o.title
    T['Description'] = o.text
    T['Category 1'] = "4291"
    T['PicURL'] = "http://www.yourdomain.com/images/picture1.pjg"
    #T['PicURL'] = util.GetItemPicture('1234567890' , url=1)
    T['Starting Price'] = util.Money2StrUS(util.Str2Money(o.bid) + 4.99)
    TL.add(T)     # add the entry to the TurboLister Import-Table

TL.write( outcsv )  # [HX+]

MessageBox(
    "%s Listing templates are written to %s.\n"
    "Now run TurboLister and select menu/File/Import from CSV" % (len(TL.lines),outcsv))


Interface for calling HarvEX+ from outside through file interface & polling
[ cmd_interface ]

#!init 777  # thus this macro is auto-run at HarvEX start
# to test: write "test()" into a new file "C:/tmp/hx-cmd-in.txt".

cmd_in = "C:/tmp/hx-cmd-in.txt"
cmd_out= "C:/tmp/hx-cmd-out.txt"
def test():
print "test"
return 4
def poll():
if util.isfile(cmd_in):
cmd = open(cmd_in).read()
util.remove(cmd_in)
ret = eval(cmd)
open(cmd_out, 'wb').write(repr(ret))

util.Schedule(poll, 1.0, id=177)
print "cmd_interface scheduled"
 

Play a sound everytime the current-bid value of an auction in bid manger changes
[ bid_change_sound ]

#!init 777
# toggle the process

dBids = {}

def Step_WatchForBidChange():
## print "step"
for b in bm.Iter():
if b.item in dBids and dBids[b.item].currentbid != b.currentbid:
print "bid change", b.item, b.currentbid
util.PlayFile('bidding.wav')
dBids[b.item] = b

util.PlayFile('alarm.wav')
print "BidChangeSound started"
util.Schedule(Step_WatchForBidChange, 3.0, id=100)

 

Top of page