Skip to content

Commit 7d9559e

Browse files
committed
Fix some minor code style issues
1 parent 4abbc72 commit 7d9559e

9 files changed

Lines changed: 40 additions & 49 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CloudBot
22

3-
CloudBot is a simple, fast, extendable open-source Python IRC Bot!
3+
CloudBot is a simple, fast, expandable open-source Python IRC Bot!
44

55
## Getting CloudBot
66

plugins/geoip.py

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121

2222
def fetch_db():
23-
logger.info("fetch called")
2423
if os.path.exists(PATH):
2524
os.remove(PATH)
2625
r = requests.get(DB_URL, stream=True)
@@ -34,28 +33,23 @@ def update_db():
3433
"""
3534
Updates the DB.
3635
"""
37-
try:
38-
if os.path.isfile(PATH):
39-
# check if file is over 2 weeks old
40-
if time.time() - os.path.getmtime(PATH) > (14 * 24 * 60 * 60):
41-
# geoip is outdated, re-download
42-
fetch_db()
43-
return geoip2.database.Reader(PATH)
44-
else:
45-
try:
46-
return geoip2.database.Reader(PATH)
47-
except:
48-
# issue loading, geo
49-
fetch_db()
50-
return geoip2.database.Reader(PATH)
51-
else:
52-
# no geoip file
53-
print("calling fetch_db")
36+
if os.path.isfile(PATH):
37+
# check if file is over 2 weeks old
38+
if time.time() - os.path.getmtime(PATH) > (14 * 24 * 60 * 60):
39+
# geoip is outdated, re-download
5440
fetch_db()
55-
print("fetch_db finished")
5641
return geoip2.database.Reader(PATH)
57-
except Exception as e:
58-
print("GEOERROR" + e)
42+
else:
43+
try:
44+
return geoip2.database.Reader(PATH)
45+
except:
46+
# issue loading, geo
47+
fetch_db()
48+
return geoip2.database.Reader(PATH)
49+
else:
50+
# no geoip file
51+
fetch_db()
52+
return geoip2.database.Reader(PATH)
5953

6054

6155
def check_db(loop):

plugins/quote.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,12 @@ def quote(text, nick, chan, db, notice):
159159
notice(add_quote(db, chan, quoted_nick, nick, msg))
160160
return
161161
elif retrieve:
162-
select, num = retrieve.groups()
163-
by_chan = True if select.startswith('#') else False
162+
selected, num = retrieve.groups()
163+
by_chan = True if selected.startswith('#') else False
164164
if by_chan:
165-
return get_quote_by_chan(db, select, num)
165+
return get_quote_by_chan(db, selected, num)
166166
else:
167-
return get_quote_by_nick(db, select, num)
167+
return get_quote_by_nick(db, selected, num)
168168
elif retrieve_chan:
169169
chan, nick, num = retrieve_chan.groups()
170170
return get_quote_by_nick_chan(db, chan, nick, num)

plugins/rottentomatoes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
@hook.command('rottentomatoes', 'rt')
12-
def rottentomatoes(text, bot):
12+
def rotten_tomatoes(text, bot):
1313
"""rt <title> -- gets ratings for <title> from Rotten Tomatoes"""
1414
api_key = bot.config.get("api_keys", {}).get("rottentomatoes", None)
1515
if not api_key:

plugins/speedtest.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ def speedtest_url(match):
2222
upload = data.xpath('//div[@class="share-speed share-upload"]/p')[0].text_content().strip()
2323

2424
ping = data.xpath('//div[@class="share-data share-ping"]/p')[0].text_content().strip()
25-
stars = data.xpath('//div[contains(@class, "share-stars")]')[0].text_content().strip()
26-
2725
isp = data.xpath('//div[@class="share-data share-isp"]/p')[0].text_content().strip().title()
2826

2927
return "\x02{}\x02 - Download: \x02{}\x02, Upload: \x02{}\x02, Ping: \x02{}\x02".format(isp, download, upload, ping)

