예제 #1
0
파일: steam.py 프로젝트: tarabluh/botmily
def steam(message_data, bot):
    result = urlopen('http://www.steamcalculator.com/id/' + message_data["parsed"])
    soup = BeautifulStoneSoup(result, convertEntities=BeautifulStoneSoup.HTML_ENTITIES)
    data = soup.find('div', id='rightdetail')
    game_count = re.search('Found ([0-9]+)', data.text).group(1)
    output = irc.bold(message_data["parsed"]) + ' owns ' + irc.bold(game_count) + ' Games with a value of ' + irc.bold(re.search('\$.*', data.text).group(0)) + '.'
    if int(game_count) >= 125:
        output += ' <--- jesus f**k quit buying games you neckbeard.'
    return output
예제 #2
0
파일: lastfm.py 프로젝트: TZer0/botmily
def lastfm(message_data, bot):
    if message_data["parsed"] == "":
        return "Type in a username ¬_¬"
    result = urlopen('http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user='******'&api_key=' + config.lastfm_api_key)
    root = ElementTree.fromstring(result.read())
    track = root.find('recenttracks/track')
    result_string = irc.bold(message_data["parsed"]) + '\'s last track - '
    result_string += irc.bold(track.find('name').text) + ' :: Artist - '
    result_string += irc.bold(track.find('artist').text) + ' :: Link to Song - '
    result_string += irc.bold(track.find('url').text)
    return result_string
예제 #3
0
def lastfm(message_data, bot):
    if message_data["parsed"] == "":
        return "Type in a username ¬_¬"
    result = urlopen(
        'http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user='******'&api_key=' +
        config.lastfm_api_key)
    root = ElementTree.fromstring(result.read())
    track = root.find('recenttracks/track')
    result_string = irc.bold(message_data["parsed"]) + '\'s last track - '
    result_string += irc.bold(track.find('name').text) + ' :: Artist - '
    result_string += irc.bold(
        track.find('artist').text) + ' :: Link to Song - '
    result_string += irc.bold(track.find('url').text)
    return result_string
예제 #4
0
파일: google.py 프로젝트: kgc/botmily
def google(message_data, bot):
    result = urlopen('http://ajax.googleapis.com/ajax/services/search/web?v=1.0&safe=off&q=' + quote_plus(message_data["parsed"].encode("utf-8")))
    json_data = json.load(result)
    if len(json_data["responseData"]["results"]) == 0:
        return "No results found"
    first_result = json_data['responseData']['results'][0]
    output = first_result['unescapedUrl'] + ' | '
    output += irc.bold(BeautifulStoneSoup(first_result['titleNoFormatting'], convertEntities=BeautifulStoneSoup.HTML_ENTITIES).text) + ' | '
    output += BeautifulStoneSoup(first_result['content'], convertEntities=BeautifulStoneSoup.HTML_ENTITIES).text
    return output
예제 #5
0
파일: google.py 프로젝트: TZer0/botmily
def google(message_data, bot):
    result = urlopen('http://ajax.googleapis.com/ajax/services/search/web?v=1.0&safe=off&q=' + quote_plus(message_data["parsed"].encode("utf-8")))
    json_data = json.load(result)
    if len(json_data["responseData"]["results"]) == 0:
        return "No results found"
    first_result = json_data['responseData']['results'][0]
    output = first_result['unescapedUrl'] + ' | '
    output += irc.bold(BeautifulSoup(first_result['titleNoFormatting'].read()).text) + ' | ' #irc.bold(BeautifulStoneSoup(first_result['titleNoFormatting'], convertEntities=BeautifulStoneSoup.HTML_ENTITIES).text) + ' | '
    output += BeautifulSoup(first_result['content'].read()).text #BeautifulStoneSoup(first_result['content'], convertEntities=BeautifulStoneSoup.HTML_ENTITIES).text
    return output
예제 #6
0
파일: youtube.py 프로젝트: tarabluh/botmily
def parse(message_data, bot):
    id = message_data["re"].group(1)
    youtube = service.YouTubeService()
    youtube.ssl = True
    entry = youtube.GetYouTubeVideoEntry(video_id=id)
    string = irc.bold(unicode(entry.media.title.text, encoding='utf-8')) + " - length "
    string += irc.bold(convertHMS(entry.media.duration.seconds)) + " - rated "
    if entry.rating is not None:
        string += irc.bold(locale.format("%.2f", float(entry.rating.average))) + "/5.0 ("
        string += entry.rating.num_raters + ") - "
    if entry.statistics is not None:
        string += irc.bold(locale.format("%d", float(entry.statistics.view_count), True)) + " views - "
    string += irc.bold(unicode(entry.author[0].name.text, encoding='utf-8')) + " on "
    string += irc.bold(time.strftime("%Y.%m.%d", time.strptime(entry.published.text, "%Y-%m-%dT%H:%M:%S.000Z")))
    return string
예제 #7
0
def parse(message_data, bot):
	# Takes a message_data dictionary as a param
	# Get the regex match entry from the dictionry, and select result 1 from it. This is all done in the bot script somewhere.
 	video_id = message_data['re'].group(1)

	# Create API service:
	youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, developerKey=config.YOUTUBE_API_KEY)

	# Call the videos.list method to retrieve results matching the specified
	# query term.
	video_responces = youtube.videos().list(
	id=video_id,
	part="id,snippet,contentDetails,statistics" # We call all these things to uh, well I don't know why we do ID really, but we do it to get all the info we need
	).execute()
	# snippet has most of the title/uploader/date info
	# contentDetails has the duration
	# statistics has the likes/views

	my_result = None

	for video_responce in video_responces.get("items", []):
		if video_responce['kind'] == "youtube#video":
			my_result = irc.bold(unicode(video_responce['snippet']['title'])) + " - length "
			my_result += irc.bold(convertISOTime(video_responce['contentDetails']['duration']))

			# Generate score out of 5 I guess?
			# Get how many likes/dislikes the video has
			likes = int(video_responce['statistics']['likeCount'])
			dislikes = int(video_responce['statistics']['dislikeCount'])
			# Work out the total
			totals = likes + dislikes
			# If non zero, add the score
			if totals > 0:
				score = 5 * (float(likes) / float(totals))
				my_result += " - rated " + irc.bold(locale.format("%.2f", score)) + "/5.0 (" + locale.format("%d",totals) + ")"

			# Do something entirely dissimilar but the same kinda for the views. Which is to say: add the views
			views = video_responce['statistics']['viewCount']
			if views:
				my_result += " - " + irc.bold(views) + " views"

			# Add the remaining user and upload time fields:
			my_result += " - " + irc.bold(unicode(video_responce['snippet']['channelTitle'])) + " on "
			my_result += irc.bold(time.strftime("%Y.%m.%d", time.strptime(video_responce['snippet']['publishedAt'], "%Y-%m-%dT%H:%M:%S.000Z")))

 	return my_result