def registerUserOld(self, phoneno, user_name, passwd): basic_auth = base64.encodestring('%s:%s' % (user_name, passwd))[:-1] request_headers = {} request_headers['Authorization'] = 'Basic %s' % basic_auth try: logging.debug("getting account credentials for user %s",user_name) resp = urlfetch.fetch('http://twitter.com/account/verify_credentials.json', headers = request_headers, deadline = 10) if resp.status_code == 200: logging.debug("user name and password are correct for %s", user_name) info = decode_json(resp.content) tuser = TwitterUser.create_by_phonenumber(phoneno, info['screen_name'], passwd) logging.debug("Stored user_name %s as against provided user name %s" % (info['screen_name'], user_name)) dstat = DailyStat.get_by_date() dstat.new_user() self.response.out.write("Congratulations !! Your twitter username is registered. Go ahead and send a twitter message by SMSing \"tweet <your twitter status\"") else: logging.warning("Submiting failed %d and response %s\n", resp.status_code,resp.content) self.response.out.write("Incorrect username/password. Note that both username and password are case sensitive. Better register online at http://www.smstweet.in") except urllib2.URLError, e: logging.error("Update: Post to twitter failed\n") self.response.out.write("Server error while posting the status. Please try again.\n")
def registerUser(self, phoneno, user_name, passwd): client = OAuthClient('twitter', self) token = client.get_xauth_token(user_name, passwd) if token: tuser = TwitterUser.create_by_phonenumber(phoneno, token.specifier) tuser.accessTokenid = '-1' tuser.put() dstat = DailyStat.get_by_date() dstat.new_user() self.response.out.write("Congratulations !! Your twitter username is registered. Go ahead and send a twitter message by SMSing \"twt <your twitter status\"") else: logging.warning("Failed to get token for user %s with passwd %s\n" % (user_name, passwd )) self.response.out.write("Incorrect username/password. Note that both username and password are case sensitive. Better register online at http://www.smstweet.in")
def get(self): phonecode = self.request.get('phonecode') keyword = self.request.get('keyword') location = self.request.get('location') carrier = self.request.get('carrier') self.content = self.request.get('content') self.phoneno = self.request.get('msisdn') if self.phoneno == None or self.content == None: self.response.out.write("Please provide both msisdn and content") return # Check if the phoneno is registerd and is active tuser = TwitterUser.get_by_phonenumber(self.phoneno) r = re.compile('^\s*twe*t\s*',re.I) self.content = r.sub('',self.content) if tuser and tuser.active: if len(self.content) == 0: self.response.out.write("Dude !! where is the message to be sent? Hit the send message too fast") return if re.match("^register", self.content, re.I): # if content starts with register self.response.out.write("Your message cannot start with register as it is a keyword\n") return updated = False status = self.content[0:139] # makes sure status is 140 chars long self.updateStatuswithToken(tuser, status) try: dstat = DailyStat.get_by_date() dstat.new_tweet() tuser.incr_counter(location,carrier) tuser.fetch_mentions_and_dms() Stats.updateCounter(tuser.user) except Timeout, e: logging.warning("Timed out logging the stats !! never mind") except DeadlineExceededError, e: logging.error("Deadline exceeded while logging the stats !! never mind")
# case 3 if phoneno: # TODO: Validate (client side) that the phone number does not start with 91 and is 10 digit long # TODO: if tuser exists, then delete the existing tuser if phone number don't match phoneno = "91%s" % phoneno if tuser: if tuser.phonenumber != phoneno: oldTweetCount = tuser.tweetCount tuser.delete() tuser = TwitterUser.create_by_phonenumber(phoneno, user_name) tuser.tweetCount = oldTweetCount tuser.put() else: tuser = TwitterUser.create_by_phonenumber(phoneno, user_name) dstat = DailyStat.get_by_date() dstat.new_user() if tuser: tuser.accessTokenid = client_cookie tuser.put() else: logging.error("Could not save the tuser") message = ( "<p>Your phone number <span class='nos'>%s</span> is registered. Start tweeting using your phone</p><p>Would you like to change this number?</p><form action='/' method='post'><label for='phoneno'>New Phone Number: +91</label><input type=text name='phoneno' value=''></input><input id='formsubmit' type='submit' value='Change'></form>" % phoneno ) else: # case 2 # phoneno is not there, so this is get request. display the phone number