|
9 | 9 | class DelayedCore(fut.Core): |
10 | 10 | def __init__(self, email, passwd, secret_answer, platform='pc', code=None, emulate=None, debug=False, cookies=cookies_file): |
11 | 11 | # Set initial delay |
12 | | - self.delayInterval = 2 |
| 12 | + self.delayInterval = 4 |
13 | 13 | self.delay = time() |
| 14 | + self.cardInfoCache = {} |
14 | 15 | super(DelayedCore, self).__init__(email, passwd, secret_answer, platform, code, emulate, debug, cookies) |
15 | 16 |
|
16 | 17 | def setRequestDelay(self, delay): |
@@ -41,15 +42,28 @@ def __request__(self, method, url, *args, **kwargs): |
41 | 42 | return super(DelayedCore, self).__request__(method, url, *args, **kwargs) |
42 | 43 |
|
43 | 44 | def bid(self, trade_id, bid): |
44 | | - # no delay between getting trade info and bidding |
| 45 | + # no delay between getting trade info and bidding, but still want a delay before both |
| 46 | + if self.delay > time(): |
| 47 | + sleep(self.delay - time()) |
45 | 48 | delayInterval = self.delayInterval |
46 | 49 | self.delayInterval = 0 |
47 | 50 | try: |
48 | 51 | result = super(DelayedCore, self).bid(trade_id, bid) |
49 | 52 | except fut.exceptions.PermissionDenied as e: |
50 | 53 | if e.code == '461': |
51 | 54 | result = False |
52 | | - raise |
53 | | - self.delayInterval = delayInterval |
54 | | - self.delay = time() + (self.delayInterval * random.uniform(0.75, 1.25)) |
| 55 | + else: |
| 56 | + raise |
| 57 | + finally: |
| 58 | + self.delayInterval = delayInterval |
| 59 | + self.delay = time() + (self.delayInterval * random.uniform(0.75, 1.25)) |
| 60 | + return result |
| 61 | + |
| 62 | + def cardInfo(self, resource_id): |
| 63 | + """Returns card info.""" |
| 64 | + if resource_id in self.cardInfoCache: |
| 65 | + result = self.cardInfoCache[resource_id] |
| 66 | + else: |
| 67 | + result = super(DelayedCore, self).cardInfo(resource_id) |
| 68 | + self.cardInfoCache[resource_id] = result |
55 | 69 | return result |
0 commit comments