Last active
September 9, 2019 20:08
-
-
Save geotheory/d2d789f8af4bc7d56474bee8521f1477 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Report on snipes | |
import urllib.request, json | |
from time import sleep | |
from re import sub | |
from tabulate import tabulate | |
with urllib.request.urlopen("http://localhost:3647/snipes") as url: | |
snipes_arr = json.loads(url.read().decode()) | |
snipes_arr.sort(key=lambda x: x['snipeTime']) | |
snipes = {} | |
for s in snipes_arr: | |
id = s['auctionId'] | |
snipes[id] = s | |
auctions = {} | |
for s in snipes_arr: | |
id = s['auctionId'] | |
print(id) | |
with urllib.request.urlopen("http://localhost:3647/auction/" + id) as url: | |
auctions[id] = json.loads(url.read().decode()) | |
snipes[id]['auctionDetail'] = auctions[id] | |
sleep(1) | |
tbl = [['AUCTION ID', 'SNIPE TIME', 'SNIPE BID', 'BIDS', 'TOP BID', 'SHIPPING', 'TITLE', 'LINK']] | |
for s in snipes_arr: | |
id = s['auctionId'] | |
a = auctions[id] | |
tbl.append([id, sub('T', ' ', s['snipeTime'][:16]), s['bid'], a['bidCount'], a['currentBid'], a['shippingCost'], a['title'], 'https://www.ebay.co.uk/itm/' + id]) | |
rpt = tabulate(tbl) | |
with open('snipes.txt', 'w') as f: | |
for row in rpt.split('\n'): | |
f.write("%s\n" % row) | |
with open('snipes.json', 'w') as f: | |
json.dump(snipes, f) | |
print(rpt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment