Skip to content

Instantly share code, notes, and snippets.

@brandon15811
Created November 15, 2012 04:22
Show Gist options
  • Save brandon15811/4076613 to your computer and use it in GitHub Desktop.
Save brandon15811/4076613 to your computer and use it in GitHub Desktop.
ps
#!/usr/bin/python
import email
from google.appengine.ext import webapp
from google.appengine.ext.webapp.mail_handlers import InboundMailHandler
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import util
from google.appengine.ext import db
import uuid
import urllib, urllib2
import re
def main():
application = webapp.WSGIApplication([LogSenderHandler.mapping()], debug=True)
util.run_wsgi_app(application)
class Ps(db.Model):
email = db.StringProperty()
id = db.IntegerProperty()
class MainHandler(webapp.RequestHandler):
def get(self):
self.response.out.write('Hello world!')
class LogSenderHandler(InboundMailHandler):
def receive(self, message):
if message.subject.find("is now following you on PhotoShare!") != -1 or message.subject.find("is_now_following_you_on_PhotoShare") != -1:
quit()
bodies = message.bodies(content_type='text/plain')
allBodies = "";
for body in bodies:
allBodies = allBodies + "\n---------------------------\n" + body[1].decode()
psname = allBodies.split("You have a comment from")
psname = psname[1].replace("You have a comment from", "")
psname = psname.split("\n")[0]
pscomment = allBodies.split("Comment Added:")
pscomment = pscomment[1].replace("Comment Added:", "")
pscomment = pscomment.split("\n")[0]
pstitle = allBodies.split("Image Title:")
pstitle = pstitle[1].replace("Image Title:", "")
pstitle = pstitle.split("\n")[0]
re1='.*?' # Non-greedy match on filler
re2='(email)' # Word 1
re3='(\\/)' # Any Single Character 1
re4='(\\d+)' # Integer Number 1
rg = re.compile(re1+re2+re3+re4,re.IGNORECASE|re.DOTALL)
m = rg.search(allBodies)
if m:
psid=m.group(3)
hash = Ps.gql("WHERE id = :1", int(psid))
email = hash.get().email
values = {
'email' : email,
'notification[from_screen_name]' : psname.encode('utf-8'),
'notification[message]' : pstitle.encode('utf-8') + " - " + pscomment.encode('utf-8'),
'notification[from_remote_service_id]' : str(uuid.uuid4()),
'notification[redirect_payload]' : 'bcphoto://',
'notification[source_url]' : 'bcphoto://'
}
params = urllib.urlencode(values)
f = urllib2.urlopen('http://boxcar.io/devices/providers/<key>/notifications', params)
f.close()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment