#!/usr/bin/python3 -u from dumperqueue import DumperQueue from allegro import Allegro from multiprocessing.pool import Pool import signal import json import datetime import time import io import sys import traceback queue = DumperQueue('dumper.sq3') allegro = Allegro() allegro.load_credentials('.credentials') allegro._perform_login() concurrency = 3 def today_date(): return datetime.datetime.now().strftime("%Y-%m-%d") def dump_transactions(transactions): with io.open("transactions.%s.txt" % today_date(), "a+", encoding='utf8') as file: for transaction in transactions: if is_valid_transaction(transaction): transaction['itemInfo']['itDescription'] = None file.write(json.dumps(transaction, ensure_ascii=False) + "\n") def is_valid_transaction(item):
only_auctions = queue.filter_auctions(ends) for event in journal: if event['changeType'] == 'end' and event['itemId'] in (only_auctions): queue.add_transaction(event['rowId'], event['itemId'], event['changeDate'], False) queue.commit() def dump_journal(journal): with open("journal.%s.txt" % today_date(), "a+") as journaldump: for event in journal: journaldump.write(json.dumps(event) + "\n") print('Currently at %s, gathered events: %d' % (datetime.datetime.fromtimestamp(event['changeDate']).strftime('%Y-%m-%d %H:%M:%S'), len(journal))) queue = DumperQueue('dumper.sq3') allegro = Allegro() allegro.load_credentials('.credentials') start = queue.get_status()['last_journal_rowid'] print("Starting from %d" % start) while True: journal = allegro.get_site_journal(start) if len(journal) > 0: mark_actions(journal) mark_auctions_wins(journal) dump_journal(journal) queue.set_status(last_journal_rowid=start, last_journal_timestamp=journal[-1]['changeDate']) start=journal[-1]['rowId'] if len(journal) < 100: