Twitter module for twiting twits on twitter """ # yes, I know they're called "tweets" import oauth2 as oauth import time import urllib, urllib2 import json import re import csv from lib.botconfig import config from BotModule import BotModule # Import relevant config oauth_token = config.get("twitter", "oauth_token") oauth_secret = config.get("twitter", "oauth_secret") consumer_key = config.get("twitter", "consumer_key") consumer_secret = config.get("twitter", "consumer_secret") account = config.get("twitter", "account") base_url = "https://api.twitter.com/1/" def twit(self, user, channel, args): """Twits.""" nick = user.split("!", 1)[0] if not args: self.msg(channel, "{0}: Needs something to twit, yo.".format(nick)) return
#!/usr/bin/env python """ Google weather lookup Uses the undocumented Google API to fetch current weather data """ from xml.dom import minidom import urllib2 from lib.botconfig import config from BotModule import BotModule default_locale = config.get("weather", "default_locale") weather_url = "http://www.google.com/ig/api?weather=" def display_weather(self, user, channel, args): """Displayes weather data for given location.""" location = args if args else default_locale try: weather_data = get_weather(location) self.msg(channel, "{location}: {temp}, {condition}".format(**weather_data)) except InvalidLocale: self.msg(channel, "Invalid location") def get_weather(location): if location == "":
Twitter module for twiting twits on twitter """ # yes, I know they're called "tweets" import oauth2 as oauth import time import urllib, urllib2 import json import re import csv from lib.botconfig import config from BotModule import BotModule # Import relevant config oauth_token = config.get("twitter", "oauth_token") oauth_secret = config.get("twitter", "oauth_secret") consumer_key = config.get("twitter", "consumer_key") consumer_secret = config.get("twitter", "consumer_secret") account = config.get("twitter", "account") base_url = "https://api.twitter.com/1/" def twit(self, user, channel, args): """Twits.""" nick = user.split("!", 1)[0] if not args: self.msg(channel, "{0}: Needs something to twit, yo.".format(nick))
last.fm module Adds some last.fm functionality to the bot: registers nicknames, displays currently playing songs for registered nicknames, compares people """ from xml.dom import minidom import urllib2 from urllib import urlencode import datetime from lib.database import db from lib.botconfig import config from BotModule import BotModule lfm_url = "http://ws.audioscrobbler.com/2.0/" api_key = config.get("lastfm", "api_key") def register_nickname(self, user, channel, args): """ Adds a irc nickname -> last.fm username mapping record to the db""" irc_name = user.split("!", 1)[0] if not args: self.msg(channel, "{0}: Please provide a last.fm username".format()) return # discard everything after the first space - lastfm usernames have no spaces args = args.split(" ", 1)[0] data = minidom.parse(lfm_call({"user": args, "method": "user.getInfo"})) # if status is failed, we weren't able to fetch the profile if data.getElementsByTagName( "lfm")[0].attributes["status"].value == "failed":
last.fm module Adds some last.fm functionality to the bot: registers nicknames, displays currently playing songs for registered nicknames, compares people """ from xml.dom import minidom import urllib2 from urllib import urlencode import datetime from lib.database import db from lib.botconfig import config from BotModule import BotModule lfm_url = "http://ws.audioscrobbler.com/2.0/" api_key = config.get("lastfm", "api_key") def register_nickname(self, user, channel, args): """ Adds a irc nickname -> last.fm username mapping record to the db""" irc_name = user.split("!", 1)[0] if not args: self.msg(channel, "{0}: Please provide a last.fm username".format()) return # discard everything after the first space - lastfm usernames have no spaces args = args.split(" ",1)[0] data = minidom.parse(lfm_call({"user": args, "method": "user.getInfo"})) # if status is failed, we weren't able to fetch the profile if data.getElementsByTagName("lfm")[0].attributes["status"].value == "failed": self.msg(channel, "{0}: Cannot find profile. Is the username correct?".format(irc_name))