예제 #1
0
def main():
    try:
        parser = ArgumentParser()
        parser.add_argument("oauth_keys_file",
                        help="The location of a file containing the application " +
                        "oath consumer key, consumer secret, " +
                        "access token, and access token secret, " +
                        "each on its own line, in that order.  " +
                        "See the tweepy example on oauth to figure " +
                        "out how to get these keys."
                        )
        parser.add_argument("mail_settings_file", help="The automail settings file for sending emails.")
        args = parser.parse_args()
        (consumer_key, consumer_secret, access_token, access_token_secret) = \
            parse_oauth_file(args.oauth_keys_file)
    
        auth = OAuthHandler(consumer_key, consumer_secret)
        auth.set_access_token(access_token, access_token_secret)
    
        pl = PaxListener(args.mail_settings_file, auth)
        
        #open a stream, with ourself as the listener
        stream = Stream(auth, pl)
        #stream.filter(track=["the"])
    
        pax_user_id = '26281970' #follow requires userid, found at mytwitterid.com
        daemon_user_id = '1954653840'
        stream.filter(follow=[pax_user_id]) #track ignores follow, pulls from firehose regardless (this is testing acct)

    except BaseException as e:
        subject = "Exception from paxtix"
        exc_type, exc_value, exc_traceback = sys.exc_info()
        message = '\n'.join(["Pax tix listener has hit an exception!",] + 
                             traceback.format_exception(exc_type, exc_value, exc_traceback),
                             )
        send_email(parse_settings(args.mail_settings_file), subject, message)
        traceback.print_exception(exc_type, exc_value, exc_traceback)
예제 #2
0
import clparse
from automail import automail
from datetime import date
import os


listings = clparse.compile_listings(
    "http://boston.craigslist.org/search/aap", bedrooms="5", query="somerville|davis|porter|ball|tufts"
)

listings.sort(key=lambda listing: listing.price)
listings = clparse.sift_by_location(listings, ["somerville", "porter", "davis", "ball", "tufts", "cambridge"])
subject = "Craigslist results for " + str(date.today())
body_text = ""
for listing in listings:
    body_text += listing.print_link() + "<br/>"

body_text += "<br/>Search terms: somerville, davis, porter, ball, tufts"

directory = os.path.dirname(__file__)
if not directory:
    directory = "."
settings_filename = directory + "/mail_settings.txt"

automail.send_email(automail.parse_settings(settings_filename), subject, body_text, "html")
예제 #3
0
 def on_error(self, status_code):
     subject = status_code + "error recieved by tweepy!"
     message = "PAX tix listener recieved a " + status_code + " error from twitter"
     send_email(self.mail_settings, subject, message)
     return True
예제 #4
0
 def on_status(self, status):
     if re.search(r'east|ticket|tickets|registration|open', status.text, re.IGNORECASE): #regex open for editing
         subject = "New message from %s" % status.user.name.encode('ascii', 'xmlcharrefreplace')
         message = status.text.encode('ascii', 'xmlcharrefreplace')
         send_email(self.mail_settings, subject, message)
     return True
예제 #5
0
 def daily_heartbeat(self):
     subject = "PAX ticket listener heatbeat"
     msg = "Heartbeat for %s" % datetime.datetime.utcnow().isoformat()
     send_email(self.mail_settings, subject, msg)
     t = threading.Timer(86400, self.daily_heartbeat)