This repository has been archived by the owner on Dec 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mistadobalina.py
106 lines (82 loc) · 3.86 KB
/
mistadobalina.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/python
"""
A script that selects two random lines from Del Tha Funkee Homosapien's first album,
I Wish My Brother George Was Here, and posts them to the @mistadoblina Twitter account.
http://twitter.com/mistadobalina
Lyrics data provied by LyricWiki. Their API is documented here:
* http://lyricwiki.org/LyricWiki:SOAP
Dependencies: PyXML, fpconst, SOAPpy, python-twitter, simplejson.
For more information on SOAPpy or python-twitter refer to:
* http://www.diveintopython.org/soap_web_services/
* http://code.google.com/p/python-twitter/
The MIT License
Copyright (c) 2008 Ben Welsh
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""
__author__ = "Ben Welsh <palewire@palewire.com>"
__date__ = "$Date: 2008/06/01 $"
__version__ = "$Revision: 0.2 $"
import re
import cgi
import random
import string
import twitter
from SOAPpy import WSDL
# Since the LyricWiki getArtist() method wasn't working, I just hammered in the song titles by hand.
# I've excluded a couple tracks. Here's why:
# * "Interlude" is too short to include, I figure.
# * There weren't good lyrics in the API for "The Wacky World of Public Transit"
I_Wish_My_Brother_George_Was_Here = ['Dr._Bombay', 'What_Is_A_Booty', 'Ahonetwo,_Ahonetwo', 'Mistadobalina',
'Sleepin\'_On_My_Couch', 'Sunny_Meadowz', 'Eye Examination',
'Pissin\'_On_Your_Steps', 'Dark Skin Girls', 'Money_For_Sex',
'Hoodz_Come_In_Dozens', 'Same_Ol\'_Thing', 'Ya_Li\'l_Crumbsnatchers']
# Selecting a random song from the album
random_song = random.randrange(len(I_Wish_My_Brother_George_Was_Here))
song = I_Wish_My_Brother_George_Was_Here[random_song]
# Logging into the LyricWiki API and downloading our randomly selected song
wsdlFile = ('http://lyricwiki.org/server.php?wsdl')
server = WSDL.Proxy(wsdlFile)
song = server.getSong('Del_Tha_Funkee_Homosapien', song)
title = song[1]
lyrics = song[2]
lines = string.split(lyrics, '\n')
def Filter(line):
"""Flagging any line that contains one of the words we want to omit."""
# The words we want to exclude.
black_list = ('Chorus', 'CHORUS', 'REPEAT', 'BRIDGE',
'PAUSE', 'INTERLUDE', 'CHROUS', 'Chrous',
'chorus', 'REPEAT', 'Bridge', 'Intro',
'Verse One', 'Verse Two', '&(.*);')
# Walk through each term in the list and return false where there's a match.
# There must be a more concise way to do this with a comprehension, but I haven't
# figured it out yet.
for term in black_list:
if re.search(term, line):
return False
else:
pass
return True
# Walking every line in the song through the filter.
# If they don't have a blacklisted word, they return True and we keep em.
lines = [line for line in lines if Filter(line)]
# Selecting a random line from the song
random_line = random.randrange(len(lines))
# Since there's a chance we might draw the last line in the song,
# the exception should back it up to grab the second to last line.
try:
quote = lines[random_line] + ' / ' + lines[random_line+1]
except:
quote = lines[random_line-1] + ' / ' + lines[random_line]
# Shooting it up to Twitter
# This could probably use some test that makes sure the quote isn't over Twitters 140 character limit.
# But I'm too lazy to do that tonight.
un = 'mistadobalina'
pw = '##'
api = twitter.Api(username=un, password=pw)
status = api.PostUpdate(quote)