plugins/steam_user.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ def convert_id32(id_64):
2121
:type id_64: int
2222
:return: str
2323
"""
24-
out = []
25-
out.append("STEAM_0:")
24+
out = ["STEAM_0:"]
2625
final = id_64 - ID_BASE
2726
if final % 2 == 0:
2827
out.append("0:")

plugins/tvdb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def get_episodes_for_series(series_name, api_key):
3232
try:
3333
_request = requests.get(base_url + '%s/series/%s/all/en.xml' % (api_key, series_id))
3434
_request.raise_for_status()
35-
except (requests.exceptions.HTTPError, requests.exceptions.ConnectionError) as e:
35+
except (requests.exceptions.HTTPError, requests.exceptions.ConnectionError):
3636
res["error"] = "error contacting thetvdb.com"
3737
return res
3838

plugins/twitch.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,23 @@ def twitch_lookup(location):
7070
locsplit = location.split("/")
7171
if len(locsplit) > 1 and len(locsplit) == 3:
7272
channel = locsplit[0]
73-
type = locsplit[1] # should be b or c
74-
id = locsplit[2]
73+
_type = locsplit[1] # should be b or c
74+
_id = locsplit[2]
7575
else:
7676
channel = locsplit[0]
77-
type = None
78-
id = None
77+
_type = None
78+
_id = None
7979
fmt = "{}: {} playing {} ({})" # Title: nickname playing Game (x views)
80-
if type and id:
81-
if type == "b": # I haven't found an API to retrieve broadcast info
80+
if _type and _id:
81+
if _type == "b": # I haven't found an API to retrieve broadcast info
8282
soup = http.get_soup("http://twitch.tv/" + location)
8383
title = soup.find('span', {'class': 'real_title js-title'}).text
8484
playing = soup.find('a', {'class': 'game js-game'}).text
8585
views = soup.find('span', {'id': 'views-count'}).text + " view"
8686
views = views + "s" if not views[0:2] == "1 " else views
8787
return html.unescape(fmt.format(title, channel, playing, views))
88-
elif type == "c":
89-
data = http.get_json("https://api.twitch.tv/kraken/videos/" + type + id)
88+
elif _type == "c":
89+
data = http.get_json("https://api.twitch.tv/kraken/videos/" + _type + _id)
9090
title = data['title']
9191
playing = data['game']
9292
views = str(data['views']) + " view"

plugins/youtube.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
search_api_url = base_url + 'search?part=id&maxResults=1'
1818
playlist_api_url = base_url + 'playlists?part=snippet%2CcontentDetails%2Cstatus'
1919
video_url = "http://youtu.be/%s"
20-
err_noapi = "The YouTube API is off in the Google Developers Console."
20+
err_no_api = "The YouTube API is off in the Google Developers Console."
2121

2222

2323
def get_video_description(video_id, key):
2424
json = requests.get(api_url.format(video_id, key)).json()
2525

2626
if json.get('error'):
2727
if json['error']['code'] == 403:
28-
return err_noapi
28+
return err_no_api
2929
else:
3030
return
3131

@@ -41,14 +41,14 @@ def get_video_description(video_id, key):
4141

4242
length = isodate.parse_duration(content_details['duration'])
4343
out += ' - length \x02{}\x02'.format(timeformat.format_time(int(length.total_seconds()), simple=True))
44-
totalvotes = float(statistics['likeCount']) + float(statistics['dislikeCount'])
44+
total_votes = float(statistics['likeCount']) + float(statistics['dislikeCount'])
4545

46-
if totalvotes != 0:
46+
if total_votes != 0:
4747
# format
4848
likes = pluralize(int(statistics['likeCount']), "like")
4949
dislikes = pluralize(int(statistics['dislikeCount']), "dislike")
5050

51-
percent = 100 * float(statistics['likeCount']) / totalvotes
51+
percent = 100 * float(statistics['likeCount']) / total_votes
5252
out += ' - {}, {} (\x02{:.1f}\x02%)'.format(likes,
5353
dislikes, percent)
5454

@@ -75,7 +75,7 @@ def load_key(bot):
7575

7676

7777
@hook.regex(youtube_re)
78-
def youtube_url(match, bot):
78+
def youtube_url(match):
7979
return get_video_description(match.group(1), dev_key)
8080

8181

@@ -89,7 +89,7 @@ def youtube(text):
8989

9090
if json.get('error'):
9191
if json['error']['code'] == 403:
92-
return err_noapi
92+
return err_no_api
9393
else:
9494
return 'Error performing search.'
9595

@@ -111,7 +111,7 @@ def youtime(text):
111111

112112
if json.get('error'):
113113
if json['error']['code'] == 403:
114-
return err_noapi
114+
return err_no_api
115115
else:
116116
return 'Error performing search.'
117117

@@ -154,7 +154,7 @@ def ytplaylist_url(match):
154154

155155
if json.get('error'):
156156
if json['error']['code'] == 403:
157-
return err_noapi
157+
return err_no_api
158158
else:
159159
return 'Error looking up playlist.'
160160

0 commit comments

Comments
 (0)