From 29a17f53e8536f6f67a8e59e1eba1dc986d78499 Mon Sep 17 00:00:00 2001 From: Ari Koivula Date: Fri, 28 Jun 2013 02:22:48 +0300 Subject: [PATCH] [modules] Remove unused imports and variables. Also fixes some formatting. --- bugzilla.py | 2 -- dice.py | 2 +- github.py | 11 +++++------ ip.py | 7 +++++-- isup.py | 3 +-- meetbot.py | 3 +-- radio.py | 3 +-- remind.py | 2 +- rss.py | 3 +-- tell.py | 2 -- tld.py | 1 - translate.py | 4 +--- version.py | 2 +- weather.py | 13 +++++-------- wiktionary.py | 2 +- youtube.py | 18 +++++++++--------- 16 files changed, 33 insertions(+), 45 deletions(-) diff --git a/bugzilla.py b/bugzilla.py index 5bb96dd050..bacdc7052e 100644 --- a/bugzilla.py +++ b/bugzilla.py @@ -10,8 +10,6 @@ import re from willie import web, tools from willie.module import rule -import urllib -import urllib2 def configure(config): diff --git a/dice.py b/dice.py index b09d17caf3..98cdca1ddf 100644 --- a/dice.py +++ b/dice.py @@ -30,7 +30,7 @@ def dice(bot, trigger): arr = arr.replace('-', ' - ').replace('+', ' + ').replace('/', ' / ') arr = arr.replace('*', ' * ').replace('(', ' ( ').replace(')', ' ) ') arr = arr.replace('^', ' ^ ').replace('()', '').split(' ') - full_string, calc_string = '', '' + full_string = '' for segment in arr: #check for dice diff --git a/github.py b/github.py index d2e1b63a33..ce16a9b6e8 100644 --- a/github.py +++ b/github.py @@ -9,7 +9,6 @@ from datetime import datetime from urllib2 import HTTPError import json -import re from willie import web from willie.module import commands @@ -38,20 +37,20 @@ def configure(config): @commands('makeissue', 'makebug') def issue(bot, trigger): """Create a GitHub issue, also known as a bug report. Syntax: .makeissue Title of the bug report""" - #check input + # check input if not trigger.group(2): return bot.say('Please title the issue') - #Is the Oauth token and repo available? + # Is the Oauth token and repo available? gitAPI = checkConfig(bot) if gitAPI == False: return bot.say('Git module not configured, make sure github.oauth_token and github.repo are defined') - #parse input + # parse input now = ' '.join(str(datetime.utcnow()).split(' ')).split('.')[0] + ' UTC' body = 'Submitted by: %s\nFrom channel: %s\nAt %s' % (trigger.nick, trigger.sender, now) data = {"title": trigger.group(2).encode('utf-8'), "body": body, "labels": ["IRC"]} - #submit + # submit try: raw = web.post('https://api.github.com/repos/' + gitAPI[1] + '/issues?access_token=' + gitAPI[0], json.dumps(data)) except HTTPError: @@ -68,7 +67,7 @@ def findIssue(bot, trigger): if not trigger.group(2): return bot.reply('What are you searching for?') - #Is the Oauth token and repo available? + # Is the Oauth token and repo available? gitAPI = checkConfig(bot) if gitAPI == False: return bot.say('Git module not configured, make sure github.oauth_token and github.repo are defined') diff --git a/ip.py b/ip.py index 1f329dd4c7..76d976d129 100644 --- a/ip.py +++ b/ip.py @@ -22,6 +22,7 @@ from willie.module import commands, example + def configure(config): """ @@ -33,6 +34,7 @@ def configure(config): config.add_section('ip') config.interactive_add('ip', 'GeoIP_db_path', 'Full path to the GeoIP database', None) + def _decompress(source, target, delete_after_decompression = True): """ Decompress a GZip file """ f_in = gzip.open(source, 'rb') @@ -43,6 +45,7 @@ def _decompress(source, target, delete_after_decompression = True): if delete_after_decompression: os.remove(source) + def _find_geoip_db(bot): """ Find the GeoIP database """ config = bot.config @@ -53,8 +56,8 @@ def _find_geoip_db(bot): else: bot.debug('ip', 'GeoIP path configured but DB not found in configured path', 'warning') if (os.path.isfile(os.path.join(bot.config.homedir, 'GeoLiteCity.dat')) and - os.path.isfile(os.path.join(bot.config.homedir, 'GeoIPASNum.dat'))): - return bot.config.homedir + os.path.isfile(os.path.join(bot.config.homedir, 'GeoIPASNum.dat'))): + return bot.config.homedir elif (os.path.isfile(os.path.join('/usr/share/GeoIP', 'GeoLiteCity.dat')) and os.path.isfile(os.path.join('/usr/share/GeoIP', 'GeoIPASNum.dat'))): return '/usr/share/GeoIP' diff --git a/isup.py b/isup.py index 9d5e74be33..eee4986d78 100644 --- a/isup.py +++ b/isup.py @@ -8,7 +8,6 @@ from willie import web from willie.module import commands -import re @commands('isup') @@ -26,7 +25,7 @@ def isup(bot, trigger): site = 'http://' + site try: response = web.get(site) - except Exception as e: + except Exception: bot.say(site + ' looks down from here.') return diff --git a/meetbot.py b/meetbot.py index 5ce73c31e0..852b166dcc 100644 --- a/meetbot.py +++ b/meetbot.py @@ -26,6 +26,7 @@ def configure(config): config.interactive_add('meetbot', 'meeting_log_path', "Path to meeting logs storage directory (should be an absolute path, accessible on a webserver)") config.interactive_add('meetbot', 'meeting_log_baseurl', "Base URL for the meeting logs directory (eg. http://example.com/logs)") +meetings_dict = Ddict(dict) # Saves metadata about currently running meetings """ meetings_dict is a 2D dict. @@ -39,8 +40,6 @@ def configure(config): Using channel as the meeting ID as there can't be more than one meeting in a channel at the same time. """ - -meetings_dict = Ddict(dict) # Saves metadata about currently running meetings meeting_log_path = '' # To be defined on meeting start as part of sanity checks, used by logging functions so we don't have to pass them bot meeting_log_baseurl = '' # To be defined on meeting start as part of sanity checks, used by logging functions so we don't have to pass them bot diff --git a/radio.py b/radio.py index 0939c69a72..195bf6222c 100644 --- a/radio.py +++ b/radio.py @@ -10,7 +10,6 @@ from xml.dom.minidom import parseString import willie.web as web from willie.module import commands -import xml.dom.minidom def configure(config): @@ -34,7 +33,7 @@ def getAPI(bot, trigger): #contact the 'heavyweight' XML API try: raw = web.get(radioURL % 'stats') - except Exception as e: + except Exception: bot.say('The radio is not responding to the stats request.') return 0 diff --git a/remind.py b/remind.py index 5cd2e1d82e..1bb7ec8b1e 100644 --- a/remind.py +++ b/remind.py @@ -13,7 +13,7 @@ from pytz import timezone, all_timezones_set import pytz import codecs -from datetime import tzinfo, timedelta, datetime +from datetime import datetime from willie.module import commands, example, NOLIMIT diff --git a/rss.py b/rss.py index 0afeac1778..64df30440b 100644 --- a/rss.py +++ b/rss.py @@ -10,14 +10,13 @@ from willie.module import commands, priority import feedparser import socket -import sys import time DEBUG = False socket.setdefaulttimeout(10) INTERVAL = 10 # seconds between checking for new updates STOP = False -#This is reset in setup(). +# This is reset in setup(). SUB = ('%s',) diff --git a/tell.py b/tell.py index f1322e053a..3d22a5ef6e 100644 --- a/tell.py +++ b/tell.py @@ -7,11 +7,9 @@ """ import os -import re import time import datetime import pytz -import random import threading from willie.tools import Nick from willie.module import commands, nickname_commands, rule, priority, example diff --git a/tld.py b/tld.py index eb3f22d72d..68d61a84d1 100644 --- a/tld.py +++ b/tld.py @@ -9,7 +9,6 @@ from willie import web from willie.module import commands, example import re -import urllib2 uri = 'https://en.wikipedia.org/wiki/List_of_Internet_top-level_domains' r_tag = re.compile(r'<(?!!)[^>]+>') diff --git a/translate.py b/translate.py index 516c19dfa3..849fdd9d95 100644 --- a/translate.py +++ b/translate.py @@ -8,10 +8,8 @@ http://willie.dftba.net """ -import re from willie import web from willie.module import rule, commands, priority, example -from time import sleep import urllib2 import json import random @@ -163,7 +161,7 @@ def mangle(bot, trigger): global mangle_lines long_lang_list = ['fr', 'de', 'es', 'it', 'no', 'he', 'la', 'ja', 'cy', 'ar', 'yi', 'zh', 'nl', 'ru', 'fi', 'hi', 'af', 'jw', 'mr', 'ceb', 'cs', 'ga', 'sv', 'eo', 'el', 'ms', 'lv'] lang_list = [] - for index in range(0, 8): + for __ in range(0, 8): lang_list = get_random_lang(long_lang_list, lang_list) random.shuffle(lang_list) if trigger.group(2) is None: diff --git a/version.py b/version.py index 4996bad23a..57b417c3da 100644 --- a/version.py +++ b/version.py @@ -7,7 +7,7 @@ """ from datetime import datetime -from subprocess import * +from subprocess import Popen, PIPE import willie diff --git a/weather.py b/weather.py index 5e81d030bb..0d87f889a7 100644 --- a/weather.py +++ b/weather.py @@ -7,9 +7,6 @@ http://willie.dftba.net """ -import re -import urllib -import json from willie import web from willie.module import commands, example from lxml import etree @@ -17,7 +14,7 @@ def setup(bot): - #Having a db means pref's exists. Later, we can just use `if bot.db`. + # Having a db means pref's exists. Later, we can just use `if bot.db`. if bot.db and not bot.db.preferences.has_columns('woeid'): bot.db.preferences.add_columns(['woeid']) @@ -48,8 +45,8 @@ def get_cover(parsed): except KeyError: return 'unknown' text = condition['text'] - code = int(condition['code']) - #TODO parse code to get those little icon thingies. + # code = int(condition['code']) + # TODO parse code to get those little icon thingies. return text @@ -82,8 +79,8 @@ def get_wind(parsed): kph = float(wind_data['speed']) except ValueError: kph = -1 - #Incoming data isn't a number, default to zero. - #This is a dirty fix for issue #218 + # Incoming data isn't a number, default to zero. + # This is a dirty fix for issue #218 speed = int(round(kph / 1.852, 0)) degrees = int(wind_data['direction']) if speed < 1: diff --git a/wiktionary.py b/wiktionary.py index a5aa3d2a9e..b32ece3081 100644 --- a/wiktionary.py +++ b/wiktionary.py @@ -84,7 +84,7 @@ def wiktionary(bot, trigger): bot.reply('You must tell me what to look up!') return - etymology, definitions = wikt(word) + _etymology, definitions = wikt(word) if not definitions: bot.say("Couldn't get any definitions for %s." % word) return diff --git a/youtube.py b/youtube.py index 36227696c8..25366e99db 100644 --- a/youtube.py +++ b/youtube.py @@ -43,18 +43,18 @@ def ytget(bot, trigger, uri): vid_id = video_entry['id']['$t'].split(':') vid_id = vid_id[len(vid_id) - 1] # last item is the actual ID vid_info['link'] = 'http://youtu.be/' + vid_id - except KeyError as e: + except KeyError: vid_info['link'] = 'N/A' try: vid_info['title'] = video_entry['title']['$t'] - except KeyError as e: + except KeyError: vid_info['title'] = 'N/A' #get youtube channel try: vid_info['uploader'] = video_entry['author'][0]['name']['$t'] - except KeyError as e: + except KeyError: vid_info['uploader'] = 'N/A' #get upload time in format: yyyy-MM-ddThh:mm:ss.sssZ @@ -64,7 +64,7 @@ def ytget(bot, trigger, uri): vid_info['uploaded'] = '%s/%s/%s, %s:%s' % (upraw[8:10], upraw[5:7], upraw[0:4], upraw[11:13], upraw[14:16]) - except KeyError as e: + except KeyError: vid_info['uploaded'] = 'N/A' #get duration in seconds @@ -88,33 +88,33 @@ def ytget(bot, trigger, uri): vid_info['length'] = vid_info['length'] + ' ' if seconds: vid_info['length'] = vid_info['length'] + str(seconds) + 'secs' - except KeyError as e: + except KeyError: vid_info['length'] = 'N/A' #get views try: views = video_entry['yt$statistics']['viewCount'] vid_info['views'] = str('{0:20,d}'.format(int(views))).lstrip(' ') - except KeyError as e: + except KeyError: vid_info['views'] = 'N/A' #get comment count try: comments = video_entry['gd$comments']['gd$feedLink']['countHint'] vid_info['comments'] = str('{0:20,d}'.format(int(comments))).lstrip(' ') - except KeyError as e: + except KeyError: vid_info['comments'] = 'N/A' #get likes & dislikes try: likes = video_entry['yt$rating']['numLikes'] vid_info['likes'] = str('{0:20,d}'.format(int(likes))).lstrip(' ') - except KeyError as e: + except KeyError: vid_info['likes'] = 'N/A' try: dislikes = video_entry['yt$rating']['numDislikes'] vid_info['dislikes'] = str('{0:20,d}'.format(int(dislikes))).lstrip(' ') - except KeyError as e: + except KeyError: vid_info['dislikes'] = 'N/A' return vid_info