Dad.post_init()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 7

Duplication

Lines 7
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 7
loc 7
rs 9.4285
1
import urllib2
2
import json
3
from event import Event
4
try:
5
  from basemodule import BaseModule
6
except ImportError:
7
  from modules.basemodule import BaseModule
8 View Code Duplication
class Dad(BaseModule):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
9
  def post_init(self):
10
    d_event = Event("__.dad__")
11
12
    d_event.define(msg_definition="^\.dad")
13
    d_event.subscribe(self)
14
15
    self.bot.register_event(d_event, self)
16
17
  def handle(self, event):
18
    try:
19
      url = "https://icanhazdadjoke.com/"
20
      req = urllib2.Request(url, headers={'Accept' : "application/json", 'User-Agent' : "Magic Browser"})
21
      resp = urllib2.urlopen(req)
22
      j = json.loads(resp.read())
23
      self.say(event.channel, j['joke'])
24
    except:
25
      pass
26