40 return False # not throttled |
40 return False # not throttled |
41 |
41 |
42 def throttle (address): |
42 def throttle (address): |
43 tt = datetime.utcnow() + timedelta (0, 30) |
43 tt = datetime.utcnow() + timedelta (0, 30) |
44 |
44 |
45 try: |
45 if address in g_throttle: |
46 # attempt to just update the item |
|
47 g_throttle[g_throttle.index (address)][1] = tt |
46 g_throttle[g_throttle.index (address)][1] = tt |
48 except ValueError: |
47 else: |
49 # not in list |
|
50 g_throttle.append ([address, tt]) |
48 g_throttle.append ([address, tt]) |
51 |
49 |
52 Irc.broadcast ('Throttling %s for 30 seconds' % address) |
50 Irc.broadcast ('Throttling %s for 30 seconds' % address) |
53 |
51 |
54 def handle_rest_http (data, address): |
52 def handle_rest_http (data, address): |
102 |
100 |
103 try: |
101 try: |
104 with open ('rejected_json.txt', 'w') as fp: |
102 with open ('rejected_json.txt', 'w') as fp: |
105 fp.write (jsonstring) |
103 fp.write (jsonstring) |
106 Irc.broadcast ('bad json written to rejected_json.txt') |
104 Irc.broadcast ('bad json written to rejected_json.txt') |
107 except: |
105 except Exception as e: |
108 Irc.broadcast ('failed to log json') |
106 Irc.broadcast ('failed to log json because %s' % e) |
109 pass |
107 pass |
110 |
108 |
111 throttle (address) |
109 throttle (address) |
112 return |
110 return |
113 |
111 